private void Update() { if (Managers.GameState.Instance.IsPaused) { return; } Enums.HeroState temp = this.CurrentState; this.CurrentState = this.stateMap.GetState(this.anim.GetCurrentAnimatorStateInfo(0).fullPathHash); if (temp != CurrentState) { this.doOnce = false; this.anim.SetBool(this.attackFinishedHash, false); this.squishing.DoubleSpeed = false; this.squishing.StartSquishing(); } switch (this.CurrentState) { case Enums.HeroState.Idle: Idle(); break; case Enums.HeroState.Move: Move(); break; case Enums.HeroState.Attack: Attack(); break; case Enums.HeroState.Hurt: Hurt(); break; } }
/// <summary> Gets the path hash for a single state </summary> /// <param name="state"> The state to hash. </param> /// <returns> The hash. </returns> public int GetPathHash(Enums.HeroState state) { StateMapAttribute metadata = (StateMapAttribute)typeof(Enums.HeroState).GetField(state.ToString()).GetCustomAttributes(false)[0]; StringBuilder path = new StringBuilder(metadata.Layer + "."); foreach (string machine in metadata.StateMachines) { path.Append(machine + "."); } path.Append(state.ToString()); return(Animator.StringToHash(path.ToString())); }
/// <summary> Initiallizes the given map with the meta data on the AnimatorState enum. </summary> /// <param name="map"> The map to initialize. </param> private void InitializeStateMap(Dictionary <int, Enums.HeroState> map) { for (int i = 0; i < (int)Enums.HeroState.length; i++) { Enums.HeroState state = (Enums.HeroState)i; int hash = GetPathHash(state); map.Add(hash, state); } if (map.Keys.Count < (int)Enums.HeroState.length) { Debug.LogError("States are Missing from Behavior stateMap!"); } }
private void Update() { if (Managers.GameState.Instance.IsPaused) { return; } if (invunTimer > 0) { if (flashTimer > flashInterval) { isVisible = !isVisible; flashTimer = 0; this.sprite.enabled = isVisible; } flashTimer += Time.deltaTime; invunTimer -= Time.deltaTime; } else if (!isVisible || isInvulnerable) { isVisible = true; this.sprite.enabled = true; isInvulnerable = false; } Enums.HeroState temp = this.CurrentState; this.CurrentState = this.stateMap.GetState(this.anim.GetCurrentAnimatorStateInfo(0).fullPathHash); if (temp != CurrentState) { this.doOnce = false; this.anim.SetBool(this.attackFinishedHash, false); this.squishing.DoubleSpeed = false; this.squishing.StartSquishing(); } switch (this.CurrentState) { case Enums.HeroState.Idle: Idle(); break; case Enums.HeroState.Move: Move(); break; case Enums.HeroState.Attack: Attack(); break; case Enums.HeroState.Hurt: Hurt(); break; } }
private void Start() { this.anim = GetComponent <Animator>(); this.rgbdy = GetComponent <Rigidbody2D>(); this.input = GetComponent <HeroInput>(); this.stateMap = new StateMap(); this.doOnce = false; this.attackFinishedHash = Animator.StringToHash("AttackFinished"); this.hitHash = Animator.StringToHash("Hit"); this.Health = this.maxHealth; this.CurrentWeapon = 0; this.CurrentState = Enums.HeroState.Idle; foreach (Weapon w in this.weapons) { w.Init(); w.CleanUp(); } }
/// <summary> Gets the path hash for a single state </summary> /// <param name="state"> The state to hash. </param> /// <returns> The hash. </returns> public int GetPathHash(Enums.HeroState state) { return(Animator.StringToHash("Base Layer." + state.ToString())); }