Pascal Serrarens 4363079d43 Squashed 'NanoBrain/' changes from 7ef8e42..ec3b1d4
ec3b1d4 Completed cluster documentation
348fee3 Update .gitea/workflows/copy_documentation.yml
911e52f Update .gitea/workflows/copy_documentation.yml
d472790 Update .gitea/workflows/copy_documentation.yml
b87f40f Trying to get the workflow running...10
2b0db4f Trying to get the workflow running...9
927fd6d Trying to get the workflow running...8
176f399 Trying to get the workflow running...7
3c841c7 Trying to get the workflow running...6
5c798c2 Trying to get the workflow running...5
30b25a1 Trying to get the workflow running...4
5edf019 Trying to get the workflow running...3
587cf82 Trying to get the workflow running...2
a1d3aa7 Trying to get the workflow running...1
97ec277 Removed LinearAlgebra, first setup webserver copy workflow
5827396 Fixed documentation links
ce19335 Added Documentation
da370bb Improvements
32b5885 Multi smell works
33ea14b Single smell works
a651ec6 Add neuron property drawer
baa7def Pheromones WIP
551b4d9 Improve ant walking speed
7187f61 Ant is walking again
c78722a Make it work again
2ff550c Removed clusterPrefab property
2ef67fe Cleanup and fix connect neuron
a9a0072 Merge commit 'dd326823a8256f3ddb808e071d98c4aede72e410'
22ee17c Insect rig improvements
b6a3bc1 Added insect body parts
517e738 Merge commit '4ae9a15fc61f386b96ce0f7b440780f562d7dc68'
033ddf4 Merge commit '05fd588f9bc41d84113d410a2ca992f1a2ee66e0'
ef700c0 Merge commit '3f8716794ad9d685cfb9ed9dd230eb31cd8df10f'
7d5e157 Added NanoBrain namespace
f138201 Merge commit '611055cdcd58b01f2f19991ad35eb8fe8e573ebb'
1c4d361 Merge commit '9fcbaa5bf84f91680d24b56dbf114bcb97de4aee'
0f83945 Added NanoBrain subtree
6f398ad Merge commit '8e87e4ea77308b51c3691bdad96e7f9707952821' as 'NanoBrain'
587f104 Move out non-subtree NanoBrain
fc581a0 cleanup & documentation
837c5ce WIP Physics based walking
63486d1 The ant does it ant things!
ce8e476 Added sample assets...
88d5eb5 Placing home pheromones
481829c Ensure model follows target in editor
018c99d Any walks
e709ea4 Steps to get it working
c1dcc83 Initial Ant setup
af2fa77 Merge commit '04ca8dda0793476a59fc06f1958453730a99c105' as 'NanoBrain'
04ca8dd Squashed 'NanoBrain/' content from commit b3423b9
d9ba98d WIP: Initial scripts
2219e98 Initial commit

git-subtree-dir: NanoBrain
git-subtree-split: ec3b1d46ab2b9f332a8ae63589b09c3fb6fb1b1a
2026-05-07 15:25:20 +02:00

154 lines
6.7 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace NanoBrain {
/// <summary>
/// The Unity ScriptableObject to implement re-usable Cluster Prefabs
/// </summary>
[CreateAssetMenu(menuName = "Passer/Cluster")]
public class ClusterPrefab : ScriptableObject {
public Cluster cluster;
/*
/// The nuclei in this cluster
[SerializeReference]
// This list should not include any clusters...
public List<Nucleus> nuclei = new();
/// <summary>
/// The output of this cluster
/// </summary>
/// <deprecated>This only returens the first(default) nucleus. Use outputs[0] instead</deprecated>
public virtual Nucleus output => this.nuclei[0] as Nucleus;
/// <summary>
/// The nuclei in this cluster which are meant for receiving signals from outside the cluster
/// </summary>
/// <remark>This is currently the nuclei which do not have any incoming synapse</remark>
public List<Nucleus> _inputs = null;
public virtual List<Nucleus> inputs {
get {
if (this._inputs == null) {
this._inputs = new();
foreach (Nucleus receptor in this.nuclei) {
if (receptor is Nucleus nucleus) {
// inputs have no incoming synapses yet.
if (nucleus.synapses.Count == 0)
this._inputs.Add(nucleus);
}
}
}
return this._inputs;
}
}
/// <summary>
/// The nuclei in this cluster which are meant for sending signals onward
/// </summary>
private List<Nucleus> _outputs = null;
public List<Nucleus> outputs {
get {
if (this._outputs == null)
RefreshOutputs();
return this._outputs;
}
}
/// <summary>
/// Redetermine the outpus in the cluster
/// </summary>
public void RefreshOutputs() {
this._outputs = new();
foreach (Nucleus nucleus in this.nuclei) {
if (nucleus is Neuron neuron && neuron.receivers.Count == 0)
this._outputs.Add(nucleus);
}
}
*/
/// <summary>
/// Retrieve a nucleus in this cluster
/// </summary>
/// <param name="nucleusName">The name of the nucleus</param>
/// <returns>The Nucleus with the given name or null if no such Nucleus could be found</returns>
public Nucleus GetNucleus(string nucleusName) {
return cluster.GetNucleus(nucleusName);
// foreach (Nucleus nucleus in this.nuclei) {
// if (nucleus.name == nucleusName)
// return nucleus;
// }
// return null;
}
// Call this function to ensure that there is at least one nucleus
// This is an invariant and should be ensured before the nucleus is used
// because output requires it.
public void EnsureInitialization() {
this.cluster.prefab = this;
this.cluster.name = this.name;
this.cluster.nuclei ??= new List<Nucleus>();
if (this.cluster.nuclei.Count <= 0)
new Neuron(this.cluster, "Output"); // Every cluster should have at least 1 neuron
this.cluster.instanceCount = 1;
// nuclei ??= new List<Nucleus>();
// if (nuclei.Count == 0)
// new Neuron(this, "Output"); // Every cluster should have at least 1 neuron
}
public void GarbageCollection() {
// HashSet<Nucleus> visitedNuclei = new();
// foreach (Nucleus output in this.outputs)
// MarkNuclei(visitedNuclei, output);
// //Debug.Log($"Garbage collection found {visitedNuclei.Count} Nuclei");
// this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
}
// public void MarkNuclei(HashSet<Nucleus> 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<Synapse> 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<Nucleus> 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)
// nucleus.UpdateNuclei();
// }
// public int GetNucleusIndex(Nucleus receiver) {
// int ix = 0;
// foreach (Nucleus nucleus in this.nuclei) {
// if (receiver == nucleus)
// return ix;
// ix++;
// }
// return -1;
// }
}
}