namespace Zinnia.Data.Type { using System; using UnityEngine; using Zinnia.Extension; /// /// Holds information about the located surface. /// [Serializable] public class SurfaceData : TransformData { [Tooltip("The origin in which the surface search came from.")] [SerializeField] private Vector3 origin; /// /// The origin in which the surface search came from. /// public Vector3 Origin { get { return origin; } set { origin = value; } } [Tooltip("The direction in which the surface search came from.")] [SerializeField] private Vector3 direction; /// /// The direction in which the surface search came from. /// public Vector3 Direction { get { return direction; } set { direction = value; } } /// /// Positional offset data that has been applied to the collision point. /// public Vector3 PositionalOffset { get; set; } /// /// data about the current collision. /// private RaycastHit collisionData; public RaycastHit CollisionData { get { return collisionData; } set { if (Application.isPlaying) { OnBeforeCollisionDataChange(); } collisionData = value; } } /// /// data about the previous collision. /// public RaycastHit PreviousCollisionData { get; protected set; } /// /// Creates a new with a default and for the collision search. /// public SurfaceData() { } /// /// Creates a new with the given and a default and for the collision search. /// public SurfaceData(Transform transform) : base(transform) { } /// /// Creates a new with a given and for the collision search. /// /// The given origin to instantiate the with. /// The given direction to instantiate the with. public SurfaceData(Vector3 origin, Vector3 direction) { Origin = origin; Direction = direction; } /// public override void Clear() { base.Clear(); Origin = Vector3.zero; Direction = Vector3.zero; PositionalOffset = Vector3.zero; CollisionData = new RaycastHit(); PreviousCollisionData = new RaycastHit(); } /// public override bool Equals(object other) { if (other == null) { return false; } SurfaceData data = other as SurfaceData; return Equals(data); } /// public override int GetHashCode() { return base.GetHashCode(); } /// public override string ToString() { string[] titles = new string[] { "Origin", "Direction", "CollisionData" }; object[] values = new object[] { Origin, Direction, CollisionData.ToFormattedString() }; return StringExtensions.FormatForToString(titles, values, base.ToString()); } /// /// Checks to see if the given is equal to . /// /// The instance to check equality with. /// Whether the two instances are equal. public virtual bool Equals(SurfaceData other) { if (other == null || !GetType().Equals(other.GetType())) { return false; } return base.Equals(other) && Origin.ApproxEquals(other.Origin) && Direction.ApproxEquals(other.Direction) && CollisionData.Equals(other.CollisionData) && PreviousCollisionData.Equals(other.PreviousCollisionData); } /// /// Called before has been changed. /// protected virtual void OnBeforeCollisionDataChange() { PreviousCollisionData = CollisionData; } } }