From e8471683d6923598998c8e21725c6a7d248752b6 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 9 Feb 2026 09:53:33 +0100 Subject: [PATCH] Inspector cleanup --- Editor/ClusterInspector.cs | 87 ++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 1fa78ee..2290d71 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -498,7 +498,8 @@ public class ClusterInspector : Editor { } } - private int selectedInputType = 0; + //private int selectedInputType = 0; + private bool showSynapses = true; void DrawInspector(VisualElement inspectorContainer) { if (inspectorContainer == null) return; @@ -517,19 +518,15 @@ public class ClusterInspector : Editor { if (this.currentNucleus == null) return; - GUIStyle headerStyle = new GUIStyle(EditorStyles.boldLabel) { + GUIStyle headerStyle = new(EditorStyles.boldLabel) { alignment = TextAnchor.MiddleLeft, margin = new RectOffset(10, 0, 4, 4) }; - //GUI.backgroundColor = EditorGUIUtility.isProSkin ? new Color(0.15f, 0.15f, 0.15f) : new Color(0.85f, 0.85f, 0.85f); - //GUILayout.BeginVertical("box"); - GUIStyle boldTextFieldStyle = new GUIStyle(EditorStyles.textField) { + GUIStyle boldTextFieldStyle = new(EditorStyles.textField) { fontStyle = FontStyle.Bold }; GUILayout.Label(this.currentNucleus.GetType().ToString(), headerStyle); - //GUILayout.EndVertical(); - //GUI.backgroundColor = Color.white; // Reset background color this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name, boldTextFieldStyle); if (this.currentNucleus is Neuron neuroid) { if (this.currentNucleus is MemoryCell memory) { @@ -561,49 +558,36 @@ public class ClusterInspector : Editor { else EditorGUILayout.LabelField(" "); - if (this.currentNucleus.synapses.Count > 0) { - EditorGUILayout.LabelField("Synapses"); - Synapse[] synapses = this.currentNucleus.synapses.ToArray(); - foreach (Synapse synapse in synapses) { - if (synapse.nucleus != null) { - EditorGUILayout.Space(); + showSynapses = EditorGUILayout.BeginFoldoutHeaderGroup(showSynapses, "Synapses"); + if (showSynapses) { + ConnectNucleus(this.cluster, this.currentNucleus); + AddSynapse(this.cluster, this.currentNucleus); - //EditorGUI.BeginDisabledGroup(synapse.nucleus.isSleeping); - if (Application.isPlaying) - EditorGUILayout.FloatField(synapse.nucleus.name, length(synapse.nucleus.outputValue) * synapse.weight); - else { - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField(synapse.nucleus.name); - if (GUILayout.Button("Disconnect")) - synapse.nucleus.RemoveReceiver(this.currentNucleus); - EditorGUILayout.EndHorizontal(); + if (this.currentNucleus.synapses.Count > 0) { + Synapse[] synapses = this.currentNucleus.synapses.ToArray(); + foreach (Synapse synapse in synapses) { + if (synapse.nucleus != null) { + EditorGUILayout.Space(); + + //EditorGUI.BeginDisabledGroup(synapse.nucleus.isSleeping); + if (Application.isPlaying) + EditorGUILayout.FloatField(synapse.nucleus.name, length(synapse.nucleus.outputValue) * synapse.weight); + else { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(synapse.nucleus.name); + if (GUILayout.Button("Disconnect")) + synapse.nucleus.RemoveReceiver(this.currentNucleus); + EditorGUILayout.EndHorizontal(); + } + + EditorGUI.indentLevel++; + synapse.weight = EditorGUILayout.FloatField("Weight", synapse.weight); + EditorGUI.indentLevel--; } - - EditorGUI.indentLevel++; - synapse.weight = EditorGUILayout.FloatField("Weight", synapse.weight); - EditorGUI.indentLevel--; - //EditorGUI.EndDisabledGroup(); } } } - - EditorGUILayout.Space(); - - ConnectNucleus(this.cluster, this.currentNucleus); - - EditorGUILayout.BeginHorizontal(); - string[] options = { "Neuron", "MemoryCell", "Selector", "Cluster" }; - selectedInputType = EditorGUILayout.Popup(selectedInputType, options); - if (GUILayout.Button("Add Input")) - AddInput(selectedInputType, this.currentNucleus); - EditorGUILayout.EndHorizontal(); - - // if (GUILayout.Button("Add Input Neuron")) - // AddInputNeuron(this.currentNucleus); - // if (GUILayout.Button("Add Input MemoryCell")) - // AddInputMemoryCell(this.currentNucleus); - // if (GUILayout.Button("Add Input Cluster")) - // AddCluster(this.currentNucleus); + EditorGUILayout.EndFoldoutHeaderGroup(); EditorGUILayout.Space(); @@ -722,13 +706,24 @@ public class ClusterInspector : Editor { string[] names = nucleiNames.ToArray(); int selectedIndex = -1; - selectedIndex = EditorGUILayout.Popup("Connect to", selectedIndex, names); + selectedIndex = EditorGUILayout.Popup("Connect", selectedIndex, names); if (selectedIndex >= 0) { Nucleus receptor = nuclei.ElementAt(selectedIndex); receptor.AddReceiver(this.currentNucleus); } } + protected virtual void AddSynapse(ClusterPrefab cluster, Nucleus nucleus) { + if (cluster == null) + return; + + string[] options = { "Neuron", "MemoryCell", "Selector", "Cluster" }; + int selectedInputType = -1; + selectedInputType = EditorGUILayout.Popup("Add", selectedInputType, options); + if (selectedInputType >= 0) + AddInput(selectedInputType, this.currentNucleus); + } + protected virtual void DisconnectNucleus(Neuron nucleus) { if (this.currentNucleus.cluster == null) return;