diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/GenericField.cs index 3b551d3..0c69d5c 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_1_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)) { +#if UNITY_2022_1_OR_NEWER AddField(new UnsignedLongField(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..ba935f3 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_1_OR_NEWER listView.itemsChosen += items => { if (events.OnItemsChosen == null) return; ReflectionHelper.Invoke(target, events.OnItemsChosen, new object[] { items }); }; +#else + 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_1_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 }); }; +#else + listView.onSelectionChange += 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..4a025a5 100644 --- a/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs +++ b/Alchemy/Assets/Alchemy/Runtime/Inspector/InspectorAttributes.cs @@ -229,5 +229,6 @@ namespace Alchemy.Inspector public string OnItemsSourceChanged { get; set; } public string OnSelectionChanged { get; set; } public string OnSelectedIndicesChanged { get; set; } + } } \ No newline at end of file diff --git a/Alchemy/Assets/Tests/OnListViewChangedTest.cs b/Alchemy/Assets/Tests/OnListViewChangedTest.cs index 249aad0..5e2599e 100644 --- a/Alchemy/Assets/Tests/OnListViewChangedTest.cs +++ b/Alchemy/Assets/Tests/OnListViewChangedTest.cs @@ -8,6 +8,8 @@ public class OnListViewChangedTest : MonoBehaviour OnItemChanged = nameof(OnItemChanged), OnItemsAdded = nameof(OnItemsAdded), OnItemsRemoved = nameof(OnItemsRemoved), + OnItemsChosen = nameof(OnItemChosen), + OnSelectionChanged = nameof(OnSelectionChanged), OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), OnItemIndexChanged = nameof(OnItemIndexChanged)) ] @@ -27,12 +29,22 @@ public class OnListViewChangedTest : MonoBehaviour { Debug.Log($"Removed: [{string.Join(',', indices)}]"); } - + + void OnItemChosen(IEnumerable items) + { + Debug.Log($"Chosen: [{string.Join(',', items)}]"); + } + + void OnSelectionChanged(IEnumerable items) + { + Debug.Log($"Selection Changed: [{string.Join(',', items)}]"); + } + void OnSelectedIndicesChanged(IEnumerable indices) { Debug.Log($"Selected: [{string.Join(',', indices)}]"); } - + 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