Skip to content
Snippets Groups Projects
Commit aaa63a15 authored by Matthewit Dechatech's avatar Matthewit Dechatech
Browse files

Use animator hash ids

parent f83ae004
No related branches found
No related tags found
No related merge requests found
Showing
with 141 additions and 229 deletions
Loading
Loading
@@ -741,6 +741,7 @@ MonoBehaviour:
GroundedBool: Grounded
GroundSpeedFloat:
AbsGroundSpeedFloat: Absolute Ground Speed
GroundSpeedBool: Ground Moving
SurfaceAngleFloat:
--- !u!114 &11416224
MonoBehaviour:
Loading
Loading
@@ -1071,10 +1072,7 @@ MonoBehaviour:
InputBool:
AcceleratingBool: Accelerating
BrakingBool: Braking
TopSpeedBool: At Top Speed
TopSpeedPercentFloat: Top Speed %
ControlLockBool:
ControlLockTimerFloat:
MovementAxis: Horizontal
InvertAxis: 0
Acceleration: 1.6875
Loading
Loading
Loading
Loading
@@ -13,115 +13,109 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Absolute Ground Speed
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Top Speed %
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Cycle Speed
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Edge Distance
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Hit Spring
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Balancing
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Grounded
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Ground Input
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: At Top Speed
m_Controller: {fileID: 0}
- m_Name: Ground Moving
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Accelerating
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Braking
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Looking Up
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Spindashing
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Ducking
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Jumping
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Rolling
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Pushing
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Underwater
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Main Sprites
Loading
Loading
@@ -699,12 +693,12 @@ AnimatorStateTransition:
m_PrefabInternal: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 4
m_ConditionEvent: Top Speed %
m_EventTreshold: .00999999978
- m_ConditionMode: 1
m_ConditionEvent: Grounded
m_EventTreshold: 0
- m_ConditionMode: 2
m_ConditionEvent: Ground Moving
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
Loading
Loading
@@ -726,8 +720,8 @@ AnimatorStateTransition:
m_PrefabInternal: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: Top Speed %
- m_ConditionMode: 1
m_ConditionEvent: Ground Moving
m_EventTreshold: .00999999978
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
Loading
Loading
@@ -750,8 +744,8 @@ AnimatorStateTransition:
m_PrefabInternal: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 4
m_ConditionEvent: Top Speed %
- m_ConditionMode: 2
m_ConditionEvent: Ground Moving
m_EventTreshold: .00999999978
- m_ConditionMode: 1
m_ConditionEvent: Grounded
Loading
Loading
@@ -1197,8 +1191,8 @@ AnimatorStateTransition:
m_PrefabInternal: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: Top Speed %
- m_ConditionMode: 1
m_ConditionEvent: Ground Moving
m_EventTreshold: .00999999978
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
Loading
Loading
@@ -1386,8 +1380,8 @@ AnimatorStateTransition:
m_PrefabInternal: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 4
m_ConditionEvent: Top Speed %
- m_ConditionMode: 2
m_ConditionEvent: Ground Moving
m_EventTreshold: .00999999978
- m_ConditionMode: 1
m_ConditionEvent: Grounded
Loading
Loading
Loading
Loading
@@ -191,7 +191,8 @@ public override void OnInspectorGUI()
HedgehogEditorGUIUtility.DrawProperties(serializedObject,
"AttachTrigger", "DetachTrigger", "AirSpeedXFloat",
"AirSpeedYFloat", "GroundedBool", "FacingForwardBool",
"GroundSpeedFloat", "AbsGroundSpeedFloat", "SurfaceAngleFloat");
"GroundSpeedFloat", "GroundSpeedBool", "AbsGroundSpeedFloat",
"SurfaceAngleFloat");
}
#endregion
#region Events Foldout
Loading
Loading
Loading
Loading
@@ -483,42 +483,49 @@ public float RelativeSurfaceAngle
/// </summary>
[Tooltip("Name of an Animator trigger set when the controller falls off a surface.")]
public string DetachTrigger;
protected int DetachTriggerHash;
 
