Make it work again
This commit is contained in:
parent
2ff550cba4
commit
c78722abce
@ -88,7 +88,7 @@ namespace NanoBrain {
|
|||||||
|
|
||||||
if (Application.isPlaying == false)
|
if (Application.isPlaying == false)
|
||||||
this.serializedBrain = new SerializedObject(this.prefab);
|
this.serializedBrain = new SerializedObject(this.prefab);
|
||||||
this.selectedOutput = this.currentCluster.outputs[0];
|
this.selectedOutput = this.currentCluster.defaultOutput;
|
||||||
this.currentNucleus = this.selectedOutput;
|
this.currentNucleus = this.selectedOutput;
|
||||||
//this.currentCluster = this.currentNucleus.parent;
|
//this.currentCluster = this.currentNucleus.parent;
|
||||||
Rebuild(inspectorContainer);
|
Rebuild(inspectorContainer);
|
||||||
@ -375,7 +375,7 @@ namespace NanoBrain {
|
|||||||
bool disconnecting = GUILayout.Button("Disconnect", GUILayout.Width(80));
|
bool disconnecting = GUILayout.Button("Disconnect", GUILayout.Width(80));
|
||||||
if (disconnecting) {
|
if (disconnecting) {
|
||||||
synapse.neuron.RemoveReceiver(this.currentNucleus);
|
synapse.neuron.RemoveReceiver(this.currentNucleus);
|
||||||
this.prefab.GarbageCollection();
|
this.currentCluster.Refresh();
|
||||||
anythingChanged = true;
|
anythingChanged = true;
|
||||||
}
|
}
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
@ -517,35 +517,32 @@ namespace NanoBrain {
|
|||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
if (connecting) {
|
if (connecting) {
|
||||||
Nucleus nucleus = nuclei.ElementAt(selectedConnectNucleus);
|
Nucleus nucleus = nuclei.ElementAt(selectedConnectNucleus);
|
||||||
// Nucleus prefabNucleus = this.prefab.cluster.nuclei.ElementAt(selectedConnectNucleus);
|
|
||||||
if (nucleus is Cluster subCluster) {
|
if (nucleus is Cluster subCluster) {
|
||||||
subCluster.AddArrayReceiver(this.currentNucleus);
|
subCluster.AddArrayReceiver(this.currentNucleus);
|
||||||
// Cluster prefabSubCluster = prefabNucleus as Cluster;
|
|
||||||
}
|
}
|
||||||
else if (nucleus is Neuron neuron) {
|
else if (nucleus is Neuron neuron) {
|
||||||
neuron.AddReceiver(this.currentNucleus);
|
neuron.AddReceiver(this.currentNucleus);
|
||||||
// if (prefabNucleus is Neuron prefabNeuron)
|
|
||||||
// prefabNeuron.AddReceiver(this.currentPrefabNucleus);
|
|
||||||
}
|
}
|
||||||
|
this.currentCluster.Refresh();
|
||||||
}
|
}
|
||||||
return connecting;
|
return connecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void DisconnectNucleus(Neuron nucleus) {
|
// protected virtual void DisconnectNucleus(Neuron nucleus) {
|
||||||
if (this.currentNucleus.parent.prefab == null)
|
// if (this.currentNucleus.parent.prefab == null)
|
||||||
return;
|
// return;
|
||||||
Neuron currentNeuron = this.currentNucleus as Neuron;
|
// Neuron currentNeuron = this.currentNucleus as Neuron;
|
||||||
string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
|
// string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
|
||||||
int selectedIndex = -1;
|
// int selectedIndex = -1;
|
||||||
selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
|
// selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
|
||||||
if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
|
// if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
|
||||||
Synapse synapse = currentNeuron.synapses[selectedIndex];
|
// Synapse synapse = currentNeuron.synapses[selectedIndex];
|
||||||
synapse.neuron.RemoveReceiver(this.currentNucleus);
|
// synapse.neuron.RemoveReceiver(this.currentNucleus);
|
||||||
|
|
||||||
// synapse = currentNeuron.synapses[selectedIndex];
|
// // synapse = currentNeuron.synapses[selectedIndex];
|
||||||
// synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
|
// // synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
protected virtual void DeleteNucleus(Nucleus nucleus) {
|
protected virtual void DeleteNucleus(Nucleus nucleus) {
|
||||||
if (nucleus == null)
|
if (nucleus == null)
|
||||||
|
|||||||
@ -72,10 +72,11 @@ namespace NanoBrain {
|
|||||||
public Cluster(ClusterPrefab prefab, ClusterPrefab parent = null) {
|
public Cluster(ClusterPrefab prefab, ClusterPrefab parent = null) {
|
||||||
this.prefab = prefab;
|
this.prefab = prefab;
|
||||||
this.name = prefab.name;
|
this.name = prefab.name;
|
||||||
this.parent.prefab = parent;
|
if (parent != null)
|
||||||
|
this.parent = parent.cluster;
|
||||||
|
|
||||||
if (this.parent.prefab != null)
|
// if (this.parent.prefab != null)
|
||||||
this.parent.prefab.cluster.nuclei.Add(this);
|
// this.parent.prefab.cluster.nuclei.Add(this);
|
||||||
|
|
||||||
ClonePrefab();
|
ClonePrefab();
|
||||||
_ = this.inputs;
|
_ = this.inputs;
|
||||||
@ -773,9 +774,9 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Neuron.Delete(nucleus);
|
Neuron.Delete(nucleus);
|
||||||
int nucleusIx = this.nuclei.IndexOf(nucleus);
|
//int nucleusIx = this.nuclei.IndexOf(nucleus);
|
||||||
this.nuclei.Remove(nucleus);
|
this.nuclei.Remove(nucleus);
|
||||||
this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
|
//this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
|
||||||
RefreshOutputs();
|
RefreshOutputs();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -908,6 +909,10 @@ namespace NanoBrain {
|
|||||||
|
|
||||||
#endregion Update
|
#endregion Update
|
||||||
|
|
||||||
|
public void Refresh() {
|
||||||
|
RefreshOutputs();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ namespace NanoBrain {
|
|||||||
/// <param name="inputValue"></param>
|
/// <param name="inputValue"></param>
|
||||||
public virtual void SetBias(Vector3 inputValue) {
|
public virtual void SetBias(Vector3 inputValue) {
|
||||||
this.bias = inputValue;
|
this.bias = inputValue;
|
||||||
this.parent.UpdateFromNucleus(this);
|
this.parent?.UpdateFromNucleus(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -623,10 +623,9 @@ namespace NanoBrain {
|
|||||||
#endregion Receivers
|
#endregion Receivers
|
||||||
|
|
||||||
public override void ProcessStimulus(Vector3 inputValue) {
|
public override void ProcessStimulus(Vector3 inputValue) {
|
||||||
;
|
|
||||||
this.lastUpdate = Time.time;
|
this.lastUpdate = Time.time;
|
||||||
this.bias = inputValue;
|
this.bias = inputValue;
|
||||||
this.parent.UpdateFromNucleus(this);
|
this.parent?.UpdateFromNucleus(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -101,38 +101,38 @@ namespace NanoBrain {
|
|||||||
// this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
|
// this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MarkNuclei(HashSet<Nucleus> visitedNuclei, Nucleus nucleus) {
|
// public void MarkNuclei(HashSet<Nucleus> visitedNuclei, Nucleus nucleus) {
|
||||||
if (nucleus is null)
|
// if (nucleus is null)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
if (nucleus.parent != null && nucleus.parent.prefab != this)
|
// if (nucleus.parent != null && nucleus.parent.prefab != this)
|
||||||
visitedNuclei.Add(nucleus.parent);
|
// visitedNuclei.Add(nucleus.parent);
|
||||||
else
|
// else
|
||||||
visitedNuclei.Add(nucleus);
|
// visitedNuclei.Add(nucleus);
|
||||||
if (nucleus is Neuron neuron) {
|
// if (nucleus is Neuron neuron) {
|
||||||
if (neuron.synapses != null) {
|
// if (neuron.synapses != null) {
|
||||||
HashSet<Synapse> visitedSynapses = new();
|
// HashSet<Synapse> visitedSynapses = new();
|
||||||
foreach (Synapse synapse in neuron.synapses) {
|
// foreach (Synapse synapse in neuron.synapses) {
|
||||||
if (synapse != null && synapse.neuron != null) {
|
// if (synapse != null && synapse.neuron != null) {
|
||||||
visitedSynapses.Add(synapse);
|
// visitedSynapses.Add(synapse);
|
||||||
if (synapse.neuron is Nucleus synapse_nucleus)
|
// if (synapse.neuron is Nucleus synapse_nucleus)
|
||||||
MarkNuclei(visitedNuclei, synapse_nucleus);
|
// MarkNuclei(visitedNuclei, synapse_nucleus);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
|
// neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
|
||||||
}
|
// }
|
||||||
if (neuron.receivers != null) {
|
// if (neuron.receivers != null) {
|
||||||
HashSet<Nucleus> visitedReceivers = new();
|
// HashSet<Nucleus> visitedReceivers = new();
|
||||||
foreach (Nucleus receiver in neuron.receivers) {
|
// foreach (Nucleus receiver in neuron.receivers) {
|
||||||
if (receiver != null && receiver != null) {
|
// if (receiver != null && receiver != null) {
|
||||||
visitedReceivers.Add(receiver);
|
// visitedReceivers.Add(receiver);
|
||||||
visitedNuclei.Add(receiver);
|
// visitedNuclei.Add(receiver);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
|
// neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// public virtual void UpdateNuclei() {
|
// public virtual void UpdateNuclei() {
|
||||||
// foreach (Nucleus nucleus in this.nuclei)
|
// foreach (Nucleus nucleus in this.nuclei)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user