diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 47721a5..6ebb721 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -18,10 +18,56 @@ public class ClusterInspector : Editor { public override VisualElement CreateInspectorGUI() { ClusterPrefab cluster = target as ClusterPrefab; + if (cluster != null) + cluster.EnsureInitialization(); serializedObject.Update(); VisualElement root = new(); + //GraphView graph = + CreateInspector(root, cluster); + // root.style.paddingLeft = 0; + // root.style.paddingRight = 0; + // root.style.paddingTop = 0; + // root.style.paddingBottom = 0; + + // root.styleSheets.Add(Resources.Load("GraphStyles")); + + // mainContainer = new() { + // style = { + // height = 450 + // } + // }; + // GraphView graph = new(); + // graph.style.flexGrow = 1; + + // inspectorContainer = new VisualElement { + // name = "inspector" + // }; + + // mainContainer.Add(graph); + // 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(evt => { + // UpdateLayout(evt.newRect.width); + // }); + + //graph.SetGraph(null, cluster, cluster.output, inspectorContainer); + + // else + // Debug.LogWarning(" No brain!"); + + serializedObject.ApplyModifiedProperties(); + return root; + } + + public static GraphView CreateInspector(VisualElement root, ClusterPrefab cluster) { root.style.paddingLeft = 0; root.style.paddingRight = 0; root.style.paddingTop = 0; @@ -29,16 +75,23 @@ public class ClusterInspector : Editor { root.styleSheets.Add(Resources.Load("GraphStyles")); + // does the main container have added value? + // is just is like the root mainContainer = new() { style = { - height = 450 + height = 450, + flexDirection = FlexDirection.Row } }; GraphView graph = new(); graph.style.flexGrow = 1; inspectorContainer = new VisualElement { - // name = "inspector" + name = "inspector", + style = { + width = 300, + flexGrow = 0 + } }; mainContainer.Add(graph); @@ -47,24 +100,33 @@ public class ClusterInspector : Editor { // 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); + //UpdateLayout(initialWidth); // React to size changes of root (or parent if appropriate) - root.RegisterCallback(evt => { - UpdateLayout(evt.newRect.width); - }); + // root.RegisterCallback(evt => { + // UpdateLayout(evt.newRect.width); + // }); - if (cluster != null) { - cluster.EnsureInitialization(); - graph.SetGraph(null, cluster, cluster.output, inspectorContainer); - } - else - Debug.LogWarning(" No brain!"); + graph.SetGraph(null, cluster, cluster.output, inspectorContainer); - serializedObject.ApplyModifiedProperties(); - return root; + return graph; } + private static void UpdateLayout(float containerWidth) { + // if (containerWidth > 600f) { + // 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 + // } + } + + public class GraphView : VisualElement { ClusterPrefab cluster; SerializedObject serializedBrain; @@ -76,6 +138,12 @@ public class ClusterInspector : Editor { ClusterWrapper currentWrapper; + public enum OutputNodes { + Output, + Output2, + Output3 + } + public GraphView() { name = "content"; style.flexGrow = 1; @@ -88,11 +156,17 @@ public class ClusterInspector : Editor { imguiContainer.focusable = true; Add(imguiContainer); + PopupField enumField = new(System.Enum.GetValues(typeof(OutputNodes)).Cast().ToList(), OutputNodes.Output); + enumField.RegisterValueChangedCallback(evt => OnOutputChanged(evt.newValue)); + Add(enumField); + // Subscribe when added to panel (editor UI ready) RegisterCallback(evt => Subscribe()); RegisterCallback(evt => Unsubscribe()); } + void OnOutputChanged(OutputNodes output) { + } bool subscribed = false; void Subscribe() { @@ -400,7 +474,8 @@ public class ClusterInspector : Editor { if (colonPos > 0) { string baseName = nucleus.name[..colonPos]; Handles.Label(labelPos, baseName, style); - } else + } + else Handles.Label(labelPos, nucleus.name, style); } @@ -706,23 +781,6 @@ public class ClusterInspector : Editor { #endregion Start - #region Update - - private void UpdateLayout(float containerWidth) { - // if (containerWidth > 600f) { - 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 - // } - } - - #endregion Update } public class NeuroidLayer { diff --git a/Editor/NanoBrain_Editor.cs b/Editor/NanoBrain_Editor.cs index 646f384..3f4888a 100644 --- a/Editor/NanoBrain_Editor.cs +++ b/Editor/NanoBrain_Editor.cs @@ -11,14 +11,14 @@ public class NanoBrainComponent_Editor : Editor { protected NanoBrain component; private SerializedProperty brainProp; - ClusterInspector.GraphView board; + ClusterInspector.GraphView board; public void OnEnable() { component = target as NanoBrain; if (Application.isPlaying == false) brainProp = serializedObject.FindProperty(nameof(NanoBrain.defaultBrain)); - + } public override VisualElement CreateInspectorGUI() { @@ -29,56 +29,53 @@ public class NanoBrainComponent_Editor : Editor { VisualElement root = new(); - root.style.flexDirection = FlexDirection.Column; // side-by-side layout - root.style.flexGrow = 1; - root.style.minHeight = 600; - root.style.paddingLeft = 0; - root.style.paddingRight = 0; - root.style.paddingTop = 0; - root.style.paddingBottom = 0; + //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("GraphStyles")); + // root.styleSheets.Add(Resources.Load("GraphStyles")); - if (Application.isPlaying == false) { - PropertyField brainField = new(brainProp) { - label = "Nano Brain" - }; - root.Add(brainField); - } + // if (Application.isPlaying == false) { + // PropertyField brainField = new(brainProp) { + // label = "Nano Brain" + // }; + // root.Add(brainField); + // } - mainContainer = new() { - name = "main", - style = { - flexDirection = FlexDirection.Row, - flexGrow = 1, - minHeight = 500, - } - }; - board = new ClusterInspector.GraphView(); - board.style.flexGrow = 1; - mainContainer.Add(board); + // 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, - } - }; + // inspectorContainer = new VisualElement { + // name = "inspector" + // // style = { + // // width = 400, + // // } + // }; - mainContainer.Add(inspectorContainer); - root.Add(mainContainer); + // 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); + // // 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(evt => { - UpdateLayout(evt.newRect.width); - }); + // // React to size changes of root (or parent if appropriate) + // root.RegisterCallback(evt => { + // UpdateLayout(evt.newRect.width); + // }); - if (brain != null && board != null) - board.SetGraph(component.gameObject, brain.prefab, brain.output, inspectorContainer); + // if (brain != null && board != null) + // board.SetGraph(component.gameObject, brain.prefab, brain.output, inspectorContainer); // else // Debug.LogWarning(" No brain!"); @@ -87,18 +84,18 @@ public class NanoBrainComponent_Editor : Editor { return root; } - private void UpdateLayout(float containerWidth) { - // if (containerWidth > 800f) { - mainContainer.style.flexDirection = FlexDirection.Row; - inspectorContainer.style.width = 400; // 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 - // } - } + // 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 + // // } + // } } \ No newline at end of file diff --git a/Nucleus.cs b/Nucleus.cs index 8652637..247ffad 100644 --- a/Nucleus.cs +++ b/Nucleus.cs @@ -27,6 +27,7 @@ public abstract class Nucleus { _outputValue = value; } } + public bool isFiring => length(_outputValue) > 0.5f; public bool isSleeping => lengthsq(this.outputValue) == 0; [NonSerialized]