/// <summary>
/// Name of an Animator trigger set when the controller lands on a surface.
/// </summary>
[Tooltip("Name of an Animator trigger set when the controller lands on a surface.")]
public string AttachTrigger;
protected int AttachTriggerHash;
 
/// <summary>
/// Name of an Animator bool set to whether the controller is facing forward.
/// </summary>
[Tooltip("Name of an Animator bool set to whether the controller is facing forward.")]
public string FacingForwardBool;
protected int FacingForwardBoolHash;
 
/// <summary>
/// Name of an Animator float set to horizontal air speed, in units per second.
/// </summary>
[Tooltip("Name of an Animator float set to horizontal air speed, in units per second.")]
public string AirSpeedXFloat;
protected int AirSpeedXFloatHash;
 
/// <summary>
/// Name of an Animator float set to vertical air speed, in units per second.
/// </summary>
[Tooltip("Name of an Animator float set to vertical air speed, in units per second.")]
public string AirSpeedYFloat;
protected int AirSpeedYFloatHash;
 
/// <summary>
/// Name of Animator float set to whether the controller is grounded.
/// </summary>
[Tooltip("Name of Animator float set to whether the controller is grounded.")]
public string GroundedBool;
protected int GroundedBoolHash;
 
/// <summary>
/// Name of an Animator float set to the controller's ground speed, in units per second.
/// </summary>
[Tooltip("Name of an Animator float set to the controller's ground speed, in units per second.")]
public string GroundSpeedFloat;
protected int GroundSpeedFloatHash;
 
/// <summary>
/// Name of an Animator float set to the absolute value of the controller's ground speed, in units per second.
Loading
Loading
@@ -526,13 +533,21 @@ public float RelativeSurfaceAngle
[Tooltip("Name of an Animator float set to the absolute value of the controller's ground speed, in units per " +
"second.")]
public string AbsGroundSpeedFloat;
protected int AbsGroundSpeedFloatHash;
/// <summary>
/// Name of an Animator bool set to whether the controller has any ground speed.
/// </summary>
[Tooltip("Name of an Animator bool set to whether the controller has any ground speed.")]
public string GroundSpeedBool;
protected int GroundSpeedBoolHash;
 
/// <summary>
/// Name of an Animator float set to the surface angle, in degrees.
/// </summary>
[Tooltip("Name of an Animator float set to the surface angle, in degrees.")]
public string SurfaceAngleFloat;
protected int SurfaceAngleFloatHash;
#endregion
 
#region Lifecycle Functions
Loading
Loading
@@ -570,6 +585,10 @@ public virtual void Reset()
 
AutoFlip = true;
AutoRotate = true;
DetachTrigger = AttachTrigger = FacingForwardBool = AirSpeedXFloat =
AirSpeedYFloat = GroundedBool = GroundSpeedFloat = AbsGroundSpeedFloat =
SurfaceAngleFloat = GroundSpeedBool = "";
}
 
public void Awake()
Loading
Loading
@@ -594,6 +613,19 @@ public void Awake()
OnSteepDetach = OnSteepDetach ?? new UnityEvent();
OnReactiveEnter = OnReactiveEnter ?? new ReactiveEvent();
OnReactiveExit = OnReactiveExit ?? new ReactiveEvent();
if (Animator == null) return;
DetachTriggerHash = string.IsNullOrEmpty(DetachTrigger) ? 0 : Animator.StringToHash(DetachTrigger);
AttachTriggerHash = string.IsNullOrEmpty(AttachTrigger) ? 0 : Animator.StringToHash(AttachTrigger);
FacingForwardBoolHash = string.IsNullOrEmpty(FacingForwardBool) ? 0 : Animator.StringToHash(FacingForwardBool);
AirSpeedXFloatHash = string.IsNullOrEmpty(AirSpeedXFloat) ? 0 : Animator.StringToHash(AirSpeedXFloat);
AirSpeedYFloatHash = string.IsNullOrEmpty(AirSpeedYFloat) ? 0 : Animator.StringToHash(AirSpeedYFloat);
GroundedBoolHash = string.IsNullOrEmpty(GroundedBool) ? 0 : Animator.StringToHash(GroundedBool);
GroundSpeedFloatHash = string.IsNullOrEmpty(GroundSpeedFloat) ? 0 : Animator.StringToHash(GroundSpeedFloat);
GroundSpeedBoolHash = string.IsNullOrEmpty(GroundSpeedBool) ? 0 : Animator.StringToHash(GroundSpeedBool);
AbsGroundSpeedFloatHash = string.IsNullOrEmpty(AbsGroundSpeedFloat) ? 0 : Animator.StringToHash(AbsGroundSpeedFloat);
SurfaceAngleFloatHash = string.IsNullOrEmpty(SurfaceAngleFloat) ? 0 : Animator.StringToHash(SurfaceAngleFloat);
}
 
