-
Notifications
You must be signed in to change notification settings - Fork 364
/
GraphInspector.cs
83 lines (69 loc) · 2.64 KB
/
GraphInspector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using UnityEngine;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using System;
using System.Reflection;
namespace GraphProcessor
{
public class GraphInspector : Editor
{
protected VisualElement root;
protected BaseGraph graph;
protected ExposedParameterFieldFactory exposedParameterFactory;
VisualElement parameterContainer;
protected virtual void OnEnable()
{
graph = target as BaseGraph;
graph.onExposedParameterListChanged += UpdateExposedParameters;
graph.onExposedParameterModified += UpdateExposedParameters;
if (exposedParameterFactory == null)
exposedParameterFactory = new ExposedParameterFieldFactory(graph);
}
protected virtual void OnDisable()
{
graph.onExposedParameterListChanged -= UpdateExposedParameters;
graph.onExposedParameterModified -= UpdateExposedParameters;
exposedParameterFactory?.Dispose(); // Graphs that created in GraphBehaviour sometimes gives null ref.
exposedParameterFactory = null;
}
public sealed override VisualElement CreateInspectorGUI()
{
root = new VisualElement();
CreateInspector();
return root;
}
protected virtual void CreateInspector()
{
parameterContainer = new VisualElement{
name = "ExposedParameters"
};
FillExposedParameters(parameterContainer);
root.Add(parameterContainer);
}
protected void FillExposedParameters(VisualElement parameterContainer)
{
if (graph.exposedParameters.Count != 0)
parameterContainer.Add(new Label("Exposed Parameters:"));
foreach (var param in graph.exposedParameters)
{
if (param.settings.isHidden)
continue;
var field = exposedParameterFactory.GetParameterValueField(param, (newValue) => {
param.value = newValue;
serializedObject.ApplyModifiedProperties();
graph.NotifyExposedParameterValueChanged(param);
});
parameterContainer.Add(field);
}
}
void UpdateExposedParameters(ExposedParameter param) => UpdateExposedParameters();
void UpdateExposedParameters()
{
parameterContainer.Clear();
FillExposedParameters(parameterContainer);
}
// Don't use ImGUI
public sealed override void OnInspectorGUI() {}
}
}