44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using Architecture.Variables;
|
|
|
|
namespace Architecture.Editor
|
|
{
|
|
/// <summary>
|
|
/// 变量资产的 Inspector 绘制器:在字段右侧实时显示当前值(含 Play 模式运行时值),
|
|
/// 设计师无需打开脚本即可看到数值,降低沟通成本。
|
|
/// </summary>
|
|
[CustomPropertyDrawer(typeof(FloatVariable))]
|
|
[CustomPropertyDrawer(typeof(IntVariable))]
|
|
[CustomPropertyDrawer(typeof(BoolVariable))]
|
|
[CustomPropertyDrawer(typeof(Vector3Variable))]
|
|
public class VariableDrawer : PropertyDrawer
|
|
{
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
var target = property.objectReferenceValue as ScriptableObject;
|
|
if (target != null)
|
|
{
|
|
var so = new SerializedObject(target);
|
|
so.Update();
|
|
var valueProp = so.FindProperty("_value");
|
|
Rect objRect = new Rect(position.x, position.y, position.width * 0.58f, position.height);
|
|
Rect valRect = new Rect(position.x + position.width * 0.60f, position.y, position.width * 0.40f, position.height);
|
|
EditorGUI.ObjectField(objRect, property, GUIContent.none);
|
|
if (valueProp != null)
|
|
{
|
|
EditorGUI.BeginDisabledGroup(true);
|
|
EditorGUI.PropertyField(valRect, valueProp, GUIContent.none);
|
|
EditorGUI.EndDisabledGroup();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUI.ObjectField(position, property, label);
|
|
}
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
}
|