using UnityEngine; using Unity.Mathematics; using static Unity.Mathematics.math; [System.Serializable] public class Receptor : Neuron, IReceptor { public Receptor(Cluster parent, string name) : base(parent, name) { this.array = new NucleusArray(this); if (this.name.IndexOf(":") < 0) this.name += ": 0"; } public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) { this.array = new NucleusArray(this); } public string GetName() { return this.name; } public override Nucleus ShallowCloneTo(Cluster parent) { Receptor clone = new(parent, name) { }; CloneFields(clone); return clone; } public override Nucleus Clone(ClusterPrefab prefab) { Receptor clone = new(prefab, name) { array = this._array }; CloneFields(clone); // Adding receivers will also add synapses to the receivers foreach (Nucleus receiver in this.receivers.ToArray()) clone.AddReceiver(receiver); return clone; } [SerializeReference] private NucleusArray _array; public NucleusArray array { set { _array = value; } } public Nucleus[] nucleiArray { get { return _array.nuclei; } set { _array.nuclei = value; } } public void AddReceptorElement(ClusterPrefab prefab) { //this.nucleiArray = IReceptorHelpers.AddReceptorElement(this.nucleiArray, prefab); IReceptorHelpers.AddReceptorElement(this, prefab); } public void RemoveReceptorElement() { // this.nucleiArray = IReceptorHelpers.RemoveReceptorElement(this.nucleiArray); IReceptorHelpers.RemoveReceptorElement(this); } // public override void AddReceiver(Nucleus receiverToAdd, float weight = 1) { // foreach (Nucleus element in receptorToAdd.nucleiArray) { // if (element is Neuron neuron) { // neuron._receivers.Add(receiverToAdd); // receiverToAdd.AddSynapse(element, weight); // } // } // } public virtual void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) { IReceptorHelpers.AddArrayReceiver(this, receiverToAdd, weight); // foreach (Nucleus element in this._array.nuclei) { // if (element is Neuron neuron) { // neuron.AddReceiver(receiverToAdd, weight); // } // } } public override void UpdateStateIsolated() { this.outputValue = this.bias; //Debug.Log($"Receptor {this.name} outputvalue = {this.outputValue}"); } public override void UpdateNuclei() { this.stale++; if (this.stale > staleValueForSleep && lengthsq(this.bias) > 0) { this.bias = new float3(0, 0, 0); this.parent.UpdateFromNucleus(this); } } public override void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { this._array ??= new NucleusArray(this.parent); this._array.ProcessStimulus(thingId, inputValue, thingName); } }