using UnityEngine; public class NanoBrainComponent : MonoBehaviour { public ClusterPrefab defaultBrain; private ClusterPrefab brainInstance; public INucleus root => brainInstance.output; public ClusterPrefab brain { get { if (brainInstance == null && defaultBrain != null) { brainInstance = Instantiate(defaultBrain); brainInstance.name = defaultBrain.name + " (Instance)"; SwarmControl sc = FindFirstObjectByType(); 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(ClusterPrefab brain, string name, float weight) { INucleus root = brain.output; foreach (Synapse synapse in root.synapses) { if (synapse.nucleus.name == name) { synapse.weight = weight; } } } }