public void Update()
Loading
Loading
@@ -773,26 +805,29 @@ public void HandleDisplay(float timestep)
if (Animator == null)
return;
 
if(!string.IsNullOrEmpty(FacingForwardBool))
Animator.SetBool(FacingForwardBool, FacingForward);
if(FacingForwardBoolHash != 0)
Animator.SetBool(FacingForwardBoolHash, FacingForward);
if(AirSpeedXFloatHash != 0)
Animator.SetFloat(AirSpeedXFloatHash, Velocity.x);
 
if(!string.IsNullOrEmpty(AirSpeedXFloat))
Animator.SetFloat(AirSpeedXFloat, Velocity.x);
if(AirSpeedYFloatHash != 0)
Animator.SetFloat(AirSpeedYFloatHash, Velocity.y);
 
if(!string.IsNullOrEmpty(AirSpeedYFloat))
Animator.SetFloat(AirSpeedYFloat, Velocity.y);
if(GroundedBoolHash != 0)
Animator.SetBool(GroundedBoolHash, Grounded);
 
if(!string.IsNullOrEmpty(GroundedBool))
Animator.SetBool(GroundedBool, Grounded);
if(GroundSpeedFloatHash != 0)
Animator.SetFloat(GroundSpeedFloatHash, GroundVelocity);
 
if(!string.IsNullOrEmpty(GroundSpeedFloat))
Animator.SetFloat(GroundSpeedFloat, GroundVelocity);
if(GroundSpeedBoolHash != 0)
Animator.SetBool(GroundSpeedBool, GroundVelocity != 0.0f);
 
if(!string.IsNullOrEmpty(AbsGroundSpeedFloat))
Animator.SetFloat(AbsGroundSpeedFloat, Mathf.Abs(GroundVelocity));
if(AbsGroundSpeedFloatHash != 0)
Animator.SetFloat(AbsGroundSpeedFloatHash, Mathf.Abs(GroundVelocity));
 
if(!string.IsNullOrEmpty(SurfaceAngleFloat))
Animator.SetFloat(SurfaceAngleFloat, SurfaceAngle);
if(SurfaceAngleFloatHash != 0)
Animator.SetFloat(SurfaceAngleFloatHash, SurfaceAngle);
}
 
/// <summary>
Loading
Loading
@@ -1609,8 +1644,8 @@ public bool Detach()
if (Grounded)
{
OnDetach.Invoke();
if (Animator != null && !string.IsNullOrEmpty(DetachTrigger))
Animator.SetTrigger(DetachTrigger);
if (Animator != null && DetachTriggerHash != 0)
Animator.SetTrigger(DetachTriggerHash);
}
 
Grounded = false;
Loading
Loading
@@ -1637,8 +1672,8 @@ public bool Attach(float groundSpeed, float angleRadians)
if (!Grounded)
{
OnAttach.Invoke();
if (Animator != null && !string.IsNullOrEmpty(AttachTrigger))
Animator.SetTrigger(AttachTrigger);
if (Animator != null && AttachTriggerHash != 0)
Animator.SetTrigger(AttachTriggerHash);
}
 
