using System; using UnityEngine; /// /// The Nanobrain namespace /// namespace NanoBrain { /// /// A Nucleus is a basic element in a brain cluster /// [Serializable] public abstract class Nucleus { /// /// The name of the Nucleus /// [HideInInspector] public string name; /// /// The cluster instance in which the nucleus is located /// [SerializeReference] //[HideInInspector] public Cluster parent; /// /// Function to make a partial clone of this nucleus /// /// The cluster in which the cloned nucleus should be placed /// public abstract Nucleus ShallowCloneTo(Cluster parent); /// /// The types of Nucleus /// public enum Type { None, Neuron, MemoryCell, Cluster, } #region Update /// /// Update the state without updating other Nuclei /// public abstract void UpdateStateIsolated(); #endregion Update public static bool EqualStructure(Nucleus nucleus1, Nucleus nucleus2) { if (nucleus1.parent != null && nucleus2.parent != null) { if (nucleus1.parent.baseName != nucleus2.parent.baseName) return false; } else { // mainly to check one is null, other is not. if (nucleus1.parent != nucleus2.parent) return false; } if (nucleus1 is Neuron neuron1) { if (nucleus2 is not Neuron neuron2) return false; if (neuron1.name != neuron2.name) return false; return Neuron.EqualStructure(neuron1, neuron2); } else if (nucleus1 is Cluster cluster1) { if (nucleus2 is not Cluster cluster2) return false; if (cluster1.baseName != cluster2.baseName) return false; return Cluster.EqualStructure(cluster1, cluster2); } return false; } } }