using System; using Goap.Core; namespace Goap.Runtime { public abstract class GlobalWorldSensorBase : IGlobalWorldSensor { public IWorldKey Key => this.Config.Key; public virtual ISensorTimer Timer => SensorTimer.Always; public IWorldSensorConfig Config { get; private set; } public void SetConfig(IWorldSensorConfig config) => this.Config = config; /// /// Called when the sensor is created. /// public abstract void Created(); public Type[] GetKeys() => new[] { TypeReSolveHelper.ResolveType(this.Key) }; /// /// Senses the world data using this sensor. Don't override this method. /// /// The world data. public void Sense(IWorldData data) { var state = data.GetWorldState(TypeReSolveHelper.ResolveType(this.Key)); if (!this.Timer.ShouldSense(state?.Timer)) return; data.SetState(this.Key, this.Sense()); } /// /// Senses the world data. /// /// The sensed value. public abstract SenseValue Sense(); } }