NanoBrain-unitypackage/Perceptoid.cs

105 lines
3.3 KiB
C#

/*
using UnityEngine;
[System.Serializable]
public class Perceptoid : Neuroid {
// A neuroid which has no neurons as input
// But receives value from a receptor
public NanoBrain brain;
public Receptor receptor;
public string baseName;
public int thingId;
//[SerializeField]
// Needs serialization!!!!
[SerializeReference]
public PercepteiArray array;
#region Serialization
[SerializeField]
public int thingType;
public override void Rebuild(NanoBrain brain) {
base.Rebuild(brain);
this.receptor = Receptor.GetReceptor(brain, thingType);
this.receptor.perceptei.Add(this);
if (string.IsNullOrEmpty(this.baseName))
this.baseName = this.name;
}
public override void Deserialize(Nucleus nucleus) {
base.Deserialize(nucleus);
if (nucleus is Perceptoid perceptoid)
this.receptor.thingType = perceptoid.thingType;
// Point all receivers to this perceptoid instead of the default nucleus
foreach (INucleus receiver in nucleus.receivers) {
foreach (Synapse synapse in receiver.synapses) {
if (synapse.nucleus == nucleus)
synapse.nucleus = this;
}
}
// Point all synapses to this perceptoid instead of the default nucleus
// foreach (Synapse synapse in nucleus.synapses) {
// foreach (INucleus r in synapse.nucleus.receivers) {
// if (r == nucleus)
// this.receiver = this;
// }
// }
// Copying disabled for now
// // Copy all the synapses
// this.synapses = nucleus.synapses;
// // Copy all receivers
// this.receivers = nucleus.receivers;
}
#endregion Serialization
public Perceptoid(NanoBrain brain, int thingType, string name = "sensor") : base(name) {
this.brain = brain;
this.cluster = brain.cluster;
if (this.cluster != null) {
brain.perceptei.Add(this);
}
else
Debug.LogError("No neuroid network");
this.nucleusType = nameof(Perceptoid);
this.name = name;
this.baseName = name;
this.thingType = thingType;
this.receptor = Receptor.GetReceptor(brain, thingType);
this.receptor.perceptei.Add(this);
this.array = new PercepteiArray(this);
}
public Perceptoid(PercepteiArray array) : base(array.name) {
this.array = array;
Perceptoid source = array.perceptei[0];
this.brain = source.brain;
this.cluster = source.cluster;
if (this.brain != null) {
this.brain.perceptei.Add(this);
}
else
Debug.LogError("No neuroid network");
this.nucleusType = nameof(Perceptoid);
this.name = source.baseName;
this.baseName = source.baseName;
this.thingType = source.thingType;
this.receptor = Receptor.GetReceptor(this.brain, this.thingType);
this.receptor.perceptei.Add(this);
}
public override void UpdateState() {
Vector3 result = this.receptor.localPosition;
UpdateResult(result);
}
}
*/