Utils/Editor/ReadOnlyOnPlayFieldDrawer.cs

18 lines
531 B
C#

using Runtime;
using UnityEditor;
using UnityEngine;
namespace Utils
{
[CustomPropertyDrawer(typeof(ReadOnlyOnPlayFieldAttribute))]
public class ReadOnlyOnPlayFieldDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var state = Application.isPlaying;
if (state) GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
if (state) GUI.enabled = true;
}
}
}