更新日 2022/7/18
【Unity】ボックスを表示するエディター拡張方法を紹介します!
ボックスを表示するエディター拡張方法を紹介します。

Box属性を作成する
ボックス表示用のBox属性を作成します。
BoxAttribute.cs
using System;
namespace UnityEngine
{
[AttributeUsage(AttributeTargets.Field)]
public class BoxAttribute : PropertyAttribute
{
public readonly string label;
public BoxAttribute(string label)
{
this.label = label;
}
}
}
BoxDrawerの作成
ボックスを表示するのにGUI.Box関数を呼びます。
今回作成するボックスはプロパティーの変更はないのでボックス表示して終わりです。
BoxDrawer.cs
using UnityEngine;
namespace UnityEditor
{
[CustomPropertyDrawer(typeof(BoxAttribute))]
public class BoxDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var box = attribute as BoxAttribute;
GUI.Box(position, box.label);
}
}
}
ボックスを表示する
Box属性の引数は表示したいラベル文字列です。
using UnityEngine;
public class TestScript : MonoBehaviour
{
[Box("Box")]
public int box;
}

中心に文字列を表示するボックス表示を紹介しました。
何に使えるのか分かりませんが、こういったものもあるということで・・・。
関連ページ
こちらのページも合わせてご覧下さい。

【Unity】エディター拡張方法をまとめます!2022/9/21

【Unity】Vector4を1行で表示するエディター拡張を紹介します!2022/7/6

【Unity】両端編集可能なスライダーを表示するエディター拡張を紹介します!2022/7/11

【Unity】ツールバー表示するエディター拡張方法を紹介します!2022/7/14

【Unity】プログレスバーを表示するエディター拡張方法を紹介します!2022/7/15