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(); } }
public override void Draw() { float width = UnityEditor.EditorGUIUtility.labelWidth; using (new GUILayout.HorizontalScope()) { GUILayout.Label("Search Name", GUILayout.Width(width)); search = GUILayout.TextField(search); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Filter", GUILayout.Width(width)); if (GUILayout.Button(filter == null ? "No Filter" : filter.Name, UnityEditor.EditorStyles.toolbarDropDown)) { var menu = new UnityEditor.GenericMenu(); var items = new List <Type>(AllGroups.Keys); items.Remove(typeof(GameSystem)); items.Sort((x, y) => y.Name.CompareTo(x.Name)); items.Add(typeof(GameSystem)); for (int i = items.Count - 1; i >= 0; --i) { var item = items[i]; menu.AddItem(new GUIContent(item.Name), filter == item, () => filter = item); } menu.ShowAsContext(); } } if (AllGroups.TryGetValue(filter, out var group)) { using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Priority", UnityEditor.EditorStyles.boldLabel, GUILayout.Width(64f)); GUILayout.Label("Game System", UnityEditor.EditorStyles.boldLabel); } foreach (var item in group.List) { if (item.GetType().Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) { using (new GUILayout.HorizontalScope()) { GUILayout.Label(((int)item.GetType().GetCustomAttribute <Priority>()).ToString(), GUILayout.Width(64f)); using (new GUILayout.VerticalScope()) { if (GUILayout.Button(item.GetType().Name, UnityEditor.EditorStyles.label)) { if (item is IOnInspect inspectable) { if (inspected.Contains(inspectable)) { inspected.Remove(inspectable); } else { inspected.Add(inspectable); } } } if (inspected.Contains(item as IOnInspect)) { using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) { (item as IOnInspect).OnInspect(); } } } } } } } } }