示例#1
0
    // Use this for initialization
    void Awake()
    {
        m_TrInfo        = GetComponent <Transform>();
        m_Animator      = GetComponent <Animator>();
        m_PunchCollider = GetComponentInChildren <SphereCollider>();

        m_Animator.speed = 2.0f;

        m_PhotonView = GetComponent <PhotonView>();
        m_PhotonView.synchronization       = ViewSynchronization.UnreliableOnChange;
        m_PhotonView.ObservedComponents[0] = this;
        m_NaviMesh = GetComponent <NavMeshAgent>();

        source = GetComponent <AudioSource>();

        if (m_PhotonView.isMine)
        {
            Camera.main.GetComponent <CameraCtrl>().m_TrTargetInfo = m_TrInfo;
            m_PunchCollider.tag = "PLAYER_ATTACK";

            if (PhotonNetwork.player.GetTeam() == PunTeams.Team.red)
            {
                m_PlayerTeam = PLAYER_TEAM.PLAYER_TEAM_RED;
            }
            else
            {
                m_PlayerTeam = PLAYER_TEAM.PLAYER_TEAM_BLUE;
            }

            //GameObject.FindGameObjectWithTag("RUN_BTN").GetComponent<RunBtnCtrl>().m_PlayerCtrl = this;
        }
        else
        {
            m_PunchCollider.tag = "NET_PLAYER_ATTACK";
        }

        m_Animator.SetBool("IsAttack", false);

        m_PunchCollider.isTrigger = false;

        m_CurrPos           = m_TrInfo.position;
        m_CurrRot           = m_TrInfo.rotation;
        m_NetworkPlayerTeam = PLAYER_TEAM.PLAYER_TEAM_END;

        m_PlayerState = PLAYER_STATE.PLAYER_IDLE;

        transform.FindChild("Canvas").gameObject.SetActive(false);  //같은 팀의 위에 뜨도록 만들자..
    }
示例#2
0
 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(m_TrInfo.position);
         stream.SendNext(m_TrInfo.rotation);
         stream.SendNext(m_PlayerState);
         stream.SendNext(m_PlayerTeam);
         //stream.SendNext(m_fTime);
     }
     else
     {
         m_CurrPos           = (Vector3)stream.ReceiveNext();
         m_CurrRot           = (Quaternion)stream.ReceiveNext();
         m_CurrState         = (PLAYER_STATE)stream.ReceiveNext();
         m_NetworkPlayerTeam = (PLAYER_TEAM)stream.ReceiveNext();
         //m_fTime = (float)stream.ReceiveNext();
         //m_PlayerTeam = m_NetworkPlayerTeam;
     }
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (m_bDie)
        {
            return;
        }

        if (m_PhotonView.isMine)
        {
            if (m_bFindBtn == false)
            {
                GameObject pGameObject = GameObject.FindGameObjectWithTag("BTN_MGR");

                if (pGameObject != null)
                {
                    pGameObject.GetComponent <BtnCtrl>().m_pPlayerCtrl = this;
                    m_bFindBtn = true;

                    Debug.Log("BtnMgr_Link");
                }
            }

            if (m_bFindInput == false)
            {
                GameObject pGameobject = GameObject.FindGameObjectWithTag("JOY_STICK");

                if (pGameobject != null)
                {
                    m_pInput = pGameobject.GetComponent <Controller>();

                    Debug.Log("인풋 연결!");

                    m_bFindInput = true;
                }
            }

            if (m_pInput != null)
            {
                m_vDir = m_pInput.GetDir();
            }

            /*
             * if (Application.platform != RuntimePlatform.Android)
             * {
             *  m_vDir.x = Input.GetAxis("Horizontal");
             *  m_vDir.y = Input.GetAxis("Vertical");
             * }
             */

            if (m_vDir.y != 0.0f)
            {
                PlayerMove();
            }
            else if (m_PlayerState != PLAYER_STATE.PLAYER_ATTACK)
            {
                m_PlayerState = PLAYER_STATE.PLAYER_IDLE;

                m_NaviMesh.Stop();
            }

            /*
             * if (m_vDir.x != 0.0f)
             * {
             *  m_TrInfo.Rotate(Vector3.up * Time.deltaTime * m_fRotSpeed * m_vDir.x);
             * }
             */
        }
        else
        {
            Vector3 vPos = m_TrInfo.position;

            m_TrInfo.position = Vector3.Lerp(m_TrInfo.position, m_CurrPos, Time.deltaTime * 3.0f);
            m_TrInfo.rotation = Quaternion.Slerp(m_TrInfo.rotation, m_CurrRot, Time.deltaTime * 3.0f);

            //대략 0.2초마다 다음위치를 받는다..

            //어짜피 네비메쉬를 탄 위치를 받기 때문에 isMine인 것만 처리를 해준다면 여기는 딱히 처리를 하지 않아도 괜찮다.

            m_PlayerState = m_CurrState;

            m_PlayerTeam = m_NetworkPlayerTeam;

            if (m_PlayerTeam == PLAYER_TEAM.PLAYER_TEAM_RED && PhotonNetwork.player.GetTeam() == PunTeams.Team.red)
            {
                transform.FindChild("Canvas").gameObject.SetActive(true);
            }
            else if (m_PlayerTeam == PLAYER_TEAM.PLAYER_TEAM_BLUE && PhotonNetwork.player.GetTeam() == PunTeams.Team.blue)
            {
                transform.FindChild("Canvas").gameObject.SetActive(true);
            }
        }

        switch (m_PlayerState)
        {
        case PLAYER_STATE.PLAYER_IDLE:

            m_Animator.SetBool("IsWalk", false);
            m_Animator.SetBool("IsRun", false);
            m_Animator.SetBool("IsAttack", false);
            m_PunchCollider.isTrigger = false;
            m_NaviMesh.Stop();

            break;

        case PLAYER_STATE.PLAYER_WALK:

            m_Animator.SetBool("IsWalk", true);
            m_Animator.SetBool("IsRun", false);
            m_Animator.SetBool("IsAttack", false);
            m_PunchCollider.isTrigger = false;
            m_NaviMesh.Resume();

            break;

        case PLAYER_STATE.PLAYER_RUN:

            m_Animator.SetBool("IsWalk", false);
            m_Animator.SetBool("IsRun", true);
            m_Animator.SetBool("IsAttack", false);
            m_PunchCollider.isTrigger = false;
            m_NaviMesh.Resume();

            break;

        case PLAYER_STATE.PLAYER_ATTACK:

            m_Animator.SetBool("IsWalk", false);
            m_Animator.SetBool("IsRun", false);
            m_Animator.SetBool("IsAttack", true);
            m_PunchCollider.isTrigger = true;
            m_NaviMesh.Stop();

            break;
        }

        if (m_Animator.GetBool("IsAttack"))
        {
            float m_fTime = m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime % 2.0f;

            //Debug.Log(m_fTime.ToString());

            if (m_fTime >= 0.8f)
            {
                //Debug.Log("초기화");

                m_PlayerState = PLAYER_STATE.PLAYER_IDLE;

                m_Animator.SetBool("IsWalk", false);
                m_Animator.SetBool("IsRun", false);
                m_Animator.SetBool("IsAttack", false);
                m_PunchCollider.isTrigger = false;

                m_NaviMesh.Stop();
            }
        }
    }