diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 0b28264..18e6b94 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -618,6 +618,7 @@ public class ClusterInspector : Editor { } } + private VisualElement inspectorIMGUIContainer; private bool showSynapses = true; private bool showActivation = true; protected bool breakOnWake = false; @@ -632,9 +633,9 @@ public class ClusterInspector : Editor { // create a SerializedObject wrapper so Unity inspector controls work (and Undo) SerializedObject so = new(prefabAsset); - IMGUIContainer container = new(() => InspectorHandler(so)); + this.inspectorIMGUIContainer = new IMGUIContainer(() => InspectorHandler(so)); - inspectorContainer.Add(container); + inspectorContainer.Add(inspectorIMGUIContainer); } void InspectorHandler(SerializedObject serializedObject) { @@ -728,18 +729,15 @@ public class ClusterInspector : Editor { if (this.currentNucleus is not Receptor && this.currentNucleus is not ClusterReceptor) { showSynapses = EditorGUILayout.BeginFoldoutHeaderGroup(showSynapses, "Synapses"); if (showSynapses) { - - anythingChanged = ConnectNucleus(this.prefab, this.currentNucleus); - anythingChanged = AddSynapse(this.prefab, this.currentNucleus); - EditorGUILayout.Space(); - if (this.currentNucleus is Neuron neuron2) { Neuron.CombinatorType newCombinator = (Neuron.CombinatorType)EditorGUILayout.EnumPopup("Combinator", neuron2.combinator); anythingChanged |= newCombinator != neuron2.combinator; neuron2.combinator = newCombinator; } - Vector3 newBias = EditorGUILayout.Vector3Field("Bias", this.currentNucleus.bias); + EditorGUIUtility.wideMode = true; + EditorGUIUtility.labelWidth = 100; + Vector3 newBias = EditorGUILayout.Vector3Field("Bias", this.currentNucleus.bias); //, GUILayout.Width(200)); anythingChanged |= newBias != this.currentNucleus.bias; this.currentNucleus.bias = newBias; @@ -776,7 +774,7 @@ public class ClusterInspector : Editor { if (synapse.nucleus.parent != null && synapse.nucleus.parent != this.currentNucleus) { GUIStyle labelStyle = new(GUI.skin.label); float labelWidth = labelStyle.CalcSize(new GUIContent($"{synapse.nucleus.clusterPrefab.name}.")).x; - EditorGUILayout.LabelField($"{synapse.nucleus.clusterPrefab.name}", GUILayout.Width(labelWidth)); + GUILayout.Label($"{synapse.nucleus.clusterPrefab.name}", GUILayout.Width(labelWidth)); string[] options = synapse.nucleus.parent.clusterNuclei.Select(n => n.name).ToArray(); int selectedIndex = System.Array.IndexOf(options, synapse.nucleus.name); int newIndex = EditorGUILayout.Popup(selectedIndex, options); @@ -784,13 +782,16 @@ public class ClusterInspector : Editor { ChangeSynapse(synapse, newNeuron); } else - EditorGUILayout.LabelField(synapse.nucleus.name); - if (GUILayout.Button("Disconnect") && synapse.nucleus is Neuron synapseNeuron) { + GUILayout.Label(synapse.nucleus.name); + + bool disconnecting = GUILayout.Button("Disconnect", GUILayout.Width(80)); + if (disconnecting && synapse.nucleus is Neuron synapseNeuron) { synapseNeuron.RemoveReceiver(this.currentNucleus); this.prefab.GarbageCollection(); anythingChanged = true; } EditorGUILayout.EndHorizontal(); + } EditorGUI.indentLevel++; @@ -802,12 +803,17 @@ public class ClusterInspector : Editor { if (s.nucleus is IReceptor r && r.nucleiArray == receptorArray) s.weight = newWeight; } - } else - synapse.weight= newWeight; + } + else + synapse.weight = newWeight; } EditorGUI.indentLevel--; } } + + EditorGUILayout.Space(); + anythingChanged = ConnectNucleus(this.prefab, this.currentNucleus); + anythingChanged = AddSynapse(this.prefab, this.currentNucleus); } EditorGUILayout.EndFoldoutHeaderGroup(); } @@ -1012,19 +1018,33 @@ public class ClusterInspector : Editor { string[] names = nucleiNames.ToArray(); int selectedIndex = -1; - selectedIndex = EditorGUILayout.Popup("Connect", selectedIndex, names); - if (selectedIndex < 0) - return false; + EditorGUILayout.BeginHorizontal(); + selectedIndex = EditorGUILayout.Popup(selectedIndex, names); + bool connecting = GUILayout.Button("Connect", GUILayout.Width(80)); + EditorGUILayout.EndHorizontal(); + if (connecting) { + Nucleus nucleus = nuclei.ElementAt(selectedIndex); + if (nucleus is Receptor receptor) + receptor.AddArrayReceiver(this.currentNucleus); + else if (nucleus is Neuron neuron) + neuron.AddReceiver(this.currentNucleus); + else if (nucleus is Cluster subCluster) + subCluster.defaultOutput.AddReceiver(this.currentNucleus); - Nucleus nucleus = nuclei.ElementAt(selectedIndex); - if (nucleus is Receptor receptor) - receptor.AddArrayReceiver(this.currentNucleus); - else if (nucleus is Neuron neuron) - neuron.AddReceiver(this.currentNucleus); - else if (nucleus is Cluster subCluster) - subCluster.defaultOutput.AddReceiver(this.currentNucleus); + } + return connecting; + // if (selectedIndex < 0) + // return false; - return true; + // Nucleus nucleus = nuclei.ElementAt(selectedIndex); + // if (nucleus is Receptor receptor) + // receptor.AddArrayReceiver(this.currentNucleus); + // else if (nucleus is Neuron neuron) + // neuron.AddReceiver(this.currentNucleus); + // else if (nucleus is Cluster subCluster) + // subCluster.defaultOutput.AddReceiver(this.currentNucleus); + + // return true; } protected virtual void DeleteNucleus(Nucleus nucleus) { @@ -1057,12 +1077,20 @@ public class ClusterInspector : Editor { if (cluster == null) return false; - Nucleus.Type selectedType = (Nucleus.Type)EditorGUILayout.EnumPopup("Add", Nucleus.Type.None); - if (selectedType == Nucleus.Type.None) - return false; + EditorGUILayout.BeginHorizontal(); + Nucleus.Type selectedType = (Nucleus.Type)EditorGUILayout.EnumPopup(Nucleus.Type.None); + bool connecting = GUILayout.Button("Add", GUILayout.Width(80)); + EditorGUILayout.EndHorizontal(); - AddInput(selectedType, this.currentNucleus); - return true; + if (connecting) { + AddInput(selectedType, this.currentNucleus); + } + return connecting; + // if (selectedType == Nucleus.Type.None) + // return false; + + // AddInput(selectedType, this.currentNucleus); + // return true; } protected virtual void ChangeSynapse(Synapse synapse, Neuron newNucleus) {