Skip to content

Instantly share code, notes, and snippets.

@XakazukinX
Last active April 8, 2019 19:46
Show Gist options
  • Save XakazukinX/9f9e2cbd49d9d85601b5b8be88dcf686 to your computer and use it in GitHub Desktop.
Save XakazukinX/9f9e2cbd49d9d85601b5b8be88dcf686 to your computer and use it in GitHub Desktop.
変数名の代わりに好きな文字列をインスペクタに表示できるカスタム属性
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace shigeno_EditorUtility
{
public class CustomLabelAttribute : PropertyAttribute
{
public string newFieldLabel;
public CustomLabelAttribute(string _newLabel)
{
this.newFieldLabel = _newLabel;
}
}
[CustomPropertyDrawer(typeof(CustomLabelAttribute))]
public class Drawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
CustomLabelAttribute customLabel = (CustomLabelAttribute) attribute;
label.text = customLabel.newFieldLabel;
EditorGUI.PropertyField(position, property, label);
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment