46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class Receptor {
|
|
|
|
|
|
public List<Perceptoid> perceptei = new();
|
|
|
|
public int thingId;
|
|
public int thingType;
|
|
public Vector3 localPosition;
|
|
|
|
public Receptor(Perceptoid perceptoid) {
|
|
this.perceptei.Add(perceptoid);
|
|
}
|
|
|
|
|
|
public virtual void ProcessStimulus(int thingId, Vector3 localPosition) {
|
|
this.thingId = thingId;
|
|
this.localPosition = localPosition;
|
|
|
|
Perceptoid selectedPerceptoid = null;
|
|
foreach (Perceptoid perceptoid in this.perceptei) {
|
|
if (perceptoid.thingId == this.thingId) {
|
|
selectedPerceptoid = perceptoid;
|
|
break;
|
|
}
|
|
else if (perceptoid.isSleeping)
|
|
selectedPerceptoid = perceptoid;
|
|
else if (selectedPerceptoid == null) {
|
|
selectedPerceptoid = perceptoid;
|
|
}
|
|
else if (selectedPerceptoid.isSleeping == false) {
|
|
if (perceptoid.receptor.localPosition.magnitude < selectedPerceptoid.receptor.localPosition.magnitude)
|
|
selectedPerceptoid = perceptoid;
|
|
}
|
|
}
|
|
if (selectedPerceptoid == null) {
|
|
Debug.Log("No perceptoid selected, stimulus is ignored");
|
|
return;
|
|
}
|
|
Debug.Log($"Stimulus {thingId} {selectedPerceptoid.thingId}");
|
|
selectedPerceptoid.UpdateState(this.thingId, this.localPosition);
|
|
}
|
|
} |