Skip to content

Commit c6e2208

Browse files
committed
Change host component back to field
1 parent 3727757 commit c6e2208

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

Editor/PropertyDrawers/ComponentStackDrawer.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,27 @@ private void FixDuplicateReferences(SerializedProperty stack)
221221

222222
private float DrawItem(Rect position, SerializedProperty arrayProp, SerializedProperty stackProp, int i)
223223
{
224-
var elem = arrayProp.GetArrayElementAtIndex(i);
225-
var obj = elem.GetValue() as StackComponent;
226-
if(obj != null) elem.FindPropertyRelative("hostComponent").objectReferenceValue = stackProp.serializedObject.targetObject as MonoBehaviour;
227-
var drawer = GetDrawerFor(obj?.GetType() ?? typeof(StackElementDrawer));
224+
try
225+
{
226+
var elem = arrayProp.GetArrayElementAtIndex(i);
227+
var obj = elem.GetValue() as StackComponent;
228+
if(obj != null) elem.FindPropertyRelative("hostComponent").objectReferenceValue = stackProp.serializedObject.targetObject as MonoBehaviour;
229+
var drawer = GetDrawerFor(obj?.GetType() ?? typeof(StackElementDrawer));
228230

229-
position.height = ItemHeaderHeight;
231+
position.height = ItemHeaderHeight;
230232

231-
drawer.OnHeaderGUI(position, i, elem, obj, stackProp, arrayProp);
233+
drawer.OnHeaderGUI(position, i, elem, obj, stackProp, arrayProp);
232234

233-
position.xMin += 2;
234-
position.xMax -= 2;
235-
if(elem.isExpanded && obj != null)
235+
position.xMin += 2;
236+
position.xMax -= 2;
237+
if(elem.isExpanded && obj != null)
238+
{
239+
drawer.OnGUI(ref position, elem, obj, stackProp);
240+
}
241+
}
242+
catch (Exception e)
236243
{
237-
drawer.OnGUI(ref position, elem, obj, stackProp);
244+
e.LogException();
238245
}
239246
return position.yMax;
240247
}

Runtime/Collections/ComponentStack.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public abstract class ComponentStack<T> : IEnumerable<T> where T : StackComponen
1313
[SerializeField, SerializeReference]
1414
protected List<T> stack = new List<T>();
1515

16-
public MonoBehaviour HostComponent { get; private set; }
16+
[SerializeField, HideInInspector]
17+
private MonoBehaviour hostComponent;
18+
public MonoBehaviour HostComponent => hostComponent;
1719

1820
public T this[int index]
1921
{
@@ -23,9 +25,9 @@ public T this[int index]
2325

2426
public int Count => stack.Count;
2527

26-
public void SetHost(MonoBehaviour hostComponent)
28+
public void SetHost(MonoBehaviour host)
2729
{
28-
HostComponent = hostComponent;
30+
hostComponent = host;
2931
}
3032

3133
public void Add(T item) => stack.Add(item);

0 commit comments

Comments
 (0)