common extensions and some utilities
This commit is contained in:
34
Editor/PropertyDrawers/SerializableGuidDrawer.cs
Normal file
34
Editor/PropertyDrawers/SerializableGuidDrawer.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKitEditor.PropertyDrawers {
|
||||
[CustomPropertyDrawer(typeof(SerializableGuid))]
|
||||
public class SerializableGuidDrawer : PropertyDrawer {
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
EditorGUILayout.TextField(label, BuildGuidString(FindGuidParts(property)));
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public SerializedProperty[] FindGuidParts(SerializedProperty property) {
|
||||
SerializedProperty[] res = {
|
||||
property.FindPropertyRelative("A"),
|
||||
property.FindPropertyRelative("B"),
|
||||
property.FindPropertyRelative("C"),
|
||||
property.FindPropertyRelative("D")
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
public string BuildGuidString(SerializedProperty[] parts) {
|
||||
StringBuilder sb = new();
|
||||
sb.AppendFormat("{0:X8}", parts[0].uintValue);
|
||||
sb.AppendFormat("{0:X8}", parts[1].uintValue);
|
||||
sb.AppendFormat("{0:X8}", parts[2].uintValue);
|
||||
sb.AppendFormat("{0:X8}", parts[3].uintValue);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user