-
Notifications
You must be signed in to change notification settings - Fork 5
/
PrefabAITypes.cs
60 lines (51 loc) · 1.53 KB
/
PrefabAITypes.cs
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
using System;
using System.Collections.Generic;
using ColossalFramework;
using UnityEngine;
using System.Reflection;
using System.Linq;
namespace PrefabAIChanger
{
class PrefabAITypes : Singleton<PrefabAITypes>
{
private PrefabAITypes() { }
private bool typesLoaded = false;
private readonly List<PrefabAIInfo> allTypes = new List<PrefabAIInfo>();
public List<PrefabAIInfo> All()
{
if (typesLoaded) return allTypes;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
IEnumerable<Type> types;
try
{
types = a.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
types = e.Types.Where(t => t != null);
}
catch (Exception e)
{
Debug.Log(e.Message);
continue;
}
allTypes.AddRange(
types.Where(t => t.IsSubclassOf(typeof(PrefabAI)))
.Select(t => new PrefabAIInfo(t))
);
}
typesLoaded = true;
return allTypes;
}
public PrefabAIInfo GetAIInfo(string name)
{
return All().Find((info) => info.type.FullName == name);
}
public void Invalidate()
{
allTypes.Clear();
typesLoaded = false;
}
}
}