From 9cbf0aaa2c7325059aaaf44f41c7039b154265da Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 13 Feb 2026 17:25:48 +0100 Subject: [PATCH] Fix labels --- Editor/ClusterInspector.cs | 108 +++++++++++++------------------------ NucleusArray.cs | 4 +- 2 files changed, 41 insertions(+), 71 deletions(-) diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 04fe3b5..e4813da 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -326,6 +326,19 @@ public class ClusterInspector : Editor { DrawNucleus(nucleus, pos, maxValue, size); row++; } + GUIStyle style = new(EditorStyles.label) { + alignment = TextAnchor.UpperCenter, + normal = { textColor = Color.white }, + fontStyle = FontStyle.Bold, + }; + Vector3 labelPos = new(150, yMax + size + 5, 0); + int colonPos = receptor1.name.IndexOf(":"); + if (colonPos > 0) { + string baseName = receptor1.name[..colonPos]; + Handles.Label(labelPos, baseName, style); + } + else + Handles.Label(labelPos, receptor1.name, style); } } else { @@ -415,9 +428,6 @@ public class ClusterInspector : Editor { Handles.DrawLine(parentPos, pos); if (synapse.nucleus != null) { Color color = Color.black; - // if (synapse.nucleus.isSleeping) - // color = Color.darkRed; - // else if (Application.isPlaying) { float brightness = length(synapse.nucleus.outputValue) * synapse.weight / maxValue; color = new Color(brightness, brightness, brightness, 1f); @@ -430,17 +440,12 @@ public class ClusterInspector : Editor { private void DrawNucleus(Nucleus nucleus, Vector3 position, float maxValue, float size) { Color color; - // if (nucleus.isSleeping) - // color = Color.darkRed; - // else - { - if (Application.isPlaying) { - float brightness = length(nucleus.outputValue) / maxValue; - color = new Color(brightness, brightness, brightness, 1f); - } - else - color = Color.black; + if (Application.isPlaying) { + float brightness = length(nucleus.outputValue) / maxValue; + color = new Color(brightness, brightness, brightness, 1f); } + else + color = Color.black; DrawNucleus(nucleus, position, maxValue, size, color); } @@ -468,37 +473,35 @@ public class ClusterInspector : Editor { receptor1.array = new NucleusArray(nucleus); if ((!expandArray || receptor1.array.nuclei.First() != this.currentNucleus) && receptor1.array.nuclei.Count() > 1) { - Handles.Label(labelPosition, receptor1.array.nuclei.Count().ToString(), style); + if (color.grayscale > 0.5f) + style.normal.textColor = Color.black; + else + style.normal.textColor = Color.white; + Handles.Label(labelPosition, receptor1.array.nuclei.Length.ToString(), style); + style.normal.textColor = Color.white; } } - if (nucleus is ReceptorArray receptor) { - Handles.Label(labelPosition, receptor.instances.Count().ToString(), style); - } - // else if (nucleus is ReceptorInstance receptorI) { - // if (expandArray) { - // int arrayIx = 0; - // foreach (ReceptorInstance n in receptorI.receptorArray.receptors) { - // if (n == receptorI) - // break; - // arrayIx++; - // } - // Handles.Label(labelPosition, $"[{arrayIx}]", style); - // } + // if (nucleus is ReceptorArray receptor) { + // if (color.grayscale > 0.5f) + // style.normal.textColor = Color.black; + // else + // style.normal.textColor = Color.white; + // Handles.Label(labelPosition, receptor.instances.Count().ToString(), style); // } if (expandArray && nucleus is Receptor receptor2 && receptor2.array.nuclei.First() == this.currentNucleus) { - int arrayIx = 0; - foreach (Nucleus n in receptor2.array.nuclei) { - if (n == nucleus) - break; - arrayIx++; + style.alignment = TextAnchor.LowerCenter; + Vector3 labelPos = position + Vector3.down * (size + 5); // below disc along up axis + int colonPos = nucleus.name.IndexOf(":"); + if (colonPos > 0) { + string extName = nucleus.name[(colonPos + 2)..]; + Handles.Label(labelPos, extName, style); } - Handles.Label(labelPosition, $"[{arrayIx}]", style); } else { style.alignment = TextAnchor.UpperCenter; - Vector3 labelPos = position - Vector3.down * (size + 10f); // below disc along up axis + Vector3 labelPos = position - Vector3.down * (size + 5); // below disc along up axis int colonPos = nucleus.name.IndexOf(":"); - if (colonPos > 0) { + if (colonPos > 0 && colonPos < nucleus.name.Length - 2) { string baseName = nucleus.name[..colonPos]; Handles.Label(labelPos, baseName, style); } @@ -602,7 +605,6 @@ public class ClusterInspector : Editor { this.currentNucleus.name = newName; this.prefab.RefreshOutputs(); outputsField.choices = this.prefab.outputs.Select(output => output.name).ToList(); - //outputsField.value = newName; } if (Application.isPlaying) { @@ -729,22 +731,6 @@ public class ClusterInspector : Editor { if (receptor2.array == null || receptor2.array.nuclei == null || receptor2.array.nuclei.Count() == 0) receptor2.array = new NucleusArray(neuron); } - - // if (this.currentNucleus is Receptor receptor1) { - // EditorGUILayout.BeginHorizontal(); - // EditorGUILayout.IntField("Array size", receptor1.array.nuclei.Count()); - // if (GUILayout.Button("Add")) { - // Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name); - // receptor1.array.AddNucleus(this.prefab); - // anythingChanged = true; - // } - // if (GUILayout.Button("Del")) { - // Undo.RecordObject(prefabAsset, "Array delete " + prefabAsset.name); - // receptor1.array.RemoveNucleus(); - // anythingChanged = true; - // } - // EditorGUILayout.EndHorizontal(); - // } } EditorGUILayout.Space(); @@ -831,25 +817,7 @@ public class ClusterInspector : Editor { } } - // protected virtual void AddInput(int selectedInputType, Nucleus nucleus) { - // switch (selectedInputType) { - // case 0: // Neuron - // AddNeuronInput(nucleus); - // break; - // case 1: // MemoryCell - // AddMemoryCellInput(nucleus); - // break; - // case 2: // Selector - // AddSelectorInput(nucleus); - // break; - // case 3: // Cluster - // AddClusterInput(nucleus); - // break; - // } - // } - protected virtual void AddNeuronInput(Nucleus nucleus) { - //Neuron newNeuroid = new(this.cluster, "New neuron"); Neuron newNeuroid = new(this.prefab, "New neuron"); newNeuroid.AddReceiver(nucleus); this.currentNucleus = newNeuroid; diff --git a/NucleusArray.cs b/NucleusArray.cs index 48595b5..118f174 100644 --- a/NucleusArray.cs +++ b/NucleusArray.cs @@ -36,8 +36,10 @@ public class NucleusArray { for (int i = 0; i < this._nuclei.Length; i++) newArray[i] = this._nuclei[i]; - if (this._nuclei[0] is Nucleus nucleus) + if (this._nuclei[0] is Nucleus nucleus) { newArray[newLength - 1] = nucleus.Clone(prefab); + newArray[newLength - 1].name += $"{newLength - 1}"; + } this._nuclei = newArray; }