diff --git a/Editor/ClusterEditor.cs b/Editor/ClusterEditor.cs
index ce75239..868297d 100644
--- a/Editor/ClusterEditor.cs
+++ b/Editor/ClusterEditor.cs
@@ -88,7 +88,7 @@ namespace NanoBrain {
if (Application.isPlaying == false)
this.serializedBrain = new SerializedObject(this.prefab);
- this.selectedOutput = this.currentCluster.outputs[0];
+ this.selectedOutput = this.currentCluster.defaultOutput;
this.currentNucleus = this.selectedOutput;
//this.currentCluster = this.currentNucleus.parent;
Rebuild(inspectorContainer);
@@ -375,7 +375,7 @@ namespace NanoBrain {
bool disconnecting = GUILayout.Button("Disconnect", GUILayout.Width(80));
if (disconnecting) {
synapse.neuron.RemoveReceiver(this.currentNucleus);
- this.prefab.GarbageCollection();
+ this.currentCluster.Refresh();
anythingChanged = true;
}
EditorGUILayout.EndHorizontal();
@@ -517,35 +517,32 @@ namespace NanoBrain {
EditorGUILayout.EndHorizontal();
if (connecting) {
Nucleus nucleus = nuclei.ElementAt(selectedConnectNucleus);
- // Nucleus prefabNucleus = this.prefab.cluster.nuclei.ElementAt(selectedConnectNucleus);
if (nucleus is Cluster subCluster) {
subCluster.AddArrayReceiver(this.currentNucleus);
- // Cluster prefabSubCluster = prefabNucleus as Cluster;
}
else if (nucleus is Neuron neuron) {
neuron.AddReceiver(this.currentNucleus);
- // if (prefabNucleus is Neuron prefabNeuron)
- // prefabNeuron.AddReceiver(this.currentPrefabNucleus);
}
+ this.currentCluster.Refresh();
}
return connecting;
}
- protected virtual void DisconnectNucleus(Neuron nucleus) {
- if (this.currentNucleus.parent.prefab == null)
- return;
- Neuron currentNeuron = this.currentNucleus as Neuron;
- string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
- int selectedIndex = -1;
- selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
- if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
- Synapse synapse = currentNeuron.synapses[selectedIndex];
- synapse.neuron.RemoveReceiver(this.currentNucleus);
+ // protected virtual void DisconnectNucleus(Neuron nucleus) {
+ // if (this.currentNucleus.parent.prefab == null)
+ // return;
+ // Neuron currentNeuron = this.currentNucleus as Neuron;
+ // string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
+ // int selectedIndex = -1;
+ // selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
+ // if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
+ // Synapse synapse = currentNeuron.synapses[selectedIndex];
+ // synapse.neuron.RemoveReceiver(this.currentNucleus);
- // synapse = currentNeuron.synapses[selectedIndex];
- // synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
- }
- }
+ // // synapse = currentNeuron.synapses[selectedIndex];
+ // // synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
+ // }
+ // }
protected virtual void DeleteNucleus(Nucleus nucleus) {
if (nucleus == null)
diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs
index 7dcf31c..b25222c 100644
--- a/Runtime/Scripts/Core/Cluster.cs
+++ b/Runtime/Scripts/Core/Cluster.cs
@@ -72,10 +72,11 @@ namespace NanoBrain {
public Cluster(ClusterPrefab prefab, ClusterPrefab parent = null) {
this.prefab = prefab;
this.name = prefab.name;
- this.parent.prefab = parent;
+ if (parent != null)
+ this.parent = parent.cluster;
- if (this.parent.prefab != null)
- this.parent.prefab.cluster.nuclei.Add(this);
+ // if (this.parent.prefab != null)
+ // this.parent.prefab.cluster.nuclei.Add(this);
ClonePrefab();
_ = this.inputs;
@@ -773,9 +774,9 @@ namespace NanoBrain {
}
Neuron.Delete(nucleus);
- int nucleusIx = this.nuclei.IndexOf(nucleus);
+ //int nucleusIx = this.nuclei.IndexOf(nucleus);
this.nuclei.Remove(nucleus);
- this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
+ //this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
RefreshOutputs();
return true;
@@ -908,6 +909,10 @@ namespace NanoBrain {
#endregion Update
+ public void Refresh() {
+ RefreshOutputs();
+ }
+
}
}
\ No newline at end of file
diff --git a/Runtime/Scripts/Core/Neuron.cs b/Runtime/Scripts/Core/Neuron.cs
index 1dd884f..1c2144f 100644
--- a/Runtime/Scripts/Core/Neuron.cs
+++ b/Runtime/Scripts/Core/Neuron.cs
@@ -105,7 +105,7 @@ namespace NanoBrain {
///
public virtual void SetBias(Vector3 inputValue) {
this.bias = inputValue;
- this.parent.UpdateFromNucleus(this);
+ this.parent?.UpdateFromNucleus(this);
}
///
@@ -623,10 +623,9 @@ namespace NanoBrain {
#endregion Receivers
public override void ProcessStimulus(Vector3 inputValue) {
- ;
this.lastUpdate = Time.time;
this.bias = inputValue;
- this.parent.UpdateFromNucleus(this);
+ this.parent?.UpdateFromNucleus(this);
}
}
diff --git a/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs b/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs
index 574552d..c00f234 100644
--- a/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs
+++ b/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs
@@ -101,38 +101,38 @@ namespace NanoBrain {
// this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
}
- public void MarkNuclei(HashSet visitedNuclei, Nucleus nucleus) {
- if (nucleus is null)
- return;
+ // public void MarkNuclei(HashSet visitedNuclei, Nucleus nucleus) {
+ // if (nucleus is null)
+ // return;
- if (nucleus.parent != null && nucleus.parent.prefab != this)
- visitedNuclei.Add(nucleus.parent);
- else
- visitedNuclei.Add(nucleus);
- if (nucleus is Neuron neuron) {
- if (neuron.synapses != null) {
- HashSet visitedSynapses = new();
- foreach (Synapse synapse in neuron.synapses) {
- if (synapse != null && synapse.neuron != null) {
- visitedSynapses.Add(synapse);
- if (synapse.neuron is Nucleus synapse_nucleus)
- MarkNuclei(visitedNuclei, synapse_nucleus);
- }
- }
- neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
- }
- if (neuron.receivers != null) {
- HashSet visitedReceivers = new();
- foreach (Nucleus receiver in neuron.receivers) {
- if (receiver != null && receiver != null) {
- visitedReceivers.Add(receiver);
- visitedNuclei.Add(receiver);
- }
- }
- neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
- }
- }
- }
+ // if (nucleus.parent != null && nucleus.parent.prefab != this)
+ // visitedNuclei.Add(nucleus.parent);
+ // else
+ // visitedNuclei.Add(nucleus);
+ // if (nucleus is Neuron neuron) {
+ // if (neuron.synapses != null) {
+ // HashSet visitedSynapses = new();
+ // foreach (Synapse synapse in neuron.synapses) {
+ // if (synapse != null && synapse.neuron != null) {
+ // visitedSynapses.Add(synapse);
+ // if (synapse.neuron is Nucleus synapse_nucleus)
+ // MarkNuclei(visitedNuclei, synapse_nucleus);
+ // }
+ // }
+ // neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
+ // }
+ // if (neuron.receivers != null) {
+ // HashSet visitedReceivers = new();
+ // foreach (Nucleus receiver in neuron.receivers) {
+ // if (receiver != null && receiver != null) {
+ // visitedReceivers.Add(receiver);
+ // visitedNuclei.Add(receiver);
+ // }
+ // }
+ // neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
+ // }
+ // }
+ // }
// public virtual void UpdateNuclei() {
// foreach (Nucleus nucleus in this.nuclei)