Пример #1
0
        // public method

        #endregion "public method"

        #region "private method"
        // private method

        private void _StartPrefabAction(Vector3 pos)
        {
            GameObject action = (GameObject)GameObject.Instantiate(m_PrefabAction, pos, Quaternion.identity);

            action.name = "KillingBlow";

            // prepare actors and start the cutscene
            CutsceneController cc = action.GetComponent <CutsceneController>();

            GameObject internal_Player = action.transform.Find("Player").gameObject;
            GameObject internal_Enemey = action.transform.Find("Enemy").gameObject;

            var swaplist = CutsceneController.GetSwapObjList(cc);

            swaplist.Clear();
            swaplist.Add(new CutsceneController.SwapObjPair(m_Player.gameObject, internal_Player, false, true));
            swaplist.Add(new CutsceneController.SwapObjPair(m_Enemy.gameObject, internal_Enemey, false, false));
            CutsceneController.StartCC(cc);

            cc.OnPlayStopped += _OnKillingBlowEnd;
        }
Пример #2
0
        private void _OnParryCCStop(CutsceneController cc)
        {
            cc.OnPlayStopped -= _OnParryCCStop;
            var swaplst = CutsceneController.GetSwapObjList(cc);

            foreach (var pr in swaplst)
            {
                if (pr.m_ExternalGO.name == "Enemy")
                {
                    // apply root motion
                    GameObject atkGO = pr.m_ExternalGO;
                    Transform  tr    = atkGO.transform;
                    Transform  hips  = tr.Find("Hips");

                    Vector3 pos = hips.position;
                    pos.y       = tr.position.y;
                    tr.position = pos;

                    pos   = hips.localPosition;
                    pos.x = pos.z = 0f;
                    hips.localPosition = pos;

                    Vector3 angles = hips.eulerAngles;
                    angles.x       = angles.z = 0;
                    tr.eulerAngles = angles;

                    // jump to LIEDOWN_STATE
                    Animator anim = tr.GetComponent <Animator>();
                    anim.Play(LIEDOWN_STATE);

                    // apply dmg
                    CCDemo3_EnemyProp prop = atkGO.GetComponent <CCDemo3_EnemyProp>();
                    prop.HP -= prop.AtkPwr;
                    if (prop.HP <= 0)
                    {
                        _OnEnemyDie(prop.gameObject);
                    }
                }
                else if (pr.m_ExternalGO.name == "Player")
                {
                    EnableParry = false;

                    // apply root motion
                    Transform tr   = m_PlayerGO.transform;
                    Transform hips = tr.Find("Hips");

                    Vector3 pos = hips.position;
                    pos.y       = tr.position.y;
                    tr.position = pos;
                    Dbg.Log("enemy pos: {0}", pos);

                    pos   = hips.localPosition;
                    pos.x = pos.z = 0f;
                    hips.localPosition = pos;

                    Vector3 angles = hips.eulerAngles;
                    angles.x       = angles.z = 0;
                    tr.eulerAngles = angles;

                    // jump to idle state
                    m_PlayerAnimator.Play(IDLE_STATE, 0, 0);
                }
            }
        }
Пример #3
0
        public void OnHit(GameObject hit, GameObject beHit)
        {
            GameObject atkGO = _GetCollisionOwner(hit);
            GameObject defGO = _GetCollisionOwner(beHit);

            if (defGO == m_PlayerGO) //player gets hit by enemy
            {
                if (atkGO == m_PlayerGO)
                { //this is possible if the action make his own hand touches his own body...
                    return;
                }
                if (!IsAtking(atkGO))
                { //the accident collision should not be counted
                    return;
                }
                if (IsUnderAtk(defGO))
                {
                    return; //if already be hit, don't add new
                }

                if (EnableParry)
                {
                    if (!m_ParryCC.gameObject.activeSelf)
                    {
                        Transform cctr     = m_ParryCC.transform;
                        Transform playerTr = m_PlayerGO.transform;

                        m_ParryCC.gameObject.SetActive(true);
                        var swaplst = CutsceneController.GetSwapObjList(m_ParryCC);
                        swaplst.Add(new CutsceneController.SwapObjPair(defGO, cctr.Find("Player").gameObject));
                        swaplst.Add(new CutsceneController.SwapObjPair(atkGO, cctr.Find("Enemy").gameObject));

                        Vector3 ccPos = playerTr.position;
                        ccPos.y       = cctr.position.y;
                        cctr.position = ccPos;

                        Vector3 fdir = atkGO.transform.position - playerTr.position;
                        fdir.y       = 0;
                        cctr.forward = fdir;
                        CutsceneController.StartCC(m_ParryCC);
                        m_ParryCC.OnPlayStopped += _OnParryCCStop;
                    }
                }
                else
                {
                    CCDemo3_EnemyProp prop     = atkGO.GetComponent <CCDemo3_EnemyProp>();
                    Transform         playerTr = m_PlayerGO.transform;
                    Vector3           atkPos   = atkGO.transform.position;
                    atkPos.y         = playerTr.position.y;
                    playerTr.forward = atkPos - playerTr.position;

                    m_HP = Mathf.Clamp(m_HP - prop.AtkPwr, 0, int.MaxValue);
                    Dbg.Log("player under atk, hp = {0}", m_HP);

                    if (m_HP <= 0)
                    {
                        m_PlayerAnimator.SetTrigger(HEAVY_PUNCHED_HASH);
                        _OnPlayerDie();
                    }
                    else
                    {
                        m_PlayerAnimator.SetTrigger(HEAVY_PUNCHED_HASH);
                    }
                }
            }
            else //player hit the enemy
            {
                if (atkGO != m_PlayerGO)
                { //two enemies collide...
                    return;
                }
                if (!IsAtking(atkGO))
                {
                    return;
                }
                if (IsUnderAtk(defGO))
                {
                    return; //if already be hit, don't add new
                }

                int               atkStateHash  = CCDemo3_Helper.GetAnimatorStateHash(m_PlayerAnimator.GetCurrentAnimatorStateInfo(0));
                Transform         defTr         = defGO.transform;
                CCDemo3_EnemyProp prop          = defGO.GetComponent <CCDemo3_EnemyProp>();
                Animator          enemyAnimator = defTr.GetComponent <Animator>();

                if (atkStateHash == LIGHT_PUNCH_STATE)
                {
                    Vector3 dir = atkGO.transform.position - defTr.position;
                    dir.y         = 0;
                    defTr.forward = dir;
                    prop.HP      -= m_LightPunchPwr;
                    enemyAnimator.SetTrigger(LIGHT_PUNCHED_HASH);
                    Dbg.Log("Enemy {0} under atk, hp = {1}", defGO.name, prop.HP);
                }
                else if (atkStateHash == HEAVY_PUNCH_STATE)
                {
                    Vector3 dir = atkGO.transform.position - defTr.position;
                    dir.y         = 0;
                    defTr.forward = dir;
                    prop.HP      -= m_HeavyPunchPwr;
                    enemyAnimator.SetTrigger(HEAVY_PUNCHED_HASH);
                    Dbg.Log("Enemy {0} under atk, hp = {1}", defGO.name, prop.HP);
                }

                if (prop.HP <= 0)
                {
                    _OnEnemyDie(prop.gameObject);
                }
            }
        }