72 lines
No EOL
3.2 KiB
C#
72 lines
No EOL
3.2 KiB
C#
#if UNITY_EDITOR
|
|
using ShiroginSDK.Runtime.Modules.RemoteConfig.Scripts.SO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace ShiroginSDK.Editor.RemoteConfig
|
|
{
|
|
[CustomPropertyDrawer(typeof(RemoteConfigDefinition.Entry))]
|
|
public class EntryDrawer : PropertyDrawer
|
|
{
|
|
private static readonly Color StringColor = new(0.55f, 0.9f, 0.6f);
|
|
private static readonly Color NumberColor = new(0.55f, 0.75f, 1f);
|
|
private static readonly Color BoolColor = new(1f, 0.85f, 0.55f);
|
|
private static readonly Color BorderColor = new(0.35f, 0.35f, 0.35f);
|
|
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
return 3 * EditorGUIUtility.singleLineHeight + 24f;
|
|
}
|
|
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
|
|
var typeProp = property.FindPropertyRelative("Type");
|
|
var valueType = (RemoteConfigDefinition.ValueType)typeProp.enumValueIndex;
|
|
|
|
var bgColor = valueType switch
|
|
{
|
|
RemoteConfigDefinition.ValueType.String => StringColor,
|
|
RemoteConfigDefinition.ValueType.Number => NumberColor,
|
|
RemoteConfigDefinition.ValueType.Boolean => BoolColor,
|
|
_ => Color.gray
|
|
};
|
|
|
|
var boxRect = new Rect(position.x + 4, position.y + 2, position.width - 8, position.height - 4);
|
|
EditorGUI.DrawRect(boxRect, new Color(bgColor.r, bgColor.g, bgColor.b, 0.25f));
|
|
Handles.color = BorderColor;
|
|
Handles.DrawAAPolyLine(1.5f, new Vector3(boxRect.x, boxRect.yMax), new Vector3(boxRect.xMax, boxRect.yMax));
|
|
|
|
var y = boxRect.y + 4;
|
|
var lh = EditorGUIUtility.singleLineHeight + 6;
|
|
|
|
EditorGUI.PropertyField(new Rect(boxRect.x + 6, y, boxRect.width - 12, lh - 4),
|
|
property.FindPropertyRelative("Key"), new GUIContent("🔑 Key"));
|
|
y += lh;
|
|
|
|
EditorGUI.PropertyField(new Rect(boxRect.x + 6, y, boxRect.width - 12, lh - 4),
|
|
typeProp, new GUIContent("🎛️ Type"));
|
|
y += lh;
|
|
|
|
switch (valueType)
|
|
{
|
|
case RemoteConfigDefinition.ValueType.String:
|
|
EditorGUI.PropertyField(new Rect(boxRect.x + 6, y, boxRect.width - 12, lh - 4),
|
|
property.FindPropertyRelative("StringValue"), new GUIContent("🧩 String Value"));
|
|
break;
|
|
case RemoteConfigDefinition.ValueType.Number:
|
|
EditorGUI.PropertyField(new Rect(boxRect.x + 6, y, boxRect.width - 12, lh - 4),
|
|
property.FindPropertyRelative("NumberValue"), new GUIContent("🔢 Number Value"));
|
|
break;
|
|
case RemoteConfigDefinition.ValueType.Boolean:
|
|
EditorGUI.PropertyField(new Rect(boxRect.x + 6, y, boxRect.width - 12, lh - 4),
|
|
property.FindPropertyRelative("BoolValue"), new GUIContent("✅ Boolean Value"));
|
|
break;
|
|
}
|
|
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
}
|
|
#endif |