Get it on Google Play


Wm뮤 :: 유니티 프로퍼티 드로워

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2021. 12. 16. 16:39 Unity

https://docs.unity3d.com/kr/2021.3/Manual/editor-PropertyDrawers.html

 

프로퍼티 드로어 - Unity 매뉴얼

프로퍼티 드로어는 스크립트에서 속성을 사용하거나 특정 Serializable 클래스가 표시되어야 하는 방법을 제어하여 인스펙터(Inspector) 창 에 특정 컨트롤이 표시되는 방법을 커스터마이즈할 때 사

docs.unity3d.com

 

공식 매뉴얼

 

비슷한것으론 DecoratorDrawer가 있다

 

 

 

 

 

 

 

 

[ReadOnly] 로 사용

이건 내가 만든게 아니다

원문링크 : https://discussions.unity.com/t/how-to-make-a-readonly-property-in-inspector/75448



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
    public override float GetPropertyHeight(SerializedProperty property,GUIContent label)
    {
        return EditorGUI.GetPropertyHeight(property, label, true);
    }

    public override void OnGUI(Rect position,SerializedProperty property,GUIContent label)
    {
        GUI.enabled = false;
        {
            EditorGUI.PropertyField(position, property, label, true);
        }
        GUI.enabled = true;
    }
}

#endif
public class ReadOnlyAttribute : PropertyAttribute
{

}

 

 

 

 

이걸로 다중배열은 안 되니 뻘짓하지 말자

왜냐면 배열은 프로퍼티드로워는 OnGUI에서 하위 항목만 접근 가능하고

다중배열은 접근불가하게 원천으로 차단해버린다

 

 

 

 

 

그리고 이걸로 버튼 어트리뷰트 만들어볼려고 했는데 필드에만 선언이 되어서

ContextMenu로 대체했다

자세한건 어트리뷰트 참고

 

https://wmmu.tistory.com/entry/%EC%9C%A0%EB%8B%88%ED%8B%B0-%EC%BB%A4%EC%8A%A4%ED%85%80-%EC%9D%B8%EC%8A%A4%ED%8E%99%ED%84%B0-%EC%8B%AC%ED%94%8C%ED%83%80%EC%9E%85

 

유니티 어트리뷰트

인스펙터계열 어트리뷰트 //해당 변수가 어떤 역할인지 위에 굵은 글씨로 표시해줌 [Header("헤더이름")] //슬라이더로 표시해줌 [Range(0.5f,1.5f)] //슬라이더바가 있는 멀티라인 [TextArea(1,30)] public strin

wmmu.tistory.com

 

 

 

 

그리고 툴 만들다가 드로워로 클래스별 인스펙터를 구현할 일이 있어서 만들었다

몰론 바로 폐기되었지만 언젠가 또 쓸일이 있을듯

기능제약은 심하지만 간결해서 빠르게 작성할수 있다는점이 좋다

이 코드는 https://github.com/ahzkwid/AhzkwidAvatarTools 이곳에 잠깐 사용되었다가 삭제되었다

#if UNITY_EDITOR
    using UnityEditor;
    using UnityEditorInternal;



    [CustomPropertyDrawer(typeof(BlendshapeSettingDataAttribute))]
    public class BlendshapeSettingDataDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            var fieldRect = rect;
            fieldRect.width /= 2;
            {
                var path = nameof(BlendshapeAutoSetter.BlendshapeSettingData.name);
                EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative(path), new GUIContent(path), true);
            }


            fieldRect.x += fieldRect.width;
            EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative(nameof(BlendshapeAutoSetter.BlendshapeSettingData.value)), label, true);
        }
    }
    public class BlendshapeSettingDataAttribute : PropertyAttribute
    {

    }
#endif





    public class BlendshapeAutoSetter : MonoBehaviour
{
    [System.Serializable]
    public class BlendshapeSettingData
    {
        public string name;
        [Range(0,100)]
        public float value = 100;
    }
    [System.Serializable]
    public class BlendshapeTarget
    {
        public Mesh mesh;
        [BlendshapeSettingData]
        public List<BlendshapeSettingData> blendshapeValues;
        //public Dictionary<string,float> keyValuePairs = new Dictionary<string,float>();
    }

        bool success = false;

        public bool autoDestroy = true;

        public List<BlendshapeTarget> blendshapeTargets = new List<BlendshapeTarget>();
        }

 

 

 

 

'Unity' 카테고리의 다른 글

유니티 조인트  (0) 2021.12.18
디버그로그 음소거  (0) 2021.12.13
래그돌  (0) 2021.12.04
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입