インスペクタのプロパティ変更に応じて、表示内容を動的に変更する。
チェックボックスの有無で、各設定の表示/非表示が切り替わるだけの、簡単なサンプル
HogeEditor.cs
using UnityEngine;
public class HogeObject : MonoBehaviour
{
public bool EnableShadow = false;
public ShadowSetteing Setteing = new ShadowSetteing();
[System.Serializable]
public class ShadowSetteing
{
public Color EffectColor;
public Vector2 Distance;
public bool UseAlpha;
}
}
- Editor側
HogeObjectEditor.cs
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(HogeObject))]
public class HogeObjectEditor : Editor
{
private HogeObject _target;
private void Awake()
{
_target = target as HogeObject;
}
public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
_target.EnableShadow = EditorGUILayout.ToggleLeft("EnableShadow", _target.EnableShadow);
if (_target.EnableShadow)
{
EditorGUILayout.LabelField("影の設定");
_target.Setteing.EffectColor = EditorGUILayout.ColorField("色", _target.Setteing.EffectColor);
_target.Setteing.Distance = EditorGUILayout.Vector2Field("距離", _target.Setteing.Distance);
_target.Setteing.UseAlpha = EditorGUILayout.Toggle("透過", _target.Setteing.UseAlpha);
}
// GUIの更新があったら実行
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(_target);
}
}
}
#endif