using System.Linq; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class NucleusArray { [SerializeReference] private IReceptor[] _nuclei; //private ClusterPrefab[] _clusters; public IReceptor[] nuclei { get { return _nuclei; } } public string name; public NucleusArray(INucleus nucleus) { this.name = nucleus.name; this._nuclei = new INucleus[1]; this._nuclei[0] = nucleus; //this._clusters = new ClusterPrefab[0]; } public NucleusArray(ClusterPrefab cluster) { this.name = cluster.name; this._nuclei = new INucleus[0]; // this._clusters = new ClusterPrefab[1]; // this._clusters[0] = cluster; } public NucleusArray(int size, string name) { this.name = name; this._nuclei = new INucleus[size]; } public void AddNucleus() { if (this._nuclei.Length == 0) { Debug.LogError("Empty perceptoid array, cannot add"); return; } int newLength = this._nuclei.Length + 1; IReceptor[] newArray = new INucleus[newLength]; for (int i = 0; i < this._nuclei.Length; i++) newArray[i] = this._nuclei[i]; if (this._nuclei[0] is INucleus nucleus) newArray[newLength - 1] = (INucleus)nucleus.Clone(); this._nuclei = newArray; } public void RemoveNucleus() { int newLength = this._nuclei.Length - 1; if (newLength == 0) { Debug.LogWarning("Perceptoid array cannot be empty"); return; } IReceptor[] newPerceptei = new INucleus[newLength]; for (int i = 0; i < newLength; i++) newPerceptei[i] = this._nuclei[i]; // Delete the last perception if (this._nuclei[newLength] is INucleus nucleus) Neuron.Delete(nucleus); //this._nuclei[newLength]); this._nuclei = newPerceptei; } }