Ejemplo n.º 1
0
    static void Init()
    {
        if (instance)
        {
            return;
        }
        instance = new GameObject("GameManager").AddComponent <GameManager>();
        DontDestroyOnLoad(instance);

        var types = new List <Type>(Implementors.GetTypes <GameSystem>());

        types.Sort((x, y) => ((int)x.GetCustomAttribute <Priority>()).CompareTo((int)y.GetCustomAttribute <Priority>()));

        AllGroups.Add(typeof(GameSystem), new Group <GameSystem>());

        foreach (var systemType in types)
        {
            var system = Activator.CreateInstance(systemType) as GameSystem;
            Group <GameSystem> .value.Add(system);

            foreach (var Interface in systemType.GetInterfaces())
            {
                if (!AllGroups.TryGetValue(Interface, out var group))
                {
                    AllGroups[Interface] = group = Activator.CreateInstance(typeof(Group <>).MakeGenericType(Interface)) as Group;
                }
                group.Add(system);
            }
        }

        foreach (var system in SystemsWith <IOnInitialize>())
        {
            system.OnInitialize();
        }
    }