-
-
Save aarthificial/f2dbb58e4dbafd0a93713a380b9612af to your computer and use it in GitHub Desktop.
Revisions
-
aarthificial revised this gist
Jun 27, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,10 +27,13 @@ GUIContent label EditorGUI.PropertyField(position, valueProperty, label, true); EditorGUI.EndDisabledGroup(); int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; position.x += position.width + 24; position.width = position.height = EditorGUI.GetPropertyHeight(enabledProperty); position.x -= position.width; EditorGUI.PropertyField(position, enabledProperty, GUIContent.none); EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); } } -
aarthificial revised this gist
May 17, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ using UnityEngine; [Serializable] /// Requires Unity 2020.1+ public struct Optional<T> { [SerializeField] private bool enabled; -
aarthificial revised this gist
Mar 22, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ GUIContent label var valueProperty = property.FindPropertyRelative("value"); var enabledProperty = property.FindPropertyRelative("enabled"); EditorGUI.BeginProperty(position, label, property); position.width -= 24; EditorGUI.BeginDisabledGroup(!enabledProperty.boolValue); EditorGUI.PropertyField(position, valueProperty, label, true); @@ -30,6 +31,7 @@ GUIContent label position.width = position.height = EditorGUI.GetPropertyHeight(enabledProperty); position.x -= position.width; EditorGUI.PropertyField(position, enabledProperty, GUIContent.none); EditorGUI.EndProperty(); } } } -
aarthificial created this gist
Mar 14, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ using System; using UnityEngine; [Serializable] public struct Optional<T> { [SerializeField] private bool enabled; [SerializeField] private T value; public bool Enabled => enabled; public T Value => value; public Optional(T initialValue) { enabled = true; value = initialValue; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ using UnityEditor; using UnityEngine; namespace Editor { [CustomPropertyDrawer(typeof(Optional<>))] public class OptionalPropertyDrawer : PropertyDrawer { public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { var valueProperty = property.FindPropertyRelative("value"); return EditorGUI.GetPropertyHeight(valueProperty); } public override void OnGUI( Rect position, SerializedProperty property, GUIContent label ) { var valueProperty = property.FindPropertyRelative("value"); var enabledProperty = property.FindPropertyRelative("enabled"); position.width -= 24; EditorGUI.BeginDisabledGroup(!enabledProperty.boolValue); EditorGUI.PropertyField(position, valueProperty, label, true); EditorGUI.EndDisabledGroup(); position.x += position.width + 24; position.width = position.height = EditorGUI.GetPropertyHeight(enabledProperty); position.x -= position.width; EditorGUI.PropertyField(position, enabledProperty, GUIContent.none); } } }