Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BaseVariableEditor.cs #142

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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