35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class NanoBrainComponent : MonoBehaviour {
|
|
public ClusterPrefab defaultBrain;
|
|
private Cluster brainInstance;
|
|
|
|
//public INucleus root => brainInstance.output;
|
|
public Cluster brain {
|
|
get {
|
|
if (brainInstance == null && defaultBrain != null) {
|
|
brainInstance = new Cluster(defaultBrain); //Instantiate(defaultBrain);
|
|
brainInstance.name = defaultBrain.name + " (Instance)";
|
|
|
|
SwarmControl sc = FindFirstObjectByType<SwarmControl>();
|
|
if (sc != null) {
|
|
UpdateWeight(brainInstance, "Avoidance", sc.avoidanceForce);
|
|
UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
|
|
UpdateWeight(brainInstance, "Separation", sc.separationForce);
|
|
UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
|
|
}
|
|
}
|
|
return brainInstance;
|
|
}
|
|
}
|
|
|
|
public static void UpdateWeight(Cluster brain, string name, float weight) {
|
|
INucleus root = brain.output;
|
|
foreach (Synapse synapse in root.synapses) {
|
|
if (synapse.nucleus.name == name) {
|
|
synapse.weight = weight;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |