oscarabraham / uitkeditoraid Goto Github PK
View Code? Open in Web Editor NEWUI Toolkit elements and utilities for custom Editor interfaces in Unity.
Home Page: https://artehacker.com/UITKEditorAid/
License: MIT License
UI Toolkit elements and utilities for custom Editor interfaces in Unity.
Home Page: https://artehacker.com/UITKEditorAid/
License: MIT License
I seem to be having trouble understanding how to use this library. I have the following basic setup below, which throws errors in the console whenever I reorder list elements, but when I try to use the ArrayPropertyField on my items list, it produces the same errors as before.
How am I supposed to use this library with what I have?
using System;
using System.Collections.Generic;
using UnityEngine;
public class GenericTest : MonoBehaviour
{
[SerializeReference] public List<Item> items = new()
{
new IntItem(){value = 1},
new IntItem(){value = 2},
new FloatItem(){value = 3.5f},
new StringItem(){value = "Hello World"}
};
[ContextMenu("Refresh List")]
private void RefreshParameters()
{
items = new()
{
new IntItem(){value = 1},
new IntItem(){value = 2},
new FloatItem(){value = 3.5f},
new StringItem(){value = "Hello World"}
};
}
}
[Serializable]
public abstract class Item { }
[Serializable]
public abstract class Item<T> : Item
{
public T value;
}
[Serializable]
public class IntItem : Item<int> { }
[Serializable]
public class FloatItem : Item<float> { }
[Serializable]
public class StringItem : Item<string> { }
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
[CustomEditor(typeof(GenericTest))]
public class GenericTestInspector : UnityEditor.Editor
{
private SerializedProperty itemList;
private void OnEnable()
{
itemList = serializedObject.FindProperty("items");
}
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new PropertyField(itemList));
root.Bind(serializedObject);
return root;
}
}
using SCVS.Common.Editor.Extensions;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
[CustomPropertyDrawer(typeof(Item<>), true)]
public class ItemPropertyDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var root = new VisualElement();
var value = property.FindPropertyRelative("value");
root.Add(new PropertyField(value).BindProperty2(value));
return root;
}
}
Hey there,
Looks like you have been doing some great work here. It would definitely be helpful to folks if there were a few samples of each one that could be seen in action. I checked through the documentation, while it is quite complete, I didn't see any actual example usage. I see that you have images of each one, do you happen to a scene with a few objects in it that you used in the images somewhere? It is always helpful to have a working copy to quickly check out to see if it would work as expected.
Here is one I threw together using a few scriptableobjects if anyone needs it.
// --------------------------
// --| MonoTest.cs ----------
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace instance.id
{
[ExecuteInEditMode]
public class MonoTest : MonoBehaviour
{
public List<TestSO> groupList = new List<TestSO>();
private void OnEnable()
{
if (groupList.Count != 0) return;
var gList = AssetDatabase.FindAssets($"t:{nameof(TestSO)}")
.Select(guid => AssetDatabase.LoadAssetAtPath<TestSO>(AssetDatabase.GUIDToAssetPath(guid)))
.ToList();
if (gList.Count != 0) groupList = gList;
else groupList.AddRange(new[]
{
ScriptableObject.CreateInstance<TestSO>(),
ScriptableObject.CreateInstance<TestSO>(),
ScriptableObject.CreateInstance<TestSO>()
});
for (int i = 0; i < groupList.Count; i++)
{
if (string.IsNullOrEmpty(groupList[i].name)) groupList[i].name = $"TestSO{i}";
}
}
}
}
// --------------------------
// --| Place in Editor folder
// --| MonoTestEditor.cs ----
using ArteHacker.UITKEditorAid;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace instance.id.Editors
{
[CustomEditor(typeof(MonoTest))]
public class MonoTestEditor : Editor
{
private ListOfInspectors inspectorList;
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
var gList = serializedObject.FindProperty("groupList");
inspectorList = new ListOfInspectors(gList);
root.Add(inspectorList);
root.Bind(serializedObject);
root.Add(base.CreateInspectorGUI());
return root;
}
}
}
using System.Collections.Generic;
using UnityEngine;
// --------------------------
// --| TestSO.cs ------------
namespace instance.id
{
[CreateAssetMenu(menuName = "Test/TestObject", fileName = "TestObject.asset")]
public class TestSO : ScriptableObject
{
public string someData;
public float floatData;
public List<Color> colorList = new List<Color>();
private void OnEnable()
{
if (colorList.Count == 0)
colorList.AddRange(new[]
{
new Color(), new Color(), new Color()
});
}
}
}
It seems recent Unity versions are a lot more efficient when binding multiple fields separately: https://github.com/needle-mirror/com.unity.ui/blob/7ae45176671504f37ebb5a5c3bacdc63cb692837/Editor/Bindings/BindingExtensions.cs#L854
I still need to take a good look there, but it seems that it'd be better to bind/rebind each element immediately instead of using the rebinder system. I'd gladly appreciate any insight that anyone has about this. Anyway, if my hunch results true, there's a decision to make:
I'm a lot more inclined to do the second option. I'm no longer using 2019.4 because I need generics serialization; so I'm okay with ditching older versions. It just seems easier and more practical. That said, a version 2 doesn't necessarily need to remove support for older Unity versions in the manifest; things should still work there, just a lot slower. I'd be probably okay; I believe things would also be slower in earlier versions of 2020.2, anyway. That's another decision to ponder, though.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.