Improved UI

This commit is contained in:
Pascal Serrarens 2026-03-02 11:07:40 +01:00
parent 97ea988cca
commit 83e8bd70f1

View File

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