Fix : support 2021.3 & 2022.1

This commit is contained in:
Akeit0 2024-02-27 11:01:43 +09:00
parent e21ac9e231
commit 55e9495c88
6 changed files with 86 additions and 3 deletions

View File

@ -100,9 +100,25 @@ namespace Alchemy.Editor.Elements
{ {
AddField(new IntegerField(label), (int)obj); AddField(new IntegerField(label), (int)obj);
} }
else if (type == typeof(uint)) else if (type == typeof(uint))
{ {
#if UNITY_2022_2_OR_NEWER
AddField(new UnsignedIntegerField(label), (uint)obj); 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)) else if (type == typeof(long))
{ {
@ -110,7 +126,21 @@ namespace Alchemy.Editor.Elements
} }
else if (type == typeof(ulong)) 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)) else if (type == typeof(float))
{ {

View File

@ -82,26 +82,50 @@ namespace Alchemy.Editor
if (events.OnItemsRemoved == null) return; if (events.OnItemsRemoved == null) return;
ReflectionHelper.Invoke(target, events.OnItemsRemoved, new object[] { indices }); ReflectionHelper.Invoke(target, events.OnItemsRemoved, new object[] { indices });
}; };
#if UNITY_2022_2_OR_NEWER
listView.itemsChosen += items => listView.itemsChosen += items =>
{ {
if (events.OnItemsChosen == null) return; if (events.OnItemsChosen == null) return;
ReflectionHelper.Invoke(target, events.OnItemsChosen, new object[] { items }); 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) => listView.itemIndexChanged += (before, after) =>
{ {
if (events.OnItemIndexChanged == null) return; if (events.OnItemIndexChanged == null) return;
ReflectionHelper.Invoke(target, events.OnItemIndexChanged, new object[] { before, after }); ReflectionHelper.Invoke(target, events.OnItemIndexChanged, new object[] { before, after });
}; };
#if UNITY_2022_2_OR_NEWER
listView.selectionChanged += items => listView.selectionChanged += items =>
{ {
if (events.OnSelectionChanged == null) return; if (events.OnSelectionChanged == null) return;
ReflectionHelper.Invoke(target, events.OnSelectionChanged, new object[] { items }); ReflectionHelper.Invoke(target, events.OnSelectionChanged, new object[] { items });
}; };
listView.selectedIndicesChanged += indices => listView.selectedIndicesChanged += indices =>
{ {
if (events.OnSelectedIndicesChanged== null) return; if (events.OnSelectedIndicesChanged== null) return;
ReflectionHelper.Invoke(target, events.OnSelectedIndicesChanged, new object[] { indices }); 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 += () => listView.itemsSourceChanged += () =>
{ {
if (events.OnItemsSourceChanged == null) return; if (events.OnItemsSourceChanged == null) return;

View File

@ -225,9 +225,13 @@ namespace Alchemy.Inspector
public string OnItemIndexChanged { get; set; } public string OnItemIndexChanged { get; set; }
public string OnItemsAdded { get; set; } public string OnItemsAdded { get; set; }
public string OnItemsRemoved { get; set; } public string OnItemsRemoved { get; set; }
#if UNITY_2022_1_OR_NEWER
public string OnItemsChosen { get; set; } public string OnItemsChosen { get; set; }
#endif
public string OnItemsSourceChanged { get; set; } public string OnItemsSourceChanged { get; set; }
#if UNITY_2022_1_OR_NEWER
public string OnSelectionChanged { get; set; } public string OnSelectionChanged { get; set; }
public string OnSelectedIndicesChanged { get; set; } public string OnSelectedIndicesChanged { get; set; }
#endif
} }
} }

View File

@ -8,7 +8,10 @@ public class OnListViewChangedTest : MonoBehaviour
OnItemChanged = nameof(OnItemChanged), OnItemChanged = nameof(OnItemChanged),
OnItemsAdded = nameof(OnItemsAdded), OnItemsAdded = nameof(OnItemsAdded),
OnItemsRemoved = nameof(OnItemsRemoved), OnItemsRemoved = nameof(OnItemsRemoved),
#if UNITY_2022_1_OR_NEWER
OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged),
#endif
OnItemIndexChanged = nameof(OnItemIndexChanged)) OnItemIndexChanged = nameof(OnItemIndexChanged))
] ]
public int[] array; public int[] array;
@ -27,12 +30,12 @@ public class OnListViewChangedTest : MonoBehaviour
{ {
Debug.Log($"Removed: [{string.Join(',', indices)}]"); Debug.Log($"Removed: [{string.Join(',', indices)}]");
} }
#if UNITY_2022_1_OR_NEWER
void OnSelectedIndicesChanged(IEnumerable<int> indices) void OnSelectedIndicesChanged(IEnumerable<int> indices)
{ {
Debug.Log($"Selected: [{string.Join(',', indices)}]"); Debug.Log($"Selected: [{string.Join(',', indices)}]");
} }
#endif
void OnItemIndexChanged(int before, int after) void OnItemIndexChanged(int before, int after)
{ {
Debug.Log($"Index Changed: [{before} -> {after}]"); Debug.Log($"Index Changed: [{before} -> {after}]");

View File

@ -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");
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b9202060cef47b8a30b53a9f413fbcb
timeCreated: 1708998502