From 55e9495c8816d940d7fd48b1ff43180ffbc52acb Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:01:43 +0900 Subject: [PATCH] Fix : support 2021.3 & 2022.1 --- .../Alchemy/Editor/Elements/GenericField.cs | 32 ++++++++++++++++++- .../Alchemy/Editor/Internal/GUIHelper.cs | 24 ++++++++++++++ .../Runtime/Inspector/InspectorAttributes.cs | 4 +++ Alchemy/Assets/Tests/OnListViewChangedTest.cs | 7 ++-- Alchemy/Assets/Tests/UnsignedTest.cs | 19 +++++++++++ Alchemy/Assets/Tests/UnsignedTest.cs.meta | 3 ++ 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 Alchemy/Assets/Tests/UnsignedTest.cs create mode 100644 Alchemy/Assets/Tests/UnsignedTest.cs.meta diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs index 3b551d3..9722fc8 100644 --- a/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs +++ b/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs @@ -100,9 +100,25 @@ namespace Alchemy.Editor.Elements { AddField(new IntegerField(label), (int)obj); } + else if (type == typeof(uint)) { +#if UNITY_2022_2_OR_NEWER AddField(new UnsignedIntegerField(label), (uint)obj); +#else + var value = (uint)obj; + var control = new LongField(label); + control.value = value; + control.RegisterValueChangedCallback(x => + { + var newValue = (uint)Math.Clamp(control.value, 0, uint.MaxValue); + OnValueChanged?.Invoke(newValue); + control.value = newValue; + }); + + Add(control); +#endif + } else if (type == typeof(long)) { @@ -110,7 +126,21 @@ namespace Alchemy.Editor.Elements } else if (type == typeof(ulong)) { - AddField(new UnsignedLongField(label), (ulong)obj); +#if UNITY_2022_2_OR_NEWER + AddField(new UnsignedIntegerField(label), (ulong)obj); +#else + var value = (ulong)obj; + var control = new LongField(label); + control.value = (long)value; + control.RegisterValueChangedCallback(x => + { + var newValue = (long)Math.Clamp(control.value, 0, long.MaxValue); + OnValueChanged?.Invoke(newValue); + control.value = newValue; + }); + + Add(control); +#endif } else if (type == typeof(float)) { diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs index 70c9649..d8d30ad 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs @@ -82,26 +82,50 @@ namespace Alchemy.Editor if (events.OnItemsRemoved == null) return; ReflectionHelper.Invoke(target, events.OnItemsRemoved, new object[] { indices }); }; +#if UNITY_2022_2_OR_NEWER listView.itemsChosen += items => { if (events.OnItemsChosen == null) return; ReflectionHelper.Invoke(target, events.OnItemsChosen, new object[] { items }); }; +#elif UNITY_2022_1_OR_NEWER + listView.onItemsChosen += items => + { + if (events.OnItemsChosen == null) return; + ReflectionHelper.Invoke(target, events.OnItemsChosen, new object[] { items }); + }; +#endif + listView.itemIndexChanged += (before, after) => { if (events.OnItemIndexChanged == null) return; ReflectionHelper.Invoke(target, events.OnItemIndexChanged, new object[] { before, after }); }; +#if UNITY_2022_2_OR_NEWER listView.selectionChanged += items => { if (events.OnSelectionChanged == null) return; ReflectionHelper.Invoke(target, events.OnSelectionChanged, new object[] { items }); }; + listView.selectedIndicesChanged += indices => { if (events.OnSelectedIndicesChanged== null) return; ReflectionHelper.Invoke(target, events.OnSelectedIndicesChanged, new object[] { indices }); }; +#elif UNITY_2022_1_OR_NEWER + listView.onSelectionChanged += items => + { + if (events.OnSelectionChanged == null) return; + ReflectionHelper.Invoke(target, events.OnSelectionChanged, new object[] { items }); + }; + + listView.onSelectedIndicesChange += indices => + { + if (events.OnSelectedIndicesChanged== null) return; + ReflectionHelper.Invoke(target, events.OnSelectedIndicesChanged, new object[] { indices }); + }; +#endif listView.itemsSourceChanged += () => { if (events.OnItemsSourceChanged == null) return; diff --git a/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs b/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs index 0479176..fffed14 100644 --- a/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs +++ b/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs @@ -225,9 +225,13 @@ namespace Alchemy.Inspector public string OnItemIndexChanged { get; set; } public string OnItemsAdded { get; set; } public string OnItemsRemoved { get; set; } +#if UNITY_2022_1_OR_NEWER public string OnItemsChosen { get; set; } +#endif public string OnItemsSourceChanged { get; set; } +#if UNITY_2022_1_OR_NEWER public string OnSelectionChanged { get; set; } public string OnSelectedIndicesChanged { get; set; } +#endif } } \ No newline at end of file diff --git a/Alchemy/Assets/Tests/OnListViewChangedTest.cs b/Alchemy/Assets/Tests/OnListViewChangedTest.cs index 249aad0..19e6e1a 100644 --- a/Alchemy/Assets/Tests/OnListViewChangedTest.cs +++ b/Alchemy/Assets/Tests/OnListViewChangedTest.cs @@ -8,7 +8,10 @@ public class OnListViewChangedTest : MonoBehaviour OnItemChanged = nameof(OnItemChanged), OnItemsAdded = nameof(OnItemsAdded), OnItemsRemoved = nameof(OnItemsRemoved), +#if UNITY_2022_1_OR_NEWER OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), +#endif + OnItemIndexChanged = nameof(OnItemIndexChanged)) ] public int[] array; @@ -27,12 +30,12 @@ public class OnListViewChangedTest : MonoBehaviour { Debug.Log($"Removed: [{string.Join(',', indices)}]"); } - +#if UNITY_2022_1_OR_NEWER void OnSelectedIndicesChanged(IEnumerable indices) { Debug.Log($"Selected: [{string.Join(',', indices)}]"); } - +#endif void OnItemIndexChanged(int before, int after) { Debug.Log($"Index Changed: [{before} -> {after}]"); diff --git a/Alchemy/Assets/Tests/UnsignedTest.cs b/Alchemy/Assets/Tests/UnsignedTest.cs new file mode 100644 index 0000000..5aa55e8 --- /dev/null +++ b/Alchemy/Assets/Tests/UnsignedTest.cs @@ -0,0 +1,19 @@ +using Alchemy.Inspector; +using UnityEngine; + +namespace Tests +{ + public class UnsignedTest : MonoBehaviour + { + [Button] + public void TestUint(uint value) + { + Debug.Log("TestLong"); + } + [Button] + public void TestULong(ulong value) + { + Debug.Log("TestULong"); + } + } +} \ No newline at end of file diff --git a/Alchemy/Assets/Tests/UnsignedTest.cs.meta b/Alchemy/Assets/Tests/UnsignedTest.cs.meta new file mode 100644 index 0000000..da6f358 --- /dev/null +++ b/Alchemy/Assets/Tests/UnsignedTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8b9202060cef47b8a30b53a9f413fbcb +timeCreated: 1708998502 \ No newline at end of file