Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 7000b15

Browse files
Refactored iterators
1 parent cec3382 commit 7000b15

14 files changed

Lines changed: 494 additions & 167 deletions

Assets/SO Architecture/Editor/Drawers/GenericPropertyDrawer.cs

Lines changed: 181 additions & 163 deletions
Large diffs are not rendered by default.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
namespace ScriptableObjectArchitecture.Editor
7+
{
8+
public abstract class BasePropertyDrawIterator : PropertyIterator, IPropertyDrawIterator
9+
{
10+
public BasePropertyDrawIterator(SerializedProperty property, bool drawLabel) : base(property)
11+
{
12+
this.drawLabel = drawLabel;
13+
this.startIndentLevel = EditorGUI.indentLevel;
14+
this.startDepth = iterator.depth;
15+
}
16+
17+
protected readonly bool drawLabel;
18+
protected readonly int startIndentLevel;
19+
protected readonly int startDepth;
20+
21+
protected abstract void DrawProperty();
22+
protected abstract void DrawPropertyWithLabel();
23+
24+
public virtual void Draw()
25+
{
26+
EditorGUI.indentLevel = GetIndent(iterator.depth);
27+
28+
if (IsCustom(iterator))
29+
{
30+
DrawPropertyWithLabel();
31+
}
32+
else
33+
{
34+
if(drawLabel)
35+
{
36+
DrawPropertyWithLabel();
37+
}
38+
else
39+
{
40+
DrawProperty();
41+
}
42+
}
43+
}
44+
public override void End()
45+
{
46+
base.End();
47+
48+
EditorGUI.indentLevel = startIndentLevel;
49+
}
50+
private int GetIndent(int depth)
51+
{
52+
return startIndentLevel + (depth - startDepth);
53+
}
54+
private bool IsCustom(SerializedProperty property)
55+
{
56+
return property.propertyType == SerializedPropertyType.Generic;
57+
}
58+
}
59+
}

Assets/SO Architecture/Editor/Generic Property Drawer/BasePropertyDrawIterator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace ScriptableObjectArchitecture.Editor
6+
{
7+
public interface IPropertyDrawIterator : IPropertyIterator
8+
{
9+
void Draw();
10+
}
11+
}

Assets/SO Architecture/Editor/Generic Property Drawer/IPropertyDrawIterator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace ScriptableObjectArchitecture.Editor
6+
{
7+
public interface IPropertyIterator
8+
{
9+
bool Next();
10+
void End();
11+
}
12+
13+
}

Assets/SO Architecture/Editor/Generic Property Drawer/IPropertyIterator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
namespace ScriptableObjectArchitecture.Editor
7+
{
8+
public class PropertyDrawIterator : BasePropertyDrawIterator
9+
{
10+
public PropertyDrawIterator(Rect rect, SerializedProperty property, bool drawLabel) : base(property, drawLabel)
11+
{
12+
this.rect = rect;
13+
this.rect.height = EditorGUIUtility.singleLineHeight;
14+
}
15+
16+
private Rect rect;
17+
18+
public override void Draw()
19+
{
20+
base.Draw();
21+
22+
MoveRectDownOneLine();
23+
}
24+
25+
protected override void DrawPropertyWithLabel()
26+
{
27+
EditorGUI.PropertyField(rect, iterator);
28+
}
29+
protected override void DrawProperty()
30+
{
31+
EditorGUI.PropertyField(rect, iterator, GUIContent.none);
32+
}
33+
34+
private void MoveRectDownOneLine()
35+
{
36+
rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
37+
}
38+
}
39+
}

Assets/SO Architecture/Editor/Generic Property Drawer/PropertyDrawIterator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
namespace ScriptableObjectArchitecture.Editor
7+
{
8+
public class PropertyDrawIteratorLayout : BasePropertyDrawIterator
9+
{
10+
public PropertyDrawIteratorLayout(SerializedProperty property, bool drawLabel) : base(property, drawLabel)
11+
{
12+
}
13+
14+
protected override void DrawPropertyWithLabel()
15+
{
16+
EditorGUILayout.PropertyField(iterator);
17+
}
18+
protected override void DrawProperty()
19+
{
20+
EditorGUILayout.PropertyField(iterator, GUIContent.none);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)