Containment works again
This commit is contained in:
parent
76d8714778
commit
f72a37b248
11
Cluster.cs
11
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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
23
Receptor.cs
23
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() {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9051408e82b511584998506096af4bf0
|
||||
Loading…
x
Reference in New Issue
Block a user