// Sci-Fi Ship Controller. Copyright (c) 2018-2023 SCSM Pty Ltd. All rights reserved. using System.Collections.Generic; using UnityEngine; namespace SciFiShipController { /// /// Class to store path data. Should not include any path /// manupulation code. Typically this would be in SSManager or /// in a user-defined class. /// [System.Serializable] public class PathData { #region Public variables // IMPORTANT When changing this section update: // SetClassDefaults() and PathData(PathData pathData) clone constructor /// /// A user-defined optional name for the path /// public string name; /// /// Unique identifier of the path /// public int guidHash; /// /// Path distances are out of date and need to be /// refreshed by calling sscManager.RefreshPathDistances(..) /// public bool isDirty; /// /// An ordered list of Locations associated with this Path. If they are /// orphaned or unassigned and not in the SSCManager.locationDataList, /// the isUnassigned flag should be set on the Location. /// public List pathLocationDataList; /// /// Whether the Path is drawn in the scene view of the editor /// public bool showGizmosInSceneView; /// /// Whether the Path Location number are displayed in the scene /// when the SSCManager is selected /// public bool showPointNumberLabelsInScene; /// /// Whether the Location names are displayed in the scene /// when the SSCManager is selected /// public bool showPointNameLabelsInScene; /// /// Whether the cummulative distances are displayed in the scene /// when the SSCManager is selected /// public bool showDistancesInScene; /// /// Whether the path is shown as expanded in the inspector window of the editor. /// public bool showInEditor; /// /// Whether the Path Locations are shown as expanded in the inspector window of the editor /// There could be a lot of Locations in many Paths, so collapse by default /// public bool showLocationsInEditor; /// /// Is the Path's last Location joined to the first Location to complete /// a closed circuit? /// public bool isClosedCircuit; /// /// The colour of the lines drawn in the scene stored as RGBA floats /// public Vector4 pathLineColour; /// /// The distance to place a new Location on the Path away from the line of sight object /// [Range(0f, 50f)] public float locationDefaultNormalOffset; /// /// The total length of the Path. Call sscManager.RefreshPathDistances(..) to /// update. /// public float splineTotalDistance; /// /// The maximum height in up direction that SnapToMesh will use when looking for /// the heighest mesh. See SCCManager.SnapToMesh(..). /// public float snapMaxHeight; /// /// The lowest mesh in the up direction that SnapToMesh will use when looking for /// the heighest mesh. See SCCManager.SnapToMesh(..). /// public float snapMinHeight; #endregion #region Internal or Private variables /// /// [INTERNAL ONLY] /// When a Path is attached to ShipDockingStation as an entry or exit Path /// for a ShipDockingPoint, the LocationData must be initialised so that /// they can correctly move with the docking station at runtime. /// The same Path may be used multiple times on a ShipDockingStation. /// [System.NonSerialized] internal bool isDynamicPathInitialised = false; /// /// The world velocity of the path as a vector. Derived from the world velocity /// of the rigidbody that the path is attached to. This would typically be a mothership /// for a ShipDockingStation. /// internal Vector3 worldVelocity; /// /// [INTERNAL ONLY] /// The world angular velocity of the path as a vector. Derived from the world velocity /// of the rigidbody that the path is attached to. This would typically be a mothership /// for a ShipDockingStation. /// internal Vector3 worldAngularVelocity; /// /// [INTERNAL ONLY] /// When a path is attached to a moving ShipDockingStation this is the current position /// of that gameobject, else it is Vector3.zero. /// internal Vector3 anchorPoint; /// /// [INTERNAL ONLY] /// This is used to determine if this path has already been updated in the current frame. /// Used with ShipDockingStation to avoid updating the same Path (and Locations) multiple /// times. /// [System.NonSerialized] internal float updateSeqNumber; #endregion #region Class Constructors public PathData() { SetClassDefaults(); } // Copy constructor public PathData(PathData pathData) { if (pathData == null) { SetClassDefaults(); } else { name = pathData.name; guidHash = pathData.guidHash; isDirty = pathData.isDirty; if (pathData.pathLocationDataList == null) { pathLocationDataList = new List(3); } else { pathLocationDataList = pathData.pathLocationDataList.ConvertAll(plocData => new PathLocationData(plocData)); } showInEditor = pathData.showInEditor; showLocationsInEditor = pathData.showLocationsInEditor; showGizmosInSceneView = pathData.showGizmosInSceneView; showPointNumberLabelsInScene = pathData.showPointNumberLabelsInScene; showPointNameLabelsInScene = pathData.showPointNameLabelsInScene; showDistancesInScene = pathData.showDistancesInScene; isClosedCircuit = pathData.isClosedCircuit; pathLineColour = pathData.pathLineColour; locationDefaultNormalOffset = pathData.locationDefaultNormalOffset; splineTotalDistance = pathData.splineTotalDistance; snapMinHeight = pathData.snapMinHeight; snapMaxHeight = pathData.snapMaxHeight; worldVelocity = pathData.worldVelocity; worldAngularVelocity = pathData.worldAngularVelocity; anchorPoint = pathData.anchorPoint; } } #endregion #region Initialisation private void SetClassDefaults() { name = string.Empty; // Get a unique GUID then convert it to a hash for efficient non-GC access. guidHash = SSCMath.GetHashCodeFromGuid(); isDirty = false; // Assume at least 3 points in list pathLocationDataList = new List(3); showGizmosInSceneView = true; showPointNumberLabelsInScene = false; showPointNameLabelsInScene = false; showDistancesInScene = false; showInEditor = true; showLocationsInEditor = false; isClosedCircuit = false; pathLineColour = new Vector4(1f,0f,0f,1f); locationDefaultNormalOffset = 1f; splineTotalDistance = 0f; // Used with SSCManager.SnapToMesh(..) snapMinHeight = 0f; snapMaxHeight = 2000f; worldVelocity = Vector3.zero; worldAngularVelocity = Vector3.zero; anchorPoint = Vector3.zero; } #endregion #region Overrides /// /// PathData comparison /// /// /// public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return false; } else { return guidHash == ((PathData)obj).guidHash; } } public override int GetHashCode() { return guidHash; } #endregion } }