Skip to content

Instantly share code, notes, and snippets.

@atori708
Last active November 19, 2022 06:31
Show Gist options
  • Save atori708/0f114ed239abd5dc8588684d17f19cf7 to your computer and use it in GitHub Desktop.
Save atori708/0f114ed239abd5dc8588684d17f19cf7 to your computer and use it in GitHub Desktop.
【Unity】インスペクタ上のラベルを日本語で表示するAttribute
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class LabelAttribute : PropertyAttribute
{
public readonly string Label;
public LabelAttribute(string label)
{
Label = label;
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(LabelAttribute))]
public class LabelAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var newLabel = attribute as LabelAttribute;
label = newLabel.Label;
EditorGUI.PropertyField(position, property, label, true);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, true);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment