Skip to content

Instantly share code, notes, and snippets.

@TsubameUnity
Last active March 20, 2019 04:43
Show Gist options
  • Save TsubameUnity/8665b65b22021bdc0e1a24f88db9f338 to your computer and use it in GitHub Desktop.
Save TsubameUnity/8665b65b22021bdc0e1a24f88db9f338 to your computer and use it in GitHub Desktop.
シリアライズしたプロパティの名前を自動で整形します。使い方はこんな感じ。[field: SerializeField, ShapePropertyName] public string Property { get; set; }
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