Last active
March 20, 2019 04:43
-
-
Save TsubameUnity/8665b65b22021bdc0e1a24f88db9f338 to your computer and use it in GitHub Desktop.
シリアライズしたプロパティの名前を自動で整形します。使い方はこんな感じ。[field: SerializeField, ShapePropertyName] public string Property { get; set; }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
class ShapePropertyNameAttribute : PropertyAttribute | |
{ | |
#if UNITY_EDITOR | |
[CustomPropertyDrawer(typeof(ShapePropertyNameAttribute))] | |
class FieldNameDrawer : PropertyDrawer | |
{ | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
string propertyName = property.name; | |
if (attribute is ShapePropertyNameAttribute && propertyName.EndsWith("k__BackingField")) | |
label.text = propertyName.Substring(1, propertyName.IndexOf(">") - 1); | |
EditorGUI.PropertyField(position, property, label, true); | |
} | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment