Skip to content

Instantly share code, notes, and snippets.

@XakazukinX
Created April 8, 2019 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XakazukinX/5ddee72c45f149b110c84224b76e200d to your computer and use it in GitHub Desktop.
Save XakazukinX/5ddee72c45f149b110c84224b76e200d to your computer and use it in GitHub Desktop.
そのフィールドをインスペクタから変更できなくする自作属性
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace shigeno_EditorUtility
{
public class NonEditableAttribute : PropertyAttribute
{
}
[CustomPropertyDrawer(typeof(NonEditableAttribute))]
public class NonEditableDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
NonEditableAttribute NonEditable = (NonEditableAttribute) attribute;
EditorGUI.BeginDisabledGroup(true);
EditorGUI.PropertyField(position, property, label);
EditorGUI.EndDisabledGroup();
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment