XRLoaderInfo.cs
2.39 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.XR.Management;
namespace UnityEditor.XR.Management
{
internal class XRLoaderInfo : IEquatable<XRLoaderInfo>
{
public Type loaderType;
public string assetName;
public XRLoader instance;
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is XRLoaderInfo && Equals((XRLoaderInfo)obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (loaderType != null ? loaderType.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (instance != null ? instance.GetHashCode() : 0);
return hashCode;
}
}
public bool Equals(XRLoaderInfo other)
{
return other != null && Equals(loaderType, other.loaderType) && Equals(instance, other.instance);
}
static string[] s_LoaderBlackList = { "DummyLoader", "SampleLoader", "XRLoaderHelper" };
internal static void GetAllKnownLoaderInfos(List<XRLoaderInfo> newInfos)
{
var loaderTypes = TypeLoaderExtensions.GetAllTypesWithInterface<XRLoader>();
foreach (Type loaderType in loaderTypes)
{
if (loaderType.IsAbstract)
continue;
if (s_LoaderBlackList.Contains(loaderType.Name))
continue;
var assets = AssetDatabase.FindAssets(String.Format("t:{0}", loaderType));
if (!assets.Any())
{
XRLoaderInfo info = new XRLoaderInfo();
info.loaderType = loaderType;
newInfos.Add(info);
}
else
{
foreach (var asset in assets)
{
string path = AssetDatabase.GUIDToAssetPath(asset);
XRLoaderInfo info = new XRLoaderInfo();
info.loaderType = loaderType;
info.instance = AssetDatabase.LoadAssetAtPath(path, loaderType) as XRLoader;
info.assetName = Path.GetFileNameWithoutExtension(path);
newInfos.Add(info);
}
}
}
}
}
}