using System; using UnityEngine; namespace NanoBrain { /// /// The NanoBrain Unity Componnent /// /// This implements the top-level NanoBrain Cluster public class Brain : MonoBehaviour { /// /// The Cluster prefab from which the cluster is created /// public ClusterPrefab brainPrefab; [NonSerialized] private Cluster brainInstance; /// /// The cluster isntance /// public Cluster brain { get { if (brainInstance == null && brainPrefab != null) { brainInstance = new Cluster(brainPrefab) { name = brainPrefab.name }; } else if (brainInstance != null && brainPrefab == null) { brainInstance = null; } return brainInstance; } } /// /// Update the weight for all Synapses coming from the Neuron with the given name /// /// The cluster in which the synapses are updated /// The name of the Neuron for which the weights are updated /// The new Synapse weight public static void UpdateWeight(Cluster brain, string name, float weight) { Nucleus root = brain.defaultOutput; foreach (Synapse synapse in root.synapses) { if (synapse.neuron.name == name) { if (synapse.weight != weight) { synapse.weight = weight; // Debug.Log($"Updated weight for {name}"); } } } } } }