diff --git a/Editor/Lrss3.Deconstruction.Editor.asmdef b/Editor/Lrss3.Deconstruction.Editor.asmdef index 1590311..fe9718f 100644 --- a/Editor/Lrss3.Deconstruction.Editor.asmdef +++ b/Editor/Lrss3.Deconstruction.Editor.asmdef @@ -2,8 +2,8 @@ "name": "Lrss3.SesothoLine.Editor", "rootNamespace": "SesothoLineEditor", "references": [ - "Lrss3.Deconstruction", - "UnityEditor.UI" + "Lrss3.SesothoLine", + "Lrss3.Deconstruction" ], "includePlatforms": [ "Editor" diff --git a/Editor/XericLibraryEditor.dll b/Editor/XericLibraryEditor.dll index 0766a61..838749a 100644 Binary files a/Editor/XericLibraryEditor.dll and b/Editor/XericLibraryEditor.dll differ diff --git a/Runtime/CentralizeLog.dll b/Runtime/CentralizeLog.dll index 7599df6..bcc3471 100644 Binary files a/Runtime/CentralizeLog.dll and b/Runtime/CentralizeLog.dll differ diff --git a/Runtime/Deconstruction.dll b/Runtime/Deconstruction.dll index ef803ed..bda8cb9 100644 Binary files a/Runtime/Deconstruction.dll and b/Runtime/Deconstruction.dll differ diff --git a/Runtime/UI/MacroUI.cs b/Runtime/UI/MacroUI.cs index b0724df..47fcce0 100644 --- a/Runtime/UI/MacroUI.cs +++ b/Runtime/UI/MacroUI.cs @@ -3,19 +3,22 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; - using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using XericLibrary.Runtime.CustomEditor; -using Object = UnityEngine.Object; +#if ODIN_INSPECTOR using Sirenix.OdinInspector; -#if UNITY_EDITOR +#endif + +#if UNITY_EDITOR && ODIN_INSPECTOR using Sirenix.Utilities.Editor; #endif +using Object = UnityEngine.Object; + namespace XericLibrary.Runtime.MacroLibrary { /// @@ -25,27 +28,28 @@ namespace XericLibrary.Runtime.MacroLibrary { #region toggle 扩展 - private static FieldInfo togglesFieldInfo = typeof(ToggleGroup).GetField("m_Toggles", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + private static FieldInfo togglesFieldInfo = typeof(ToggleGroup).GetField("m_Toggles", + BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); public static List GetToggles(this ToggleGroup toggleGroup) { - if (toggleGroup == null) - { - throw new ArgumentNullException(nameof(toggleGroup)); - } - - if (togglesFieldInfo == null) - { - throw new InvalidOperationException("Unable to access the 'm_Toggles' field."); - } - - var toggles = togglesFieldInfo.GetValue(toggleGroup) as List; - if (toggles == null) - { - throw new InvalidCastException("The 'm_Toggles' field is not of type List."); - } - - return toggles; + if (toggleGroup == null) + { + throw new ArgumentNullException(nameof(toggleGroup)); + } + + if (togglesFieldInfo == null) + { + throw new InvalidOperationException("Unable to access the 'm_Toggles' field."); + } + + var toggles = togglesFieldInfo.GetValue(toggleGroup) as List; + if (toggles == null) + { + throw new InvalidCastException("The 'm_Toggles' field is not of type List."); + } + + return toggles; // return (List)togglesFieldInfo.GetValue(toggleGroup); } @@ -78,7 +82,6 @@ namespace XericLibrary.Runtime.MacroLibrary return toggleGroup.GetToggles().Count; } - /// /// 在单选项组上注册一个事件,当组中的任意成员变成激活状态时调用(其他的不会发生调用)。 @@ -96,6 +99,7 @@ namespace XericLibrary.Runtime.MacroLibrary }); } } + /// /// 清空单选项组中的所有事件(与注册所有事件对应,但那个事件没法单独注销) /// @@ -107,7 +111,7 @@ namespace XericLibrary.Runtime.MacroLibrary toggle.onValueChanged.RemoveAllListeners(); } } - + #region toggle 索引 /// @@ -134,45 +138,43 @@ namespace XericLibrary.Runtime.MacroLibrary #endregion #region 字段属性 - - [LabelText("单选组")] public ToggleGroup ToggleGroup; - - [SerializeField, LabelText("编辑单选项目顺序")] - [ListDrawerSettings(OnTitleBarGUI = "GetAndSortToggle")] +#if ODIN_INSPECTOR + [LabelText("单选组")] +#endif + public ToggleGroup ToggleGroup; +#if ODIN_INSPECTOR + [SerializeField, LabelText("编辑单选项目顺序")] [ListDrawerSettings(OnTitleBarGUI = "GetAndSortToggle")] +#endif private List toggleList = new List(); - + // 当前选中的项目 private int nowSelectToggleIndex = 0; private Toggle nowSelectToggle = null; - - + + public Transform TogglesContext => ToggleGroup.transform; - + /// /// 当前选中的toggle索引 /// public int NowSelectToggleIndex => nowSelectToggleIndex; - + /// /// 当前选中的toggle /// public Toggle NowSelectToggle => nowSelectToggle; - + /// /// 获取并给列表排序(顺序不一定与拼音有关) /// public void GetAndSortToggle() { -#if UNITY_EDITOR +#if UNITY_EDITOR && ODIN_INSPECTOR // 自动获取并排序 if (SirenixEditorGUI.ToolbarButton(EditorIcons.Refresh)) { - var newToggleList = MacroSort.FullCharacterOrderSort(ToggleGroup.GetToggles(), a => a.name).ToList(); - if (newToggleList.Count <= 0 || newToggleList == null) - Debug.LogError("如果无法更新获取自动排序toggle,可能是因为toggleGroup被隐藏了,手动将其激活后再获取即可。"); - else - toggleList = newToggleList; + GetSortToggle(); } // 反转顺序 if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown)) @@ -180,12 +182,17 @@ namespace XericLibrary.Runtime.MacroLibrary toggleList.Reverse(); } #else - var newToggleList = MacroSort.FullCharacterOrderSort(ToggleGroup.GetToggles(), a => a.name).ToList(); + GetSortToggle(); +#endif + void GetSortToggle() + { + var newToggleList = MacroSort.FullCharacterOrderSort(ToggleGroup.GetToggles(), a => a.name) + .ToList(); if (newToggleList.Count <= 0 || newToggleList == null) Debug.LogError("如果无法更新获取自动排序toggle,可能是因为toggleGroup被隐藏了,手动将其激活后再获取即可。"); else toggleList = newToggleList; -#endif + } } #endregion @@ -226,7 +233,7 @@ namespace XericLibrary.Runtime.MacroLibrary // 未指定组时,说明压根没用这部分功能,用不着初始化。 if (ToggleGroup == null) return; - + // 防呆警告 if (toggleList.Count <= 0) { @@ -237,13 +244,14 @@ namespace XericLibrary.Runtime.MacroLibrary Debug.LogWarning($"在初始化单选项组时,{ToggleGroup.name}并未预先指定索引顺序,将默认使用大纲顺序。"); } } + // 事件初始化 for (int i = 0; i < toggleList.Count; i++) { var toggle = toggleList[i]; - + ToggleAddEvent(toggle); - + if (toggle.isOn) { nowSelectToggleIndex = i; @@ -263,12 +271,12 @@ namespace XericLibrary.Runtime.MacroLibrary public int AddToggle(Toggle t) { ToggleAddEvent(t); - + var resultIndex = toggleList.Count; toggleList.Add(t); return resultIndex; } - + /// /// 移除一个toggle,这不会影响其他toggle的索引,但此处移除的位置会为空。 /// @@ -282,12 +290,12 @@ namespace XericLibrary.Runtime.MacroLibrary var index = toggleList.IndexOf(t); if (index < 0) return false; - - t.onValueChanged.RemoveAllListeners(); + + t.onValueChanged.RemoveAllListeners(); toggleList[index] = null; return true; } - + /// /// 清除toggle /// @@ -300,11 +308,11 @@ namespace XericLibrary.Runtime.MacroLibrary if (allowDestroy) Object.Destroy(t); } + toggleList.Clear(); } - - + /// /// toggle注册的事件,只有当按下时才需要调用此事件。 /// @@ -316,7 +324,7 @@ namespace XericLibrary.Runtime.MacroLibrary if (a) ToggleRegister(t); }); } - + /// /// toggle注册的事件,只有当按下时才需要调用此事件。 /// @@ -328,9 +336,8 @@ namespace XericLibrary.Runtime.MacroLibrary OnAnyToggleSwitchOn?.Invoke(t); OnAnyToggleIndexSwitchOn?.Invoke(nowSelectToggleIndex); } - - - + + /// /// 获取toggle代表的索引 /// @@ -361,6 +368,7 @@ namespace XericLibrary.Runtime.MacroLibrary { target.isOn = true; } + /// /// 设置单选项激活 /// @@ -372,6 +380,7 @@ namespace XericLibrary.Runtime.MacroLibrary SetToggleOn(toggleList[index]); } } + /// /// 设置单选项激活 /// @@ -380,6 +389,7 @@ namespace XericLibrary.Runtime.MacroLibrary { target.SetIsOnWithoutNotify(true); } + /// /// 设置单选项激活 /// @@ -391,7 +401,7 @@ namespace XericLibrary.Runtime.MacroLibrary SetToggleOnWithoutNotify(toggleList[index]); } } - + /// /// 清除映射结构(不会清除toggle实例) @@ -411,11 +421,11 @@ namespace XericLibrary.Runtime.MacroLibrary { Object.Destroy(toggleList[i]); } + Clear(); } #endregion - } #endregion @@ -485,8 +495,8 @@ namespace XericLibrary.Runtime.MacroLibrary /// /// /// - public static RectTransform RectTransform(this T target) - where T : Component + public static RectTransform RectTransform(this T target) + where T : Component => target.transform as RectTransform; #endregion diff --git a/Runtime/XericLibrary.dll b/Runtime/XericLibrary.dll index 6136294..9f005fb 100644 Binary files a/Runtime/XericLibrary.dll and b/Runtime/XericLibrary.dll differ