77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace NanoBrain {
|
|
|
|
[CustomEditor(typeof(Brain))]
|
|
public class NanoBrainComponent_Editor : Editor {
|
|
protected static VisualElement mainContainer;
|
|
protected static VisualElement inspectorContainer;
|
|
|
|
protected Brain component;
|
|
private SerializedProperty brainProp;
|
|
|
|
public void OnEnable() {
|
|
component = target as Brain;
|
|
|
|
if (Application.isPlaying == false && serializedObject != null) {
|
|
string propertyName = nameof(Brain.brainPrefab);
|
|
brainProp = serializedObject.FindProperty(propertyName);
|
|
}
|
|
}
|
|
|
|
public override VisualElement CreateInspectorGUI() {
|
|
Cluster brain = component.brain;
|
|
|
|
if (Application.isPlaying == false)
|
|
serializedObject.Update();
|
|
|
|
|
|
VisualElement root = new() {
|
|
style = {
|
|
paddingLeft = 0,
|
|
paddingRight = 0,
|
|
paddingTop = 0,
|
|
paddingBottom = 0
|
|
}
|
|
};
|
|
root.styleSheets.Add(Resources.Load<StyleSheet>("GraphStyles"));
|
|
|
|
//if (Application.isPlaying == false) {
|
|
PropertyField brainField = new(brainProp) {
|
|
label = "Cluster Prefab"
|
|
};
|
|
root.Add(brainField);
|
|
//}
|
|
|
|
if (brain != null)
|
|
CreateViewer(root, brain.prefab, brain.defaultOutput, component.gameObject);
|
|
|
|
if (Application.isPlaying == false)
|
|
serializedObject.ApplyModifiedProperties();
|
|
return root;
|
|
}
|
|
|
|
public static ClusterViewer.GraphView CreateViewer(VisualElement root, ClusterPrefab cluster, Nucleus output, GameObject gameObject) {
|
|
VisualElement mainContainer = new() {
|
|
style = {
|
|
flexDirection = FlexDirection.Row,
|
|
minHeight = 450
|
|
}
|
|
};
|
|
ClusterViewer.GraphView graph = new(cluster);
|
|
graph.style.flexGrow = 1;
|
|
|
|
mainContainer.Add(graph);
|
|
root.Add(mainContainer);
|
|
|
|
graph.SetGraph(gameObject, output);
|
|
|
|
return graph;
|
|
}
|
|
}
|
|
|
|
} |