//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions /// <summary> /// Animation design here... /// </summary> /// <param name="state"></param> public override void DoAnimation(JCS_LiveObjectState state) { // return if the animation are already playing if (mCurrentState == state) { if (mOverrideAnim) { PlayAtBeginning(); } return; } // state in Unity Animator System. int stateIndex = (int)state; if (state == JCS_LiveObjectState.RAND_ATTACK) { // get the correct attack animation. stateIndex = (int)GetRandomAttackState(); mAttackState = ((JCS_AttackState)stateIndex); // update state name by attack index/animation! mCurrentStateName = GetStateName(state, (JCS_AttackState)stateIndex); // ready to check attack ends. mEndAttackStage = false; mAnimationTimer = 0; } else { mCurrentStateName = GetStateName(state); } // set the state machine into Unity Engine's // animator system! GetAnimator().SetInteger(GetAnimationState(), stateIndex); // record down the current state we are in. this.mCurrentState = state; }
/// <summary> /// Get the specific state name from animation state. /// </summary> /// <param name="state"> state to get </param> /// <returns> name of the state supose to be. </returns> private string GetStateName(JCS_LiveObjectState state, JCS_AttackState attackState = JCS_AttackState.NONE) { string stateName = mFullClipStateName; string swapName = ""; switch (state) { case JCS_LiveObjectState.STAND: swapName = "stand"; break; case JCS_LiveObjectState.WALK: swapName = "walk"; break; case JCS_LiveObjectState.RAND_ATTACK: { switch (attackState) { case JCS_AttackState.ATTACK_01: swapName = "attack01"; break; case JCS_AttackState.ATTACK_02: swapName = "attack02"; break; case JCS_AttackState.ATTACK_03: swapName = "attack03"; break; case JCS_AttackState.ATTACK_04: swapName = "attack04"; break; case JCS_AttackState.ATTACK_05: swapName = "attack05"; break; } } break; case JCS_LiveObjectState.JUMP: swapName = "jump"; break; case JCS_LiveObjectState.PRONE: swapName = "prone"; break; case JCS_LiveObjectState.ALERT: swapName = "alert"; break; case JCS_LiveObjectState.FLY: swapName = "fly"; break; case JCS_LiveObjectState.LADDER: swapName = "ladder"; break; case JCS_LiveObjectState.ROPE: swapName = "rope"; break; case JCS_LiveObjectState.SIT: swapName = "sit"; break; case JCS_LiveObjectState.HIT: swapName = "hit"; break; case JCS_LiveObjectState.DANCE: swapName = "dance"; break; case JCS_LiveObjectState.SWIM: swapName = "swim"; break; case JCS_LiveObjectState.DIE: swapName = "die"; break; case JCS_LiveObjectState.GHOST: swapName = "ghost"; break; } string[] words; words = stateName.Split(new[] { "%jcs" }, StringSplitOptions.None); stateName = words[0] + swapName + words[1]; return(stateName); }