-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServices.cs
53 lines (50 loc) · 1.68 KB
/
Services.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
using SALT.Utils;
using System.Linq;
using System.Reflection;
using UnityEngine;
using SALT.Extensions;
namespace SALT
{
/// <summary>This class controls all services that guu runs, use it to activate the services your mod needs.</summary>
public static class Services
{
private const string SYSTEM_OBJECT_NAME = "_SALTServices";
private static bool internalServicesInit;
internal static GameObject servicesObj;
internal static void InitInternalServices()
{
if (internalServicesInit)
return;
foreach (System.Type type in TypeUtils.GetChildsOf<IService>(Main.execAssembly))
{
if (type.IsSubclassOf(typeof(Component)) && !servicesObj.HasComponent(type))
{
if (typeof(IServiceInternal).IsAssignableFrom(type))
{
servicesObj.AddComponent(type);
#if DEBUG
Debug.Log("- Registered internal service '" + type.Name + "'");
#endif
}
else
{
if (servicesObj.AddComponent(type) is Behaviour behaviour)
behaviour.enabled = false;
#if DEBUG
Debug.Log("- Registered service '" + type.Name + "'");
#endif
}
}
}
internalServicesInit = true;
}
internal static void CreateServiceObject()
{
servicesObj = new GameObject(SYSTEM_OBJECT_NAME);
servicesObj.DontDestroyOnLoad();
#if DEBUG
Debug.Log("- Initializing service object");
#endif
}
}
}