/// <summary> /// Check if we are still in the attack stage. /// </summary> /// <returns> /// true: in attack stage. /// false: not in attack stage. /// </returns> protected bool isInAttackStage() { JCS_LiveObjectState lastState = (JCS_LiveObjectState)GetCharacterAnimator().CurrentAnimId; if (lastState == JCS_LiveObjectState.RAND_ATTACK && !GetCharacterAnimator().CurrentAnimation.IsDonePlaying) { return(true); } return(false); }
/// <summary> /// Check this player in that state! /// </summary> /// <param name="state"> state to check </param> /// <returns> true: in the state, false: not in the state </returns> public bool IsInState(JCS_LiveObjectState state) { // first check the self-define one. if (mCurrentState != state) { return(false); } // then check Unity's Animator state. mAnimatorStateInfo = GetAnimator().GetCurrentAnimatorStateInfo(0); return(mAnimatorStateInfo.IsName(mCurrentStateName)); }
//======================================== // 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> /// Do the animation by passin the state. /// </summary> /// <param name="state"> state </param> /// <returns> /// true: play animation success. /// false: failed to play animation. /// </returns> protected bool DoAnimation(JCS_LiveObjectState state) { if (GetCharacterAnimator().CurrentAnimation != null) { if (GetCharacterAnimator().CurrentAnimId == (int)JCS_LiveObjectState.RAND_ATTACK) { if (!GetCharacterAnimator().CurrentAnimation.IsDonePlaying) { return(false); } } } if (state != JCS_LiveObjectState.RAND_ATTACK) { if (CharacterState != JCS_2DCharacterState.CLIMBING) { JCS_LiveObjectState lastState = (JCS_LiveObjectState)GetCharacterAnimator().CurrentAnimId; if (lastState == JCS_LiveObjectState.JUMP && !isGrounded()) { return(false); } } } if (state == JCS_LiveObjectState.RAND_ATTACK) { GetCharacterAnimator().PlayOneShot((int)JCS_LiveObjectState.RAND_ATTACK); } else { GetCharacterAnimator().DoAnimation((int)state); } DoSound(state); return(true); }
public void Jump(float force) { // cannot double jump, to design // a double jump plz create another // action class to handle the effect. if (!isGrounded) { return; } VelY = force; // record down the animation before do jump animation mAnimStateBeforeJump = mLiveObjectAnimator.GetCurrentAnimationState(); // do animation mLiveObjectAnimator.DoAnimation(JCS_LiveObjectState.JUMP); // next frame re-calculate the time zone. mJumped = true; // start check if grounded and end the jump animation. mCheckEndJumpAnimation = true; }
/// <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); }
/// <summary> /// Check if the animation in the same state. /// </summary> /// <param name="state"></param> /// <returns></returns> public bool IsInState(JCS_LiveObjectState state) { return(m2DAnimator.IsInState((int)state)); }
/// <summary> /// Do the animation. /// </summary> /// <param name="state"></param> public override void DoAnimation(JCS_LiveObjectState state = JCS_LiveObjectState.STAND) { m2DAnimator.DoAnimation((int)state); mCurrentState = state; }
/// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> private AudioClip GetSoundByPlayerState(JCS_LiveObjectState state) { switch (state) { case JCS_LiveObjectState.STAND: return(mStandSound); case JCS_LiveObjectState.WALK: return(mWalkSound); case JCS_LiveObjectState.RAND_ATTACK: { //int index = JCS_Random.Range(0, mAttackSounds.Length); //return mAttackSounds[index]; return(null); } case JCS_LiveObjectState.JUMP: { //int index = JCS_Random.Range(0, mJumpSound.Length); //return mJumpSound[index]; return(null); } case JCS_LiveObjectState.PRONE: return(mProneSound); case JCS_LiveObjectState.ALERT: return(mAlertSound); case JCS_LiveObjectState.FLY: return(mFlySound); case JCS_LiveObjectState.LADDER: return(mLadderSound); case JCS_LiveObjectState.ROPE: return(mRopeSound); case JCS_LiveObjectState.SIT: return(mSitSound); case JCS_LiveObjectState.HIT: return(mHitSound); case JCS_LiveObjectState.DANCE: return(mDanceSound); case JCS_LiveObjectState.SWIM: return(mSwimSound); case JCS_LiveObjectState.DIE: return(mDeadSound); case JCS_LiveObjectState.GHOST: return(mGhostSound); } JCS_Debug.LogError( "JCS_2DSideScrollerPlayerAudioController", "Return sound that aren't in the player state..."); return(null); }
/// <summary> /// /// </summary> /// <param name="state"></param> public void PlaySoundByPlayerState(JCS_LiveObjectState state) { AudioClip clip = GetSoundByPlayerState(state); mJCSSoundPlayer.PlayOneShot(clip); }
/// <summary> /// Do the sound base on the state we are in. /// </summary> /// <param name="state"> state we are in. </param> protected void DoSound(JCS_LiveObjectState state) { GetAudioController().PlaySoundByPlayerState(state); }
/// <summary> /// Animation design here... /// </summary> /// <param name="state"></param> public abstract void DoAnimation(JCS_LiveObjectState state = JCS_LiveObjectState.STAND);