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

Commit d5b6a07

Browse files
Rewrote runtimeset inspector to be un-assignable yet still debugable
1 parent 15d6363 commit d5b6a07

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

Assets/SO Architecture/Editor/Inspectors/RuntimeSetEditor.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,49 @@
33
using UnityEditorInternal;
44
using UnityEngine;
55

6-
[CustomEditor(typeof(RuntimeSet<>), true)]
6+
[CustomEditor(typeof(BaseRuntimeSet), true)]
77
public class RuntimeSetEditor : Editor
88
{
9-
private SOArchitectureBaseObject Target { get { return (SOArchitectureBaseObject)target; } }
9+
private BaseRuntimeSet Target { get { return (BaseRuntimeSet)target; } }
1010
private SerializedProperty DeveloperDescription { get { return serializedObject.FindProperty("DeveloperDescription"); } }
11-
11+
12+
private ReorderableList _reorderableList;
13+
14+
private void OnEnable()
15+
{
16+
SerializedProperty items = serializedObject.FindProperty("_items");
17+
18+
string title = "List (" + Target.Type + ")";
19+
20+
_reorderableList = new ReorderableList(serializedObject, items, false, true, false, true);
21+
_reorderableList.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, title); };
22+
_reorderableList.drawElementCallback += DrawElement;
23+
_reorderableList.onRemoveCallback += Remove;
24+
_reorderableList.onChangedCallback += (ReorderableList list) => { Repaint(); };
25+
}
1226
public override void OnInspectorGUI()
1327
{
14-
//EditorGUILayout.HelpBox("Cannot inspect sets. They're meant to contain runtime-data only, and assets cannot have those assigned through the editor", MessageType.Info);
28+
serializedObject.Update();
29+
30+
_reorderableList.DoLayoutList();
1531

1632
EditorGUILayout.PropertyField(DeveloperDescription);
33+
34+
serializedObject.ApplyModifiedProperties();
35+
}
36+
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
37+
{
38+
rect.height = EditorGUIUtility.singleLineHeight;
39+
rect.y++;
40+
41+
SerializedProperty property = _reorderableList.serializedProperty.GetArrayElementAtIndex(index);
42+
43+
EditorGUI.BeginDisabledGroup(true);
44+
EditorGUI.ObjectField(rect, "Element " + index, property.objectReferenceValue, Target.Type, false);
45+
EditorGUI.EndDisabledGroup();
46+
}
47+
private void Remove(ReorderableList list)
48+
{
49+
Target.Items.RemoveAt(list.index);
1750
}
1851
}

Assets/SO Architecture/Runtime Sets/BaseRuntimeSet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using Type = System.Type;
45

56
public abstract class BaseRuntimeSet : SOArchitectureBaseObject, IEnumerable
67
{
@@ -19,6 +20,7 @@ public object this[int index]
1920
public int Count { get { return Items.Count; } }
2021

2122
public abstract IList Items { get; }
23+
public abstract Type Type { get; }
2224

2325
IEnumerator IEnumerable.GetEnumerator()
2426
{

Assets/SO Architecture/Runtime Sets/RuntimeSet.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45

@@ -26,6 +27,13 @@ public override IList Items
2627
return _items;
2728
}
2829
}
30+
public override Type Type
31+
{
32+
get
33+
{
34+
return typeof(T);
35+
}
36+
}
2937

3038
public void Add(T obj)
3139
{

0 commit comments

Comments
 (0)