using MalbersAnimations.Scriptables; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace MalbersAnimations.Controller { [System.Serializable] public class MSpeedSet : IComparable,IComparer { [Tooltip("Name of the Speed Set")] public string name; [Tooltip("States that will use the Speed Set")] public List states; [Tooltip("Stances that will use the Speed Set")] public List stances; [Tooltip("Which Speed the Set will start, This value is the Index for the Speed Modifier List, Starting the first index with (1) instead of (0)")] public IntReference StartVerticalIndex; [Tooltip("Set the Top Index when Increasing the Speed using SpeedUP")] public IntReference TopIndex; [Tooltip("When the Speed is locked this will be the value s")] public IntReference m_LockIndex = new IntReference(1); [Tooltip("Lock the Speed Set to Certain Value")] public BoolReference m_LockSpeed = new BoolReference(false); [Tooltip("Backwards Speed multiplier: When going backwards the speed will be decreased by this value")] public FloatReference BackSpeedMult = new FloatReference(0.5f); [Tooltip("Lerp used to Activate the FreeMovement")] public FloatReference PitchLerpOn = new FloatReference(10f); [Tooltip("Lerp used to Deactivate the FreeMovement")] public FloatReference PitchLerpOff = new FloatReference(10f); [Tooltip("Lerp used to for the Banking on FreeMovement")] public FloatReference BankLerp = new FloatReference(10f); /// List of Speed Modifiers for the Speed Set public List Speeds; /// THis Speed Set has no Stances public bool HasStances => stances != null && stances.Count > 0; // public bool HasStates => states != null && states.Count > 0; /// Current Active Index of the SpeedSet public int CurrentIndex { get; set; } /// Locked Index of a Speed Set public int LockIndex { get => m_LockIndex.Value; set => m_LockIndex.Value = value; } /// Locked Index of a Speed Set public bool LockSpeed { get => m_LockSpeed.Value; set { m_LockSpeed.Value = value; if (value) LockedSpeedModifier = Speeds[Mathf.Clamp(LockIndex-1, 0, Speeds.Count - 1)]; //Extract the Lock Speed } } /// Store the current Lock Speed Modifier public MSpeed LockedSpeedModifier { get; set; } public MSpeedSet() { name = "Set Name"; states = new List(); StartVerticalIndex = new IntReference(1); TopIndex = new IntReference(2); Speeds = new List(1) { new MSpeed("SpeedName", 1, 4, 4) }; } public MSpeed this[int index] { get => Speeds[index]; set => Speeds[index] = value; } public MSpeed this[string name] => Speeds.Find(x => x.name == name); public bool HasStance(int stance) { if (!HasStances) return true; else return stances.Find(s => s.ID == stance); } public int Compare(object x, object y) { bool XHas = (x as MSpeedSet).HasStances; bool YHas = (y as MSpeedSet).HasStances; if (XHas && YHas) return 0; else if (XHas && !YHas) return 1; else return -1; } public int CompareTo(object obj) { bool XHas = (obj as MSpeedSet).HasStances; bool YHas = HasStances; if (XHas && YHas) return 0; else if (XHas && !YHas) return 1; else return -1; } } [System.Serializable] /// Position, Rotation and Animator Modifiers for the Animals public struct MSpeed { /// Default value for an MSpeed public static readonly MSpeed Default = new MSpeed("Default", 1, 4, 4); /// Name of this Speed public string name; ///// Name of the Speed converted to HashCode, easier to compare //public int nameHash; ///// Name of this Speed //public bool active = false; /// Vertical Mutliplier for the Animator public FloatReference Vertical; /// Add additional speed to the transfrom public FloatReference position; /// Smoothness to change to the Transform speed, higher value more Responsiveness public FloatReference lerpPosition; /// Smoothness to change to the Animator Vertical speed, higher value more Responsiveness public FloatReference lerpPosAnim; /// Add Aditional Rotation to the Speed public FloatReference rotation; /// Smoothness to change to the Rotation speed, higher value more Responsiveness public FloatReference lerpRotation; /// Smoothness to change to the Animator Vertical speed, higher value more Responsiveness public FloatReference lerpRotAnim; /// Changes the Animator Speed public FloatReference animator; /// Smoothness to change to the Animator speed, higher value more Responsiveness public FloatReference lerpAnimator; /// Strafe Stored Velocity public FloatReference strafeSpeed; /// Smoothness to change to the Rotation speed, higher value more Responsiveness public FloatReference lerpStrafe; public string Name { get => name; set => name = value; } public MSpeed(MSpeed newSpeed) { name = newSpeed.name; position = newSpeed.position; lerpPosition = newSpeed.lerpPosition; lerpPosAnim = newSpeed.lerpPosAnim; rotation = newSpeed.rotation; lerpRotation = newSpeed.lerpRotation; lerpRotAnim = newSpeed.lerpRotAnim; animator = newSpeed.animator; lerpAnimator = newSpeed.lerpAnimator; Vertical = newSpeed.Vertical; strafeSpeed = newSpeed.strafeSpeed; strafeSpeed = newSpeed.strafeSpeed; lerpStrafe = newSpeed.lerpStrafe; //nameHash = name.GetHashCode(); } public MSpeed(string name, float lerpPos, float lerpanim) { this.name = name; Vertical = 1; position = 0; lerpPosition = lerpPos; lerpPosAnim = 4; rotation = 0; strafeSpeed = 0; lerpRotation = 4; lerpRotAnim = 4; lerpStrafe = 4; animator = 1; lerpAnimator = lerpanim; // nameHash = name.GetHashCode(); } public MSpeed(string name, float vertical, float lerpPos, float lerpanim) { this.name = name; Vertical = vertical; position = 0; lerpPosition = lerpPos; lerpPosAnim = 4; rotation = 0; strafeSpeed = 0; lerpRotation = 4; lerpRotAnim = 4; lerpStrafe = 4; animator = 1; lerpAnimator = lerpanim; // nameHash = name.GetHashCode(); } public MSpeed(string name) { this.name = name; Vertical = 1; position = 0; lerpPosition = 4; lerpPosAnim = 4; rotation = 0; strafeSpeed = 0; lerpRotation = 4; lerpRotAnim = 4; lerpStrafe = 4; animator = 1; lerpAnimator = 4; // nameHash = name.GetHashCode(); } } }