From f72a37b2482c79df39902f7d7a2c4f7ad09a5cae Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 18 Feb 2026 17:26:45 +0100 Subject: [PATCH] Containment works again --- Cluster.cs | 11 +++++------ ClusterReceptor.cs | 4 ++++ Editor/ClusterInspector.cs | 6 ++++-- IReceptor.cs | 6 ++++++ Receptor.cs | 23 ++++++++++++++++------ Scripts/Experimental/SelectorBrain.cs | 23 ---------------------- Scripts/Experimental/SelectorBrain.cs.meta | 2 -- 7 files changed, 36 insertions(+), 39 deletions(-) delete mode 100644 Scripts/Experimental/SelectorBrain.cs delete mode 100644 Scripts/Experimental/SelectorBrain.cs.meta diff --git a/Cluster.cs b/Cluster.cs index 315d2f8..0c0d507 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -39,10 +39,9 @@ public class Cluster : Nucleus { Nucleus[] prefabNuclei = this.prefab.nuclei.ToArray(); // first clone the nuclei without their connections foreach (Nucleus nucleus in this.prefab.nuclei) { - Debug.Log($"prefab clone {nucleus.name}"); + // Debug.Log($"prefab clone {nucleus.name}"); nucleus.ShallowCloneTo(this); } - Debug.Log(" complete"); Nucleus[] clonedNuclei = this.clusterNuclei.ToArray(); // Now clone the connections @@ -57,7 +56,7 @@ public class Cluster : Nucleus { // Copy the receivers, which will also create the synapses // Clusters do not have receivers... - foreach (Nucleus receiver in prefabNeuron.receivers) { + foreach (Nucleus receiver in prefabNeuron.receivers.ToArray()) { int ix = GetNucleusIndex(prefabNuclei, receiver); if (ix < 0) continue; @@ -420,10 +419,10 @@ public class Cluster : Nucleus { return null; } - public Receptor GetReceptor(string receptorName) { + public IReceptor GetReceptor(string receptorName) { foreach (Nucleus nucleus in this.clusterNuclei) { - if (nucleus is Receptor receptor) - if (receptor.name == receptorName) + if (nucleus is IReceptor receptor) + if (receptor.GetName() == receptorName) return receptor; } return null; diff --git a/ClusterReceptor.cs b/ClusterReceptor.cs index 8b409bc..f5bb1ad 100644 --- a/ClusterReceptor.cs +++ b/ClusterReceptor.cs @@ -15,6 +15,10 @@ public class ClusterReceptor : Cluster, IReceptor { this.array = new NucleusArray(this); } + public string GetName() { + return this.name; + } + public override Nucleus ShallowCloneTo(Cluster parent) { ClusterReceptor clone = new(this.prefab, parent, this.name) { clusterPrefab = this.clusterPrefab, diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index a099a5d..5ffb38f 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -452,10 +452,12 @@ public class ClusterInspector : Editor { Handles.DrawLine(parentPos, pos); Color color = Color.black; if (Application.isPlaying) { - float brightness = length(synapse.nucleus.outputValue) * synapse.weight / maxValue; + if (maxValue == 0 || !float.IsFinite(maxValue)) + maxValue = 1; + float brightness = length(synapse.nucleus.outputValue * synapse.weight) / maxValue; color = new Color(brightness, brightness, brightness, 1f); } - if (synapse.nucleus.parent != null && synapse.nucleus.parent != this.currentNucleus) { + if (synapse.nucleus.parent != null && synapse.nucleus.parent != this.currentNucleus.parent) { // the synapse nucleus is part of a subcluster DrawNucleus(synapse.nucleus.parent, pos, maxValue, size, color); } diff --git a/IReceptor.cs b/IReceptor.cs index 94d9ae2..18c3c35 100644 --- a/IReceptor.cs +++ b/IReceptor.cs @@ -1,5 +1,11 @@ +using UnityEngine; + public interface IReceptor { + public string GetName(); + public NucleusArray array { get; set; } + + public void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName =null); } \ No newline at end of file diff --git a/Receptor.cs b/Receptor.cs index 7ff4011..22d42aa 100644 --- a/Receptor.cs +++ b/Receptor.cs @@ -4,19 +4,29 @@ using static Unity.Mathematics.math; [System.Serializable] public class Receptor : Neuron, IReceptor { - public Receptor(Cluster parent, string name) : base(parent, name) { } - public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) { } + public Receptor(Cluster parent, string name) : base(parent, name) { + this.array ??= new NucleusArray(this); + } + public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) { + this.array ??= new NucleusArray(this); + } + + public string GetName() { + return this.name; + } public override Nucleus ShallowCloneTo(Cluster parent) { - Receptor clone = new(parent, name); + Receptor clone = new(parent, name) { + //array = this.array + }; CloneFields(clone); - clone.array = this.array; return clone; } public override Nucleus Clone(ClusterPrefab prefab) { - Receptor clone = new(prefab, name); + Receptor clone = new(prefab, name) { + //array = this.array + }; CloneFields(clone); - clone.array = this.array; // Adding receivers will also add synapses to the receivers foreach (Nucleus receiver in this.receivers) clone.AddReceiver(receiver); @@ -32,6 +42,7 @@ public class Receptor : Neuron, IReceptor { public override void UpdateStateIsolated() { this.outputValue = this.bias; + //Debug.Log($"Receptor {this.name} outputvalue = {this.outputValue}"); } public override void UpdateNuclei() { diff --git a/Scripts/Experimental/SelectorBrain.cs b/Scripts/Experimental/SelectorBrain.cs deleted file mode 100644 index 08b21f6..0000000 --- a/Scripts/Experimental/SelectorBrain.cs +++ /dev/null @@ -1,23 +0,0 @@ -using UnityEngine; - -public class SelectorBrain : NanoBrain { - public Vector3 input1; - public Vector3 input2; - public Vector3 output; - - public Receptor receptor; - //public Nucleus receptor2; - - protected void Awake() { - receptor = this.brain.GetReceptor("Selector"); - //receptor2 = this.brain.GetNucleus("Selector"); - } - - protected void Update() { - receptor.ProcessStimulus(input1, 0); - receptor.ProcessStimulus(input2, 1); - output = this.brain.outputValue; - - this.brain.UpdateNuclei(); - } -} \ No newline at end of file diff --git a/Scripts/Experimental/SelectorBrain.cs.meta b/Scripts/Experimental/SelectorBrain.cs.meta deleted file mode 100644 index ef88825..0000000 --- a/Scripts/Experimental/SelectorBrain.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 9051408e82b511584998506096af4bf0 \ No newline at end of file