Skip to content

Commit

Permalink
Update BaseVariableEditor.cs
Browse files Browse the repository at this point in the history
fixes DanielEverland#140
if(IsClampable) -> if(_isClamped.boolValue)

fixes DanielEverland#141
now invokes Raise event when value changed in Inspector

Adds a "Raise" button to invoke event.
  • Loading branch information
Monsoonexe committed Feb 7, 2021
1 parent d827386 commit 6c61835
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions Assets/SO Architecture/Editor/Inspectors/BaseVariableEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class BaseVariableEditor : UnityEditor.Editor
protected bool IsClamped { get { return Target.IsClamped; } }

private SerializedProperty _valueProperty;
private SerializedProperty _developerDescription;
private SerializedProperty _readOnly;
private SerializedProperty _raiseWarning;
private SerializedProperty _isClamped;
Expand All @@ -30,6 +31,7 @@ protected virtual void OnEnable()
_isClamped = serializedObject.FindProperty("_isClamped");
_minValueProperty = serializedObject.FindProperty("_minClampedValue");
_maxValueProperty = serializedObject.FindProperty("_maxClampedValue");
_developerDescription = serializedObject.FindProperty("developerDescription");

_raiseWarningAnimation = new AnimBool(_readOnly.boolValue);
_raiseWarningAnimation.valueChanged.AddListener(Repaint);
Expand All @@ -40,17 +42,34 @@ protected virtual void OnEnable()
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawDeveloperDescription();

EditorGUILayout.Space();

DrawValue();

EditorGUILayout.Space();

DrawClampedFields();
DrawReadonlyField();
EditorGUILayout.Space();
DrawRaiseButton();
}
protected virtual void DrawValue()
{
GenericPropertyDrawer.DrawPropertyDrawerLayout(_valueProperty, Target.Type);
using (var scope = new EditorGUI.ChangeCheckScope())
{
string content = "Cannot display value. No PropertyDrawer for (" + Target.Type + ") [" + Target.ToString() + "]";
GenericPropertyDrawer.DrawPropertyDrawerLayout(_valueProperty, Target.Type);

if (scope.changed)
{
serializedObject.ApplyModifiedProperties();

// Value changed, raise events
Target.Raise();
}
}
}
protected void DrawClampedFields()
{
Expand All @@ -73,9 +92,16 @@ protected void DrawClampedFields()
}

}
protected virtual void DrawRaiseButton()
{
if (GUILayout.Button("Raise"))
{
Target.Raise();
}
}
protected void DrawReadonlyField()
{
if (IsClampable)
if (_isClamped.boolValue)
return;

EditorGUILayout.PropertyField(_readOnly, new GUIContent("Read Only", READONLY_TOOLTIP));
Expand All @@ -91,6 +117,10 @@ protected void DrawReadonlyField()
}
}
}
protected void DrawDeveloperDescription()
{
EditorGUILayout.PropertyField(_developerDescription);
}
}
[CustomEditor(typeof(BaseVariable<,>), true)]
public class BaseVariableWithEventEditor : BaseVariableEditor
Expand Down

0 comments on commit 6c61835

Please sign in to comment.