浏览代码

Add plist entries required MPC in iOS 14

/4.0
Tim Mowrer 4 年前
当前提交
101dc06e
共有 4 个文件被更改,包括 107 次插入0 次删除
  1. 8
      Assets/Scenes/ARCollaborationData/Editor.meta
  2. 88
      Assets/Scenes/ARCollaborationData/Editor/CollaborationBuildPostprocessor.cs
  3. 11
      Assets/Scenes/ARCollaborationData/Editor/CollaborationBuildPostprocessor.cs.meta

8
Assets/Scenes/ARCollaborationData/Editor.meta


fileFormatVersion: 2
guid: 3598feda6320f4bc6b3930000e47b93b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

88
Assets/Scenes/ARCollaborationData/Editor/CollaborationBuildPostprocessor.cs


#if UNITY_IOS
using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.iOS.Xcode;
using System.IO;
using System.Linq;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.XR.ARFoundation.Samples;
namespace UnityEditor.XR.ARFoundation.Samples
{
class Processor : IPostprocessBuildWithReport, IPreprocessBuildWithReport
{
public int callbackOrder => 2;
void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report)
{
s_CollaborativeSessions = new List<CollaborativeSession>();
}
PlistElementArray GetOrCreatePlistElementArray(PlistElementDict dict, string key)
{
var element = dict[key];
return element == null ? dict.CreateArray(key) : element.AsArray();
}
void IPostprocessBuildWithReport.OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.iOS)
return;
if (s_CollaborativeSessions.Count == 0)
return;
var plistPath = Path.Combine(report.summary.outputPath, "Info.plist");
var plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
var root = plist.root;
if (root["NSLocalNetworkUsageDescription"] == null)
{
root["NSLocalNetworkUsageDescription"] = new PlistElementString("Collaborative Session");
}
// Get all the service names
var bonjourServices = GetOrCreatePlistElementArray(root, "NSBonjourServices");
var existingValues = new HashSet<string>(bonjourServices.values
.Where(value => value is PlistElementString)
.Select(value => value.AsString()));
var valuesToAdd = new HashSet<string>();
foreach (var serviceType in s_CollaborativeSessions
.Select(collaborativeSession => collaborativeSession.serviceType)
.Where(serviceType => !string.IsNullOrEmpty(serviceType)))
{
AddIfNecessary(existingValues, valuesToAdd, $"_{serviceType}._tcp");
AddIfNecessary(existingValues, valuesToAdd, $"_{serviceType}._udp");
}
foreach (var value in valuesToAdd)
{
bonjourServices.AddString(value);
}
File.WriteAllText(plistPath, plist.WriteToString());
}
static void AddIfNecessary(HashSet<string> existingValues, HashSet<string> valuesToAdd, string value)
{
if (!existingValues.Contains(value))
valuesToAdd.Add(value);
}
[PostProcessScene]
static void OnPostProcessScene()
{
foreach (var collaborativeSession in Object.FindObjectsOfType<CollaborativeSession>())
{
s_CollaborativeSessions.Add(collaborativeSession);
}
}
static List<CollaborativeSession> s_CollaborativeSessions = new List<CollaborativeSession>();
}
}
#endif

11
Assets/Scenes/ARCollaborationData/Editor/CollaborationBuildPostprocessor.cs.meta


fileFormatVersion: 2
guid: 4c9c547b7f3964e75b3b6d84570de72b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存