ARResourceGroup.cs
1.68 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
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace UnityEditor.XR.ARKit
{
internal class ARResourceGroup
{
public string name { get; set; }
public ARResourceGroup(string name)
{
this.name = name;
}
public void AddResource(ARResource resource)
{
if (resource == null)
throw new ArgumentNullException("resource");
if (m_Resources.Contains(resource))
throw new InvalidOperationException(string.Format("Duplicate resource '{0}` in group '{1}'", resource.name, name));
m_Resources.Add(resource);
}
internal void Write(string pathToAssetCatalog)
{
string path = Path.Combine(pathToAssetCatalog, name + ".arresourcegroup");
Directory.CreateDirectory(path);
// Build the contents json and write each resource to disk
var contents = new Json.ResourceGroup
{
info = new Json.AuthorInfo
{
version = 1,
author = "unity"
},
resources = new Json.Filename[m_Resources.Count]
};
for (int i = 0; i < m_Resources.Count; ++i)
{
var resource = m_Resources[i];
contents.resources[i].filename = resource.filename;
resource.Write(path);
}
// Finally, write out the json contents
File.WriteAllText(Path.Combine(path, "Contents.json"), JsonUtility.ToJson(contents));
}
List<ARResource> m_Resources = new List<ARResource>();
}
}