LoginSignup
3
1

More than 3 years have passed since last update.

インスペクタのパラメータの名前を簡単に変えるエディタ拡張

Last updated at Posted at 2018-04-25

属性

CustomLabelAttribute.cs
using UnityEngine;

public class CustomLabelAttribute : PropertyAttribute
{
    public readonly string Value;

    public CustomLabelAttribute(string value)
    {
        Value = value;
    }
}

エディタ側のコード

CustomLabelDrawer.cs

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(CustomLabelAttribute))]
public class CustomLabelDrawer : PropertyDrawer
{
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var newLabel = attribute as CustomLabelAttribute;
            EditorGUI.PropertyField(position, property, new GUIContent(newLabel.Value), true);
        }

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUI.GetPropertyHeight(property, true);
        }
}

追記2019/7/19
Rectや配列等のマルチラインに対応

使用側のコードサンプル

UseCustomLabelAttribute.cs
using UnityEngine;

public class UseCustomLabelAttribute : MonoBehaviour
{
    [CustomLabel("カウント")]
    public int Count;
}

適用前

スクリーンショット 2018-04-25 21.40.09.png

適用後

スクリーンショット 2018-04-25 21.41.02.png

名前だけ表示を変えたい事がよくあるんですけど
Unityの標準機能であるかな、と探してても見つからなかったので作りました。
競合とかは一切考えてないです

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1