var angleDegrees = DMath.Modp(angleRadians * Mathf.Rad2Deg, 360.0f);
Loading
Loading
Loading
Loading
@@ -21,7 +21,6 @@ public class AirControl : Move
 
#endregion
#region Physics Fields
/// <summary>
/// Air acceleration in units per second squared.
/// </summary>
Loading
Loading
Loading
Loading
@@ -34,6 +34,7 @@ public class EdgeBalance : Move
/// of the platform, or 0 if inactive.
/// </summary>
public string DistanceFloat;
protected int DistanceFloatHash;
#endregion
 
/// <summary>
Loading
Loading
@@ -57,6 +58,7 @@ public override void Awake()
{
base.Awake();
EdgeDistance = 0.0f;
DistanceFloatHash = string.IsNullOrEmpty(DistanceFloat) ? 0 : Animator.StringToHash(DistanceFloat);
}
 
public override void Start()
Loading
Loading
@@ -86,8 +88,8 @@ protected virtual void CreateEdgeSensors()
public override void SetAnimatorParameters()
{
base.SetAnimatorParameters();
if(!string.IsNullOrEmpty(DistanceFloat))
Animator.SetFloat(DistanceFloat, EdgeDistance);
if(DistanceFloatHash != 0)
Animator.SetFloat(DistanceFloatHash, EdgeDistance);
}
 
public override bool Available()
Loading
Loading
Loading
Loading
@@ -10,8 +10,7 @@ protected override void DrawAnimationProperties()
{
HedgehogEditorGUIUtility.DrawProperties(serializedObject,
"InputAxisFloat", "InputBool", "AcceleratingBool",
"BrakingBool", "ControlLockBool", "ControlLockTimerFloat",
"TopSpeedBool", "TopSpeedPercentFloat");
"BrakingBool", "TopSpeedPercentFloat");
base.DrawAnimationProperties();
}
 
Loading
Loading
Loading
Loading
@@ -9,56 +9,37 @@ public class GroundControl : Move
/// <summary>
/// Name of an Animator float set to magnitude of ground control input.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator float set to magnitude of ground control input.")]
public string InputAxisFloat;
protected int InputAxisFloatHash;
 
/// <summary>
/// Name of an Animator bool set to whether there is any input.
/// </summary>
[Tooltip("Name of an Animator bool set to whether there is any input.")]
public string InputBool;
protected int InputBoolHash;
 
/// <summary>
/// Name of an Animator bool set to whether the controller is accelerating.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator bool set to whether the controller is accelerating.")]
public string AcceleratingBool;
protected int AcceleratingBoolHash;
 
/// <summary>
/// Name of an Animator bool set to whether the controller is braking.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator bool set to whether the controller is braking.")]
public string BrakingBool;
/// <summary>
/// Name of an Animator bool set to whether running at top speed or faster.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator bool set to whether running at top speed or faster.")]
public string TopSpeedBool;
protected int BrakingBoolHash;
 
/// <summary>
/// Name of an Animator float set to absolute ground speed divided by top speed.
/// </summary>
[Tooltip("Name of an Animator float set to absolute ground speed divided by top speed.")]
public string TopSpeedPercentFloat;
/// <summary>
/// Name of an Animator bool set to whether the control lock is on.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator bool set to whether the control lock is on.")]
public string ControlLockBool;
/// <summary>
/// Name of an Animator float set to the control lock timer.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator float set to the control lock timer.")]
public string ControlLockTimerFloat;
protected int TopSpeedPercentFloatHash;
#endregion
#region Control
/// <summary>
Loading
Loading
@@ -172,8 +153,7 @@ public override void Reset()
InvertAxis = false;
 
InputAxisFloat = InputBool = AcceleratingBool =
BrakingBool = TopSpeedBool = ControlLockBool =
ControlLockTimerFloat = TopSpeedPercentFloat = "";
BrakingBool = TopSpeedPercentFloat = "";
 
