Merge pull request #56 from Akeit0/support2021

Fix: support 2021.3 & 2022.1
This commit is contained in:
Annulus Games 2024-03-01 14:35:22 +09:00 committed by GitHub
commit ea19961861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 91 additions and 2 deletions

View File

@ -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))
{

View File

@ -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;

View File

@ -229,5 +229,6 @@ namespace Alchemy.Inspector
public string OnItemsSourceChanged { get; set; }
public string OnSelectionChanged { get; set; }
public string OnSelectedIndicesChanged { get; set; }
}
}

View File

@ -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))
]
@ -28,6 +30,16 @@ public class OnListViewChangedTest : MonoBehaviour
Debug.Log($"Removed: [{string.Join(',', indices)}]");
}
void OnItemChosen(IEnumerable<object> items)
{
Debug.Log($"Chosen: [{string.Join(',', items)}]");
}
void OnSelectionChanged(IEnumerable<object> items)
{
Debug.Log($"Selection Changed: [{string.Join(',', items)}]");
}
void OnSelectedIndicesChanged(IEnumerable<int> indices)
{
Debug.Log($"Selected: [{string.Join(',', indices)}]");

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