/// --------------------------------------------- /// Senses Pack for Behavior Designer Pro /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.AddOns.SensesPack.Runtime.Emitters { using Opsive.BehaviorDesigner.AddOns.SensesPack.Runtime.Utility; using System; using Unity.Mathematics; using UnityEngine; /// /// Represents a trace or scent that can be detected by agents in the environment. /// The trace has an intensity that dissipates over time. /// public struct Trace : IPosition, IEquatable { [Tooltip("The maximum intensity of the trace.")] public float Intensity; [Tooltip("The position in 3D space where the trace is located.")] public float3 Position { get; } private float StartTime; private float DissipationRate; /// /// Initializes a new instance of the Trace struct. /// /// The position where the trace is created. public Trace(Vector3 position) { Intensity = 1; Position = position; StartTime = Time.time; DissipationRate = Intensity / 10; // Default to a dissipation time of 10 seconds. } /// /// Initializes a new instance of the Trace struct. /// /// The position where the trace is created. /// The maximum intensity of the trace. /// The amount of time in seconds before the trace is fully dissipated. public Trace(Vector3 position, float intensity, float dissipationTime) { Position = position; Intensity = intensity; StartTime = Time.time; if (dissipationTime > 0) { DissipationRate = Intensity / dissipationTime; } else { DissipationRate = 0; } } /// /// Calculates the current intensity of the trace based on time elapsed since creation. /// /// The current time. /// The current intensity of the trace. public float GetIntensity(float time) { return Intensity - (time - StartTime) * DissipationRate; } /// /// Determines whether this trace is equal to another trace. /// /// The trace to compare with. /// True if the traces are at the same position. public bool Equals(Trace other) { return Position.x == other.Position.x && Position.y == other.Position.y && Position.z == other.Position.z; } } }