using UnityEditor; using UnityEngine; using System; using System.Linq; using System.Reflection; using System.Collections.Generic; using AlicizaX.Runtime; using Sirenix.OdinInspector.Editor; namespace AlicizaX.Editor { public class GameFrameworkPreferenceWindow : OdinMenuEditorWindow { private List m_TabTypes; private readonly Dictionary _tabBases = new(); [MenuItem("AlicizaX/Preference Window")] public static void ShowWindow() { GetWindow(true, "Preference Window"); } private void OnEnable() { this.position = new Rect(this.position.x, this.position.y, 800, 600); var assemblies = Utility.Assembly.GetAssemblies(); m_TabTypes = new List(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (typeof(GameFrameworkTabBase).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract) { var displayNameAttr = (DisplayNameAttribute)Attribute.GetCustomAttribute(type, typeof(DisplayNameAttribute)); if (displayNameAttr != null) { m_TabTypes.Add(type); } } } } m_TabTypes = m_TabTypes.OrderBy(t => ((DisplayNameAttribute)Attribute.GetCustomAttribute(t, typeof(DisplayNameAttribute))).DisplayName).ToList(); } protected override void OnDestroy() { base.OnDestroy(); if (this.MenuTree != null && this.MenuTree.Selection.SelectedValue != null) { var selectTarget = this.MenuTree.Selection.SelectedValue; if (selectTarget != null) { var selectType = selectTarget.GetType(); if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab)) { tab.Save(); } } } } protected override OdinMenuTree BuildMenuTree() { var tree = new OdinMenuTree(); foreach (var tabType in m_TabTypes) { DisplayNameAttribute displayNameAttribute = (DisplayNameAttribute)Attribute.GetCustomAttribute(tabType, typeof(DisplayNameAttribute)); GameFrameworkTabBase instance = (GameFrameworkTabBase)Activator.CreateInstance(tabType); _tabBases.Add(tabType, instance); tree.Add(displayNameAttribute.DisplayName, instance); } tree.Selection.SelectionChanged += SelectionOnSelectionChanged; return tree; } private void SelectionOnSelectionChanged(SelectionChangedType obj) { var selectTarget = this.MenuTree.Selection.SelectedValue; if (selectTarget != null) { var selectType = selectTarget.GetType(); if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab)) { tab.Save(); } } } } }