1
Fork 0
slime-blood-and-pain/Assets/Editor/BeforeStartAttributeDrawer.cs

21 lines
795 B
C#
Raw Normal View History

2019-04-27 12:21:33 +00:00
//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(BeforeStartAttribute))]
public class BeforeStartAttributeDrawer : PropertyDrawer
{
// Necessary since some properties tend to collapse smaller than their content
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
// Draw a disabled property field
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = !Application.isPlaying;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}