예제 #1
0
    // Update is called once per frame
    void Update()
    {
        m_ElapsedTime += Time.deltaTime;
        m_PositionRef  = m_RootRef.transform.position;

        switch (m_State)
        {
        case AnimationState.Idle:
            m_PositionRef.y = 0.5f * Mathf.Sin(Define.TIME_IDLE * m_ElapsedTime);
            m_RootRef.transform.position = m_PositionRef;
            break;

        case AnimationState.Attack:
            float ratio       = Mathf.Min(m_ElapsedTime / Define.TIME_ATTACK_START, 1.0f);
            float targetRot   = (m_ScaleFactor > 0) ? 30.0f * ratio : 150.0f * ratio;
            float targetScale = 1.0f + 1.0f * ratio;
            m_RootRef.transform.rotation   = Quaternion.AngleAxis(targetRot, Vector3.up);
            m_RootRef.transform.localScale = new Vector3(m_ScaleFactor * targetScale, targetScale, targetScale);
            m_PositionRef.z = -5.0f * ratio;
            m_RootRef.transform.position = m_PositionRef;

            ChangeAnimationState(AnimationState.Attack_DoAttack, Define.TIME_ATTACK_START);
            break;

        case AnimationState.Attack_DoAttack:
            float attackRatio = Mathf.Min(m_ElapsedTime / Define.TIME_ATTACK_DO, 1.0f);
            m_PositionRef.x = m_ScaleFactor * attackRatio * 1.0f;
            m_RootRef.transform.position = m_PositionRef;

            ChangeAnimationState(AnimationState.Attack_End, Define.TIME_ATTACK_DO);
            break;

        case AnimationState.Attack_End:
            ChangeAnimationState(AnimationState.Idle, Define.TIME_ATTACK_END, true);
            break;

        case AnimationState.Hitted:
            m_PositionRef    = m_TransformRef.m_PositionRef;
            m_PositionRef.x += 2.0f * Random.Range(-1.0f, 1.0f);
            m_PositionRef.y += 2.0f * Random.Range(-1.0f, 1.0f);
            m_RootRef.transform.position = m_PositionRef;
            ChangeAnimationState(AnimationState.Hitted_BreakBone, Define.TIME_SKIPED);
            break;

        case AnimationState.Hitted_BreakBone:
            // bone animation
            Character selfRef = GetComponent <Character>();
            GlobalSingleton.GetFxManager().DoBreakBoneAnimation(ref selfRef);
            ChangeAnimationState(AnimationState.Hitted_Straight, Define.TIME_SKIPED);
            break;

        case AnimationState.Hitted_Straight:
            m_PositionRef    = m_TransformRef.m_PositionRef;
            m_PositionRef.x += 2.0f * Random.Range(-1.0f, 1.0f);
            m_PositionRef.y += 2.0f * Random.Range(-1.0f, 1.0f);
            m_RootRef.transform.position = m_PositionRef;
            ChangeAnimationState(AnimationState.Idle, Define.TIME_HITTED, true);
            break;

        case AnimationState.Defend:
            GlobalSingleton.GetFxManager().DoDefendAnimation();
            ChangeAnimationState(AnimationState.Idle, Define.TIME_DEFEND, true);
            break;
        }
    }