Unity Editor 확장 Attribute
3899 단어 Unity
Attribute
편집은 할 수 없지만 표시되는 Attribute의 작성
ReadOnlyAttribute.cs를 만들고 아래 소스 작성
ReadOnlyAttribute
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//<summary>
//ReadOnlyというAttributeを定義するためのクラス
//クラス名に「Attribute」を入れる必要がある
//</summary>
#if UNITY_EDITOR
using UnityEditor;
#endif
public class ReadOnlyAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
[CustomPropertyDrawer (typeof (ReadOnlyAttribute))]
public class ReadOnlyAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUI.PropertyField(position, property, label, true);
EditorGUI.EndDisabledGroup();
}
}
#endif
다른 스크립트에 다음 소스 작성
ExampleAttribute
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleAttribute : MonoBehaviour
{
[ReadOnly]
public int ReadOnlyPublicInt;
[SerializeField, ReadOnly]
private int ReadOnlyPrivateInt;
}
결과
Reference
이 문제에 관하여(Unity Editor 확장 Attribute), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/bu-ta/items/99fbf760a2f80fcb284b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)