BITKit/Packages/Runtime~/Unity/Scripts/Reference/ReferenceSO.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.UIElements;
#endif
namespace BITKit
{
[System.Serializable]
public class ReferenceSO : ScriptableObject
{
[TextArea]
public string value;
}
[System.Serializable]
public record ReferenceScriptableObject : References
{
public ReferenceSO so;
public override string Get() => so.value.IsNullOrEmpty() ? so.name : so.value;
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReferenceScriptableObject))]
public class ReferenceScriptableObjectDrawer : BITProperty
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
VisualElement root = new();
root.Add(base.CreatePropertyGUI(property));
Button button = new();
root.Add(button);
return root;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
base.OnGUI(position, property, label);
EditorGUI.PropertyField(position, property);
EditorGUI.LinkButton(position, "New Button");
}
}
#endif
}