Acceleration = 1.6875f;
AccelerationLocked = false;
Loading
Loading
@@ -190,6 +170,12 @@ public override void Awake()
 
ControlLocked = false;
ControlLockTimer = 0.0f;
InputAxisFloatHash = string.IsNullOrEmpty(InputAxisFloat) ? 0 : Animator.StringToHash(InputAxisFloat);
InputBoolHash = string.IsNullOrEmpty(InputBool) ? 0 : Animator.StringToHash(InputBool);
AcceleratingBoolHash = string.IsNullOrEmpty(AcceleratingBool) ? 0 : Animator.StringToHash(AcceleratingBool);
BrakingBoolHash = string.IsNullOrEmpty(BrakingBool) ? 0 : Animator.StringToHash(BrakingBool);
TopSpeedPercentFloatHash = string.IsNullOrEmpty(TopSpeedPercentFloat) ? 0 : Animator.StringToHash(TopSpeedPercentFloat);
}
 
public override void OnEnable()
Loading
Loading
@@ -269,29 +255,20 @@ public override void OnActiveFixedUpdate()
 
public override void SetAnimatorParameters()
{
if(!string.IsNullOrEmpty(InputAxisFloat))
Animator.SetFloat(InputAxisFloat, _axis);
if(!string.IsNullOrEmpty(InputBool))
Animator.SetBool(InputBool, !DMath.Equalsf(_axis));
if(!string.IsNullOrEmpty(AcceleratingBool))
Animator.SetBool(AcceleratingBool, Accelerating);
if(!string.IsNullOrEmpty(BrakingBool))
Animator.SetBool(BrakingBool, Braking);
if(InputAxisFloatHash != 0)
Animator.SetFloat(InputAxisFloatHash, _axis);
 
if(!string.IsNullOrEmpty(TopSpeedBool))
Animator.SetBool(TopSpeedBool, AtTopSpeed);
if(InputBoolHash != 0)
Animator.SetBool(InputBoolHash, !DMath.Equalsf(_axis));
 
if(!string.IsNullOrEmpty(TopSpeedPercentFloat))
Animator.SetFloat(TopSpeedPercentFloat, Mathf.Abs(Controller.GroundVelocity)/TopSpeed);
if(AcceleratingBoolHash != 0)
Animator.SetBool(AcceleratingBoolHash, Accelerating);
 
if(!string.IsNullOrEmpty(ControlLockBool))
Animator.SetBool(ControlLockBool, ControlLocked);
if(BrakingBoolHash != 0)
Animator.SetBool(BrakingBoolHash, Braking);
 
if(!string.IsNullOrEmpty(ControlLockTimerFloat))
Animator.SetFloat(ControlLockTimerFloat, ControlLockTimer);
if(TopSpeedPercentFloatHash != 0)
Animator.SetFloat(TopSpeedPercentFloatHash, Mathf.Abs(Controller.GroundVelocity)/TopSpeed);
}
 
public void OnSteepDetach()
Loading
Loading
Loading
Loading
@@ -79,23 +79,26 @@ public bool Active
/// </summary>
[Tooltip("Name of an Animator trigger set when the move is activated.")]
public string ActiveTrigger;
protected int ActiveTriggerHash;
 
/// <summary>
/// Name of an Animator bool set to whether the move is active.
/// </summary>
[Tooltip("Name of an Animator bool set to whether the move is active.")]
public string ActiveBool;
protected int ActiveBoolHash;
 
/// <summary>
/// Name of an Animator bool set to whether the move is available.
/// </summary>
[Tooltip("Name of an Animator bool set to whether the move is available.")]
public string AvailableBool;
protected int AvailableBoolHash;
#endregion
 
public virtual void Reset()
{
ActiveTrigger = AvailableBool = "";
ActiveTrigger = ActiveBool = AvailableBool = "";
}
 
public virtual void Awake()
Loading
Loading
@@ -108,6 +111,10 @@ public virtual void Awake()
InputActivated = false;
InputEnabled = true;
 
ActiveTriggerHash = ActiveTrigger == null ? 0 : Animator.StringToHash(ActiveTrigger);
ActiveBoolHash = ActiveBool == null ? 0 : Animator.StringToHash(ActiveBool);
AvailableBoolHash = AvailableBool == null ? 0 : Animator.StringToHash(AvailableBool);
OnActive = OnActive ?? new UnityEvent();
OnEnd = OnEnd ?? new UnityEvent();
OnAvailable = OnAvailable ?? new UnityEvent();
Loading
Loading
@@ -140,11 +147,11 @@ public virtual void Update()
/// </summary>
public virtual void SetAnimatorParameters()
{
if(!string.IsNullOrEmpty(ActiveBool))
Animator.SetBool(ActiveBool, CurrentState == State.Active);
if(ActiveBoolHash != 0)
Animator.SetBool(ActiveBoolHash, CurrentState == State.Active);
 
if(!string.IsNullOrEmpty(AvailableBool))
Animator.SetBool(AvailableBool, CurrentState == State.Available);
if(AvailableBoolHash != 0)
Animator.SetBool(AvailableBoolHash, CurrentState == State.Available);
}
 
/// <summary>
Loading
Loading
@@ -182,8 +189,8 @@ public bool ChangeState(State nextState)
if (Animator == null)
return true;
 
if (CurrentState == State.Active && !string.IsNullOrEmpty(ActiveTrigger))
Animator.SetTrigger(ActiveTrigger);
if (CurrentState == State.Active && ActiveTriggerHash != 0)
Animator.SetTrigger(ActiveTriggerHash);
 
return true;
}
Loading
Loading
Loading
Loading
@@ -83,6 +83,7 @@ public class Roll : Move
/// </summary>
[Tooltip("Name of an Animator bool set to whether the controller is going uphill.")]
public string UphillBool;
protected int UphillBoolHash;
#endregion
private bool _rightDirection;
 
Loading
Loading
@@ -115,6 +116,8 @@ public override void Awake()
base.Awake();
_rightDirection = false;
Uphill = false;
UphillBoolHash = string.IsNullOrEmpty(UphillBool) ? 0 : Animator.StringToHash(UphillBool);
}
 
public override void OnEnable()
Loading
Loading
using Hedgehog.Core.Triggers;
using Hedgehog.Level.Areas;
using UnityEngine;
namespace Hedgehog.Core.Moves
{
/// <summary>
/// Passive, allows custom physics values while underwater.
/// </summary>
public class WaterPhysics : Move
{
protected bool Underwater;
public float GroundAcceleration;
public float GroundDeceleration;
public float GroundFriction;
public float RollingFriction;
public float GroundTopSpeed;
public float AirAcceleration;
public float AirGravity;
public float JumpSpeed;
public float JumpReleaseSpeed;
public override void Reset()
{
base.Reset();
GroundAcceleration = 0.84375f;
GroundDeceleration = 0.9f;
GroundFriction = 0.84375f;
RollingFriction = 0.421875f;
GroundTopSpeed = 1.8f;
AirAcceleration = 1.6875f;
AirGravity = 2.25f;
JumpSpeed = 2.1f; // 1.8 for knux
JumpReleaseSpeed = 1.2f;
}
public override void Awake()
{
base.Awake();
Underwater = false;
}
public override void Start()
{
base.Start();
Controller.OnReactiveEnter.AddListener(OnReactive);
Controller.OnReactiveExit.AddListener(OnReactive);
}
protected void OnReactive(BaseReactive reactive)
{
Underwater = Controller.Inside<Water>();
if (Underwater) Perform();
else End();
}
public override void OnActiveEnter(State previousState)
{
Controller.GroundFriction = GroundFriction;
if (Controller.GroundControl != null)
{
Controller.GroundControl.Acceleration = GroundAcceleration;
Controller.GroundControl.Deceleration = GroundDeceleration;
Controller.GroundControl.TopSpeed = GroundTopSpeed;
}
if (Controller.AirControl != null)
{
Controller.AirControl.Acceleration = AirAcceleration;
Controller.AirGravity = AirGravity;
}
var jump = Controller.GetMove<Jump>();
if (jump != null)
{
jump.ActivateSpeed = JumpSpeed;
jump.ReleaseSpeed = JumpReleaseSpeed;
}
var roll = Controller.GetMove<Roll>();
if (roll != null)
{
roll.Friction = RollingFriction;
}
}
}
}
fileFormatVersion: 2
guid: 8a1b02617f5097a489f045f6a33fee21
timeCreated: 1448613803
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading
Loading
@@ -32,7 +32,6 @@ public class ObjectTrigger : BaseTrigger
/// or area trigger, an area trigger is automatically added. If there is already a platform
/// trigger, the object is activated when it is landed on.
/// </summary>
[SerializeField]
[Tooltip("Whether to automatically trigger when the object is touched.")]
public bool AutoActivate;
 
Loading
Loading
@@ -43,28 +42,24 @@ public class ObjectTrigger : BaseTrigger
/// Whether the trigger can be activated if it is already on. If true, OnActivateEnter and
/// OnActivateExit will be invoked for any number of objects that trigger it.
/// </summary>
[SerializeField]
[Tooltip("Whether the trigger can be activated if it is already on.")]
public bool AllowReactivation;
 
/// <summary>
/// Invoked when the object is activated. This will not occur if the object is already activated.
/// </summary>
[SerializeField]
public ObjectEvent OnActivateEnter;
 
/// <summary>
/// Invoked while the object is activated, each FixedUpdate. This will occur for every controller
/// that is activating it.
/// </summary>
[SerializeField]
public ObjectEvent OnActivateStay;
 
/// <summary>
/// Invoked when the object is deactivated. This will not occur if the object still has something
/// activating it.
/// </summary>
[SerializeField]
public ObjectEvent OnActivateExit;
 
[HideInInspector]
Loading
Loading
@@ -74,23 +69,22 @@ public class ObjectTrigger : BaseTrigger
/// <summary>
/// Reference to the target animator.
/// </summary>
[SerializeField]
[Tooltip("Reference to the target animator.")]
public Animator Animator;
 
/// <summary>
/// Name of an Animator trigger set when the object is activated.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator trigger set when the object is activated.")]
public string ActivatedTrigger;
protected int ActivatedTriggerHash;
 
/// <summary>
/// Name of an Animator bool set to whether the object is activated.
/// </summary>
[SerializeField]
[Tooltip("Name of an Animator bool set to whether the object is activated.")]
public string ActivatedBool;
protected int ActivatedBoolHash;
#endregion
 
public override void Reset()
Loading
Loading
@@ -119,6 +113,10 @@ public override void Awake()
Activated = false;
 
Animator = Animator ?? GetComponentInChildren<Animator>();
if (Animator == null) return;
ActivatedTriggerHash = string.IsNullOrEmpty(ActivatedTrigger) ? 0 : Animator.StringToHash(ActivatedTrigger);
ActivatedBoolHash = string.IsNullOrEmpty(ActivatedBool) ? 0 : Animator.StringToHash(ActivatedBool);
}
 
public void Start()
Loading
Loading
@@ -141,8 +139,8 @@ public void Start()
 
public void FixedUpdate()
{
if (Animator != null && ActivatedBool.Length > 0)
Animator.SetBool(ActivatedBool, Activated);
if (Animator != null && ActivatedBoolHash != 0)
Animator.SetBool(ActivatedBoolHash, Activated);
 
if (Collisions.Count <= 0) return;
 
Loading
Loading
@@ -166,8 +164,8 @@ public void Activate(HedgehogController controller = null)
OnActivateEnter.Invoke(controller);
BubbleEvent(controller);
 
if (Animator != null && ActivatedTrigger.Length > 0)
Animator.SetTrigger(ActivatedTrigger);
if (Animator != null && ActivatedTriggerHash != 0)
Animator.SetTrigger(ActivatedTriggerHash);
}
 
/// <summary>
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment