[Unity] 동적 변경 검사기 표시

검사기의 속성에 따라 동적 변경 표시 내용을 변경합니다.


각 설정의 표시/숨겨진 단순 샘플을 체크 상자가 있는 경우에만 전환합니다.
  • 동작 결과
  • Game Object 측면
  • 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;
        }
    }
    
  • 편집기 옆
  • 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
    

    좋은 웹페이지 즐겨찾기