XcodeAssetCatalog.cs
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#if UNITY_IOS
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using UnityEngine;
using UnityEditor.iOS.Xcode;
namespace UnityEditor.XR.ARKit
{
internal class XcodeAssetCatalog
{
public string name { get; set; }
public XcodeAssetCatalog(string name)
{
this.name = name;
}
public void AddResourceGroup(ARResourceGroup group)
{
if (group == null)
throw new ArgumentNullException("group");
if (m_ResourceGroups.Contains(group))
throw new InvalidOperationException(string.Format("Duplicate resource group '{0}'", group.name));
m_ResourceGroups.Add(group);
}
public void WriteAndAddToPBXProject(PBXProject project, string pathToBuiltProject)
{
var unityTargetName = "Unity-iPhone";
var relativePathToAssetCatalog = Path.Combine(unityTargetName, name + ".xcassets");
var fullPathToAssetCatalog = Path.Combine(pathToBuiltProject, relativePathToAssetCatalog);
// Create the asset catalog, destroying an existing one.
if (Directory.Exists(fullPathToAssetCatalog))
Directory.Delete(fullPathToAssetCatalog, true);
Directory.CreateDirectory(fullPathToAssetCatalog);
// Add it to Xcode's build
var folderGuid = project.AddFile(relativePathToAssetCatalog, relativePathToAssetCatalog);
var targetGuid = project.GetUnityMainTargetGuid();
project.AddFileToBuild(targetGuid, folderGuid);
foreach (var resourceGroup in m_ResourceGroups)
{
resourceGroup.Write(fullPathToAssetCatalog);
}
}
List<ARResourceGroup> m_ResourceGroups = new List<ARResourceGroup>();
}
}
#endif