Last active
November 19, 2022 06:31
-
-
Save atori708/0f114ed239abd5dc8588684d17f19cf7 to your computer and use it in GitHub Desktop.
【Unity】インスペクタ上のラベルを日本語で表示するAttribute
This file contains 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 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