同步更新
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
"name": "Lrss3.SesothoLine.Editor",
|
||||
"rootNamespace": "SesothoLineEditor",
|
||||
"references": [
|
||||
"Lrss3.Deconstruction",
|
||||
"UnityEditor.UI"
|
||||
"Lrss3.SesothoLine",
|
||||
"Lrss3.Deconstruction"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+31
-21
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,7 +28,8 @@ 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<Toggle> GetToggles(this ToggleGroup toggleGroup)
|
||||
{
|
||||
@@ -79,7 +83,6 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 在单选项组上注册一个事件,当组中的任意成员变成激活状态时调用(其他的不会发生调用)。
|
||||
/// </summary>
|
||||
@@ -96,6 +99,7 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空单选项组中的所有事件(与注册所有事件对应,但那个事件没法单独注销)
|
||||
/// </summary>
|
||||
@@ -134,11 +138,13 @@ 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<Toggle> toggleList = new List<Toggle>();
|
||||
|
||||
// 当前选中的项目
|
||||
@@ -164,15 +170,11 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
/// </summary>
|
||||
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
|
||||
@@ -237,6 +244,7 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
Debug.LogWarning($"在初始化单选项组时,{ToggleGroup.name}并未预先指定索引顺序,将默认使用大纲顺序。");
|
||||
}
|
||||
}
|
||||
|
||||
// 事件初始化
|
||||
for (int i = 0; i < toggleList.Count; i++)
|
||||
{
|
||||
@@ -300,11 +308,11 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
if (allowDestroy)
|
||||
Object.Destroy(t);
|
||||
}
|
||||
|
||||
toggleList.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// toggle注册的事件,只有当按下时才需要调用此事件。
|
||||
/// </summary>
|
||||
@@ -330,7 +338,6 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取toggle代表的索引
|
||||
/// </summary>
|
||||
@@ -361,6 +368,7 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
target.isOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置单选项激活
|
||||
/// </summary>
|
||||
@@ -372,6 +380,7 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
SetToggleOn(toggleList[index]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置单选项激活
|
||||
/// </summary>
|
||||
@@ -380,6 +389,7 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
target.SetIsOnWithoutNotify(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置单选项激活
|
||||
/// </summary>
|
||||
@@ -411,11 +421,11 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
Object.Destroy(toggleList[i]);
|
||||
}
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user