using System; using UnityEngine; public class NanoBrainComponent : MonoBehaviour { public ClusterPrefab defaultBrain; [NonSerialized] private Cluster brainInstance; public Cluster brain { get { if (brainInstance == null && defaultBrain != null) { brainInstance = new Cluster(defaultBrain) { name = defaultBrain.name + " (Instance)" }; } SwarmControl sc = FindFirstObjectByType(); if (sc != null) { UpdateWeight(brainInstance, "Containment", sc.containmentForce); 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) { if (synapse.weight != weight) { synapse.weight = weight; // Debug.Log($"Updated weight for {name}"); } } } } }