101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
[CustomEditor(typeof(NanoBrain))]
|
|
public class NanoBrainComponent_Editor : Editor {
|
|
protected static VisualElement mainContainer;
|
|
protected static VisualElement inspectorContainer;
|
|
|
|
protected NanoBrain component;
|
|
private SerializedProperty brainProp;
|
|
|
|
ClusterInspector.GraphView board;
|
|
|
|
public void OnEnable() {
|
|
component = target as NanoBrain;
|
|
|
|
if (Application.isPlaying == false)
|
|
brainProp = serializedObject.FindProperty(nameof(NanoBrain.defaultBrain));
|
|
|
|
}
|
|
|
|
public override VisualElement CreateInspectorGUI() {
|
|
Cluster brain = component.brain;
|
|
|
|
if (Application.isPlaying == false)
|
|
serializedObject.Update();
|
|
|
|
|
|
VisualElement root = new();
|
|
//ClusterInspector.GraphView board =
|
|
ClusterInspector.CreateInspector(root, brain.prefab);
|
|
// root.style.paddingLeft = 0;
|
|
// root.style.paddingRight = 0;
|
|
// root.style.paddingTop = 0;
|
|
// root.style.paddingBottom = 0;
|
|
|
|
// root.styleSheets.Add(Resources.Load<StyleSheet>("GraphStyles"));
|
|
|
|
// if (Application.isPlaying == false) {
|
|
// PropertyField brainField = new(brainProp) {
|
|
// label = "Nano Brain"
|
|
// };
|
|
// root.Add(brainField);
|
|
// }
|
|
|
|
// mainContainer = new() {
|
|
// name = "main",
|
|
// style = {
|
|
// height = 450,
|
|
// }
|
|
// };
|
|
// board = new ClusterInspector.GraphView();
|
|
// board.style.flexGrow = 1;
|
|
// mainContainer.Add(board);
|
|
|
|
// inspectorContainer = new VisualElement {
|
|
// name = "inspector"
|
|
// // style = {
|
|
// // width = 400,
|
|
// // }
|
|
// };
|
|
|
|
// mainContainer.Add(inspectorContainer);
|
|
// root.Add(mainContainer);
|
|
|
|
// // Run once for initial state (use resolved style width if available)
|
|
// float initialWidth = root.layout.width > 0 ? root.layout.width : root.contentRect.width;
|
|
// UpdateLayout(initialWidth);
|
|
|
|
// // React to size changes of root (or parent if appropriate)
|
|
// root.RegisterCallback<GeometryChangedEvent>(evt => {
|
|
// UpdateLayout(evt.newRect.width);
|
|
// });
|
|
|
|
// if (brain != null && board != null)
|
|
// board.SetGraph(component.gameObject, brain.prefab, brain.output, inspectorContainer);
|
|
// else
|
|
// Debug.LogWarning(" No brain!");
|
|
|
|
if (Application.isPlaying == false)
|
|
serializedObject.ApplyModifiedProperties();
|
|
return root;
|
|
}
|
|
|
|
// private void UpdateLayout(float containerWidth) {
|
|
// // if (containerWidth > 800f) {
|
|
// mainContainer.style.flexDirection = FlexDirection.Row;
|
|
// inspectorContainer.style.width = 300; // fixed sidebar width
|
|
// inspectorContainer.style.flexGrow = 0;
|
|
// // }
|
|
// // else {
|
|
// // mainContainer.style.flexDirection = FlexDirection.Column;
|
|
// // inspectorContainer.style.width = Length.Percent(100); // full width below
|
|
// // inspectorContainer.style.flexDirection = FlexDirection.Column;
|
|
// // inspectorContainer.style.flexGrow = 1; // can set 0 or keep as needed
|
|
// // }
|
|
// }
|
|
|
|
} |