Skip to content

Commit

Permalink
Cleaned up debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEverland committed Apr 19, 2020
1 parent b8432d1 commit 4349b9f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 318 deletions.
4 changes: 2 additions & 2 deletions Assets/SO Architecture/Editor/Drawers/BaseReferenceDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ private void DrawGenericPropertyField(Rect position, Rect valueRect)
position.y += EditorGUIUtility.singleLineHeight;
position.height = GenericPropertyDrawer.GetHeight(constantValue, ValueType);

GenericPropertyDrawer.DrawPropertyDrawerNew(position, constantValue, ValueType);
GenericPropertyDrawer.DrawPropertyDrawer(position, constantValue, ValueType);
}
}
else
{
GenericPropertyDrawer.DrawPropertyDrawerNew(valueRect, constantValue, ValueType, false);
GenericPropertyDrawer.DrawPropertyDrawer(valueRect, constantValue, ValueType, false);
}
}
private Rect GetConstantMultilineRect(Rect position, Rect valueRect)
Expand Down
307 changes: 5 additions & 302 deletions Assets/SO Architecture/Editor/Drawers/GenericPropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class GenericPropertyDrawer
private const string DefaultErrorLabelText = "Type is not drawable! Please implement property drawer";
private const string NullPropertyText = "SerializedProperty is null. Your custom type is probably missing the [Serializable] attribute";

public static void DrawPropertyDrawerNew(Rect rect, SerializedProperty property, Type type, bool drawLabel = true)
public static void DrawPropertyDrawer(Rect rect, SerializedProperty property, Type type, bool drawLabel = true)
{
if (property == null)
{
Expand All @@ -34,10 +34,10 @@ public static void DrawPropertyDrawerNew(Rect rect, SerializedProperty property,
{
PropertyDrawIterator iter = new PropertyDrawIterator(rect, property.Copy(), drawLabel);

DrawPropertyDrawerNewInternal(iter);
DrawPropertyDrawerInternal(iter);
}
}
public static void DrawPropertyDrawerLayoutNew(SerializedProperty property, Type type, bool drawLabel = true)
public static void DrawPropertyDrawerLayout(SerializedProperty property, Type type, bool drawLabel = true)
{
if(property == null)
{
Expand All @@ -60,10 +60,10 @@ public static void DrawPropertyDrawerLayoutNew(SerializedProperty property, Type
{
PropertyDrawIteratorLayout iter = new PropertyDrawIteratorLayout(property.Copy(), drawLabel);

DrawPropertyDrawerNewInternal(iter);
DrawPropertyDrawerInternal(iter);
}
}
private static void DrawPropertyDrawerNewInternal(IPropertyDrawIterator iter)
private static void DrawPropertyDrawerInternal(IPropertyDrawIterator iter)
{
do
{
Expand Down Expand Up @@ -100,302 +100,5 @@ public static float GetHeight(SerializedProperty property, Type type)
return spacing + elementHeights;
}
}

//private class Iterator
//{
// public Iterator(SerializedProperty property)
// {
// iterator = property.Copy();
// endProperty = iterator.GetEndProperty();
// }

// protected readonly SerializedProperty iterator;
// protected readonly SerializedProperty endProperty;

// private bool consumeChildren;
// private int parentDepth;

// public bool Next()
// {
// bool nextVisible = iterator.NextVisible(true);
// bool canDraw = CanDraw();

// if (nextVisible)
// {
// if (consumeChildren)
// {
// ConsumeSingleLineFields(parentDepth);
// consumeChildren = false;
// }

// int depth = iterator.depth;
// if (IsSingleLine(iterator))
// {
// parentDepth = depth;
// consumeChildren = true;
// }
// }

// return nextVisible && canDraw;
// }

// public virtual void End()
// {

// }
// private bool CanDraw()
// {
// return !SerializedProperty.EqualContents(iterator, endProperty);
// }
// private void ConsumeSingleLineFields(int depth)
// {
// do
// {
// iterator.Next(true);
// } while (iterator.depth != depth);
// }
// private bool IsSingleLine(SerializedProperty property)
// {
// switch (property.propertyType)
// {
// case SerializedPropertyType.Vector3:
// case SerializedPropertyType.Vector2:
// case SerializedPropertyType.Vector3Int:
// case SerializedPropertyType.Vector2Int:
// case SerializedPropertyType.Vector4:
// case SerializedPropertyType.Quaternion:
// case SerializedPropertyType.Rect:
// case SerializedPropertyType.RectInt:
// case SerializedPropertyType.Bounds:
// case SerializedPropertyType.BoundsInt:
// return true;
// }

// return false;
// }
//}
//private class DrawIterator : Iterator
//{
// public DrawIterator(Rect rect, SerializedProperty property, bool drawLabel) : base(property)
// {
// this.drawLabel = drawLabel;
// this.rect = rect;
// this.rect.height = EditorGUIUtility.singleLineHeight;
// startIndentLevel = EditorGUI.indentLevel;
// startDepth = iterator.depth;
// }

// private readonly bool drawLabel;
// private readonly int startIndentLevel;

// private int startDepth;
// private Rect rect;


// public void Draw()
// {
// EditorGUI.indentLevel = GetIndent(iterator.depth);

// if (IsCustom(iterator))
// {
// DrawHeader();
// }
// else
// {
// DrawValue();
// }

// rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// }


// public override void End()
// {
// base.End();

// EditorGUI.indentLevel = startIndentLevel;
// }
// private void DrawHeader()
// {
// EditorGUI.LabelField(rect, iterator.displayName);
// }
// private void DrawValue()
// {
// if (drawLabel)
// {
// EditorGUI.PropertyField(rect, iterator);
// }
// else
// {
// EditorGUI.PropertyField(rect, iterator, GUIContent.none);
// }
// }

// private int GetIndent(int depth)
// {
// // Depth starts at 1, whereas indent starts at 0. So we subtract 1
// return startIndentLevel + (depth - startDepth) - 1;
// }
// private Rect GetFieldRect()
// {
// return new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
// }
// private void NextLine()
// {
// rect.y += EditorGUIUtility.singleLineHeight * 3;
// }


// private bool IsCustom(SerializedProperty property)
// {
// return property.propertyType == SerializedPropertyType.Generic;
// }
//}



public static void DrawPropertyDrawer(Rect rect, GUIContent label, Type type, SerializedProperty property, GUIContent errorLabel)
{
if (errorLabel == GUIContent.none)
errorLabel = GetDefaultErrorLabel();

if (IsDrawable(type))
{
//Unity doesn't like it when you have scene objects on assets,
//so we do some magic to display it anyway
if (typeof(Object).IsAssignableFrom(type)
&& !EditorUtility.IsPersistent(property.objectReferenceValue)
&& property.objectReferenceValue != null)
{
using (new EditorGUI.DisabledGroupScope(true))
{
EditorGUI.ObjectField(rect, label, property.objectReferenceValue, type, false);
}
}
else if (TryDrawBuiltinType(rect, label, type, property))
{
}
else
{
EditorGUI.PropertyField(rect, property, label);
}
}
else
{
EditorGUI.LabelField(rect, errorLabel);
}
}

private static bool TryDrawBuiltinType(Rect rect, GUIContent label, Type type, SerializedProperty property)
{
if(typeof(Color).IsAssignableFrom(type))
{
EditorGUI.ColorField(rect, property.colorValue);
return true;
}
else if(typeof(AnimationCurve).IsAssignableFrom(type))
{
EditorGUI.CurveField(rect, property.animationCurveValue);
return true;
}
else if(typeof(double).IsAssignableFrom(type))
{
EditorGUI.DoubleField(rect, property.doubleValue);
return true;
}
else if(typeof(float).IsAssignableFrom(type))
{
EditorGUI.FloatField(rect, property.floatValue);
return true;
}
else if(typeof(int).IsAssignableFrom(type))
{
EditorGUI.IntField(rect, property.intValue);
return true;
}
else if(typeof(string).IsAssignableFrom(type))
{
EditorGUI.TextField(rect, property.stringValue);
return true;
}
else if(typeof(long).IsAssignableFrom(type))
{
EditorGUI.LongField(rect, property.longValue);
return true;
}
else if(typeof(bool).IsAssignableFrom(type))
{
EditorGUI.Toggle(rect, property.boolValue);
return true;
}
else if(typeof(Vector2).IsAssignableFrom(type))
{
EditorGUI.Vector2Field(rect, label, property.vector2Value);
return true;
}
else if(typeof(Vector3).IsAssignableFrom(type))
{
EditorGUI.Vector3Field(rect, label, property.vector3Value);
return true;
}
else if(typeof(Vector4).IsAssignableFrom(type))
{
EditorGUI.Vector4Field(rect, label, property.vector4Value);
return true;
}
else if(typeof(Quaternion).IsAssignableFrom(type))
{
EditorGUI.Vector4Field(rect, label, property.quaternionValue.ToVector4());
return true;
}

return false;
}

public static void DrawPropertyDrawerLayout(Type type, GUIContent label, SerializedProperty property, GUIContent errorLabel)
{
if (IsDrawable(type))
{
//Unity doesn't like it when you have scene objects on assets,
//so we do some magic to display it anyway
if (typeof(Object).IsAssignableFrom(type)
&& !EditorUtility.IsPersistent(property.objectReferenceValue)
&& property.objectReferenceValue != null)
{
using (new EditorGUI.DisabledGroupScope(true))
{
EditorGUILayout.ObjectField(label, property.objectReferenceValue, type, false);
}
}
else if (type.IsAssignableFrom(typeof(Quaternion)))
{
Vector4 displayValue = property.quaternionValue.ToVector4();

property.quaternionValue = EditorGUILayout.Vector4Field(label, displayValue).ToQuaternion();
}
else if (type.IsAssignableFrom(typeof(Vector4)))
{
property.vector4Value = EditorGUILayout.Vector4Field(label, property.vector4Value);
}
else
{
EditorGUILayout.PropertyField(property, label);
}
}
else
{
EditorGUILayout.LabelField(errorLabel);
}
}

private static bool IsDrawable(Type type)
{
return SOArchitecture_EditorUtility.HasPropertyDrawer(type) || typeof(Object).IsAssignableFrom(type) || type.IsEnum;
}

private static GUIContent GetDefaultErrorLabel()
{
return new GUIContent(DefaultErrorLabelText);
}
}
}
15 changes: 4 additions & 11 deletions Assets/SO Architecture/Editor/Inspectors/BaseVariableEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,15 @@ public override void OnInspectorGUI()
serializedObject.Update();

DrawValue();

EditorGUILayout.Space();

DrawClampedFields();
DrawReadonlyField();
}
protected virtual void DrawValue()
{
//EditorGUILayout.PropertyField(_valueProperty);
GenericPropertyDrawer.DrawPropertyDrawerLayoutNew(_valueProperty, Target.Type);
//GenericPropertyDrawer.DrawPropertyDrawerLayoutNew(serializedObject.GetIterator(), Target.Type);

EditorGUILayout.Space();

//Rect rect = new Rect()
//rect.height = GenericPropertyDrawer.GetHeight(_valueProperty, Target.Type);

//GenericPropertyDrawer.DrawPropertyDrawerNew(rect, _valueProperty, Target.Type);
//GUILayout.Space(rect.height);
GenericPropertyDrawer.DrawPropertyDrawerLayout(_valueProperty, Target.Type);
}
protected void DrawClampedFields()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)

EditorGUI.BeginDisabledGroup(DISABLE_ELEMENTS);

GenericPropertyDrawer.DrawPropertyDrawerNew(rect, property, Target.Type);
GenericPropertyDrawer.DrawPropertyDrawer(rect, property, Target.Type);

EditorGUI.EndDisabledGroup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ protected override void DrawRaiseButton()
using (var scope = new EditorGUI.ChangeCheckScope())
{
Type debugValueType = GetDebugValueType(property);
//EditorGUILayout.PropertyField(property);
GenericPropertyDrawer.DrawPropertyDrawerLayoutNew(property, debugValueType);
GenericPropertyDrawer.DrawPropertyDrawerLayout(property, debugValueType);

if (scope.changed)
{
Expand Down

0 comments on commit 4349b9f

Please sign in to comment.