public void ReceiveData() { //** 2언어(서로 다른 언어 ex. Java, C# ) 통신간 데이터 수신 방법 **/ // 1.바이트 최대 사이즈 정의 // 1).ex.byte[] rcvLenBytes = new byte[1024]; // 2).clientSocket.Receive(rcvLenBytes); // 2.전달받은 바이트 데이터 인코딩 // 1) int rcvLen = System.BitConverter.ToInt32(rcvLenBytes, 0); // 2) byte[] rcvBytes = new byte[rcvLen]; // 3) String rcv = System.Text.Encoding.ASCII.GetString(rcvBytes); // 4) 출력 Debug.Log(rev); // Receiving try { while (true) { // 소켓이 비어있다면 종료 if (clientSocket == null) { clientSocket.Close(); clientReceiveThread.Interrupt(); Debug.Log("Socket Exception"); } byte[] rcvLenBytes = new byte[4]; clientSocket.Receive(rcvLenBytes); int rcvLen = System.BitConverter.ToInt32(rcvLenBytes, 0); byte[] rcvBytes = new byte[rcvLen]; clientSocket.Receive(rcvBytes); rcv = System.Text.Encoding.ASCII.GetString(rcvBytes); String[] received = rcv.Split(','); rcvId = received[0]; Debug.Log("Client received: " + rcv); for (int i = 0; i < received.Length; i++) { if (received[i].Equals("MoveFlag")) { MoveFlag = true; float x = float.Parse(received[1]); float y = float.Parse(received[2]); JoyVec = new Vector3(x, y, 0); remoteFSM.ChangeState(RemoteFSM.State.Idle, RemoteAni.ANI_WALK); Debug.Log("MoveFlag:" + MoveFlag); } else if (received[i].Equals("MoveStop")) { MoveFlag = false; Debug.Log("MoveFlag:" + MoveFlag); } if (received[0].Equals(myId)) { Debug.Log("내 아이디 맞아 ~ : " + received[i]); // 받은 데이터가 내 아이디와 같다면 내 캐릭터에게 데이터를 넣어 컨트롤한다. //if (received[i].Equals("MoveStop")) //{ // joy.MoveFlag = false; // //playerAni.ChangeAni( PlayerAni.ANI_IDLE ); // Debug.Log("플레이어 캐릭터 이동 정지"); //} if (received[i].Equals("TrackingStart")) { playerFsm2.rcvMyid = received[0]; playerFsm2.rcvChaseStart = received[1]; playerFsm2.rcvChaseTarget = received[2]; Debug.Log("추적 시작 한다 ~"); Debug.Log("Network Script Received to Player TrackingStart data value : " + received[1]); Debug.Log("Network Script Received to Player TrackingTarget data value : " + received[2]); Debug.Log("추적 시작 i value : " + received[2]); if (received[2].Equals("remotePlayer")) { Debug.Log("네트워크 스크립트 추적 타겟 리모트 플레이어"); playerFsm2.chaseTarget = "remotePlayer"; Debug.Log("1"); attackFlag = "remotePlayer"; attackControl = true; Debug.Log("네트워크 스크립트 플레이어가 리모트 플레이어를 추적 :" + playerFsm2.chaseTarget); } else if (received[2].Equals("redTower")) { Debug.Log("타워 추적"); playerFsm2.chaseTarget = "redTower"; attackFlag = "redTower"; attackControl = true; Debug.Log("IdleState redTower chaseTarget to value : " + playerFsm2.chaseTarget); } } } else { // 데이터를 보낸 아이디가 내 아이디가 아니라면 상대 캐릭터를 컨트롤 한다. Debug.Log("내 아이디 아니야 ~ : " + received[0]); //if (received[i].Equals("MoveStop")) //{ // MoveFlag = false; //} if (received[i].Equals("TrackingStart")) { remoteFSM.rcvMyid = received[0]; remoteFSM.rcvChaseStart = received[1]; remoteFSM.rcvChaseTarget = received[2]; Debug.Log("리모트플레이어 추적 시작 ~"); Debug.Log("Network Script Received to remotePlayer TrackingStart data value : " + received[1]); Debug.Log("Network Script Received to remotePlayer TrackingTarget data value : " + received[2]); } if (received[i].Equals("MonsterTrackingStart")) { monsterFSM.monsterChasePlayer = received[2]; Debug.Log("몬스터 동기화 추적 시작 ~"); } //if(received[i].Equals("SkillOne")) //{ //skillOne.receivedSkileOne = true; //skillcheck = "SkillOne"; ////remoteMoveSpeed = 8f; //Debug.Log("received value : "+skillOne.receivedSkileOne); //} //if (received[i].Equals("SkillStop")) //{ // skillOne.receivedSkileOne = false; //skillcheck = "SkillStop"; //Debug.Log("received value : " + skillOne.receivedSkileOne); //} } } } // clientSocket.Close(); } catch (System.ObjectDisposedException e) { Debug.Log("Socket Exception"); singleton.clientReceiveThread.Interrupt(); singleton.clientReceiveThread.Abort(); singleton.clientSocket.Close(); } }
// Update is called once per frame void Update() { //if(playerParams == null) //{ // playerParams = GameObject.FindWithTag("Player").GetComponent<PlayerParams>(); //} if (playerParams.isDead == true) { countDown -= Time.deltaTime; greenRespawnTaiLung.SetActive(true); greenRespawnCoundDown.text = "" + (int)countDown; Debug.Log("리스폰 스크립티 플레이어 isDead value: " + playerParams.isDead); if (countDown < 0 && playerParams.isDead == true) { greenRespawnTaiLung.SetActive(false); Debug.Log("Player Base: " + myBase); if (myBase.Equals("1")) { // 내가 선택한 캐릭터 생성 GameObject myCharacter = Resources.Load(myCharacterName) as GameObject; Vector3 pos = new Vector3(45.02f, 60.3f, 99.59f); characterQuaternion.eulerAngles = new Vector3(0, 100, 0); myCharacter.transform.rotation = characterQuaternion; Instantiate(myCharacter, pos, myCharacter.transform.rotation).name = network.myId; playerParams = GameObject.FindWithTag("Player").GetComponent <PlayerParams>(); playerParams.isDead = false; Debug.Log("리스폰 스크립트 블루 진영 Log 1"); playerParams = GameObject.FindWithTag("Player").GetComponent <PlayerParams>(); Debug.Log("리스폰 스크립트 블루 진영 Log 2"); joy.Player = GameObject.FindWithTag("Player").GetComponent <Transform>(); Debug.Log("리스폰 스크립트 블루 진영 Log 3"); joy.anim = GameObject.FindWithTag("Player").GetComponent <Animator>(); Debug.Log("리스폰 스크립트 블루 진영 Log 4"); joy.myAni = GameObject.FindWithTag("Player").GetComponent <PlayerAni>(); Debug.Log("리스폰 스크립트 블루 진영 Log 5"); //joy.Stick = GameObject.Find("JoyStick").GetComponent<Transform>(); joy.playerFsm2 = GameObject.FindWithTag("Player").GetComponent <PlayerFSM2>(); Debug.Log("리스폰 스크립트 블루 진영 Log 6"); //playerAni.anim = GameObject.FindWithTag("Player").GetComponent<Animator>(); Debug.Log("리스폰 스크립트 블루 진영 Log 7"); network.playerFsm2 = GameObject.FindWithTag("Player").GetComponent <PlayerFSM2>(); network.player = GameObject.FindWithTag("Player").transform; playerFSM2.remotePlayer = GameObject.FindWithTag("RemotePlayer").transform; playerFSM2.ChangeState(PlayerFSM2.State.Idle, PlayerAni.ANI_IDLE); Debug.Log("1 진영 리스폰 완료"); } else { GameObject myCharacter = Resources.Load(myCharacterName) as GameObject; Vector3 pos = new Vector3(254.85f, 60.3f, 100.41f); characterQuaternion.eulerAngles = new Vector3(0, -110, 0); myCharacter.transform.rotation = characterQuaternion; Instantiate(myCharacter, pos, myCharacter.transform.rotation).name = network.myId; playerParams = GameObject.FindWithTag("Player").GetComponent <PlayerParams>(); playerParams.isDead = false; Debug.Log("리스폰 스크립트 레드 진영 Log 1"); joy.Player = GameObject.FindWithTag("Player").GetComponent <Transform>(); Debug.Log("리스폰 스크립트 레드 진영 Log 2"); joy.anim = GameObject.FindWithTag("Player").GetComponent <Animator>(); Debug.Log("리스폰 스크립트 레드 진영 Log 3"); joy.myAni = GameObject.FindWithTag("Player").GetComponent <PlayerAni>(); Debug.Log("리스폰 스크립트 레드 진영 Log 4"); //joy.Stick = GameObject.Find("JoyStick").GetComponent<Transform>(); joy.playerFsm2 = GameObject.FindWithTag("Player").GetComponent <PlayerFSM2>(); Debug.Log("리스폰 스크립트 레드 진영 Log 5"); //playerAni.anim = GameObject.FindWithTag("Player").GetComponent<Animator>(); Debug.Log("리스폰 스크립트 레드 진영 Log 6"); network.playerFsm2 = GameObject.FindWithTag("Player").GetComponent <PlayerFSM2>(); Debug.Log("리스폰 스크립트 레드 진영 Log 7"); network.player = GameObject.FindWithTag("Player").transform; playerFSM2.remotePlayer = GameObject.FindWithTag("RemotePlayer").transform; playerFSM2.ChangeState(PlayerFSM2.State.Idle, PlayerAni.ANI_IDLE); Debug.Log("2 진영 리스폰 완료"); } } } else if (remoteParams.isDead == true) { countDown -= Time.deltaTime; redRespawnTiaLung.SetActive(true); redRespawnCoundDown.text = "" + (int)countDown; if (countDown < 0 && remoteParams.isDead == true) { redRespawnTiaLung.SetActive(false); Debug.Log("RemotePlayer Base: " + myBase); if (myBase.Equals("1")) { GameObject YouerCharacter = Resources.Load("RemoteTaiLung") as GameObject; Vector3 remotePos = new Vector3(254.85f, 60.3f, 100.41f); remoteQuaternion.eulerAngles = new Vector3(0, -110, 0); YouerCharacter.transform.rotation = remoteQuaternion; Instantiate(YouerCharacter, remotePos, YouerCharacter.transform.rotation).tag = "RemotePlayer"; GameObject.FindWithTag("RemotePlayer").name = "RemotePlayer"; remoteParams = GameObject.FindWithTag("RemotePlayer").GetComponent <RemoteParams>(); remoteParams.isDead = false; network.player2 = GameObject.FindWithTag("RemotePlayer").GetComponent <Transform>(); //network.playerFsm2 = GameObject.FindWithTag("RemotePlayer").GetComponent<PlayerFSM2>(); remoteAni.anim = GameObject.FindWithTag("RemotePlayer").GetComponent <Animator>(); playerFSM2.remotePlayer = GameObject.FindWithTag("RemotePlayer").transform; network.remoteFSM = GameObject.FindWithTag("RemotePlayer").GetComponent <RemoteFSM>(); remoteFSM.ChangeState(RemoteFSM.State.Idle, RemoteAni.ANI_IDLE); } else { // 내가 선택한 캐릭터 생성 GameObject YouerCharacter = Resources.Load("RemoteTaiLung") as GameObject; Vector3 remotePos = new Vector3(45.02f, 60.3f, 99.59f); remoteQuaternion.eulerAngles = new Vector3(0, 100, 0); YouerCharacter.transform.rotation = remoteQuaternion; Instantiate(YouerCharacter, remotePos, YouerCharacter.transform.rotation).tag = "RemotePlayer"; GameObject.FindWithTag("RemotePlayer").name = "RemoteTaiLung"; remoteParams = GameObject.FindWithTag("RemotePlayer").GetComponent <RemoteParams>(); remoteParams.isDead = false; playerFSM2.remotePlayer = GameObject.FindWithTag("RemotePlayer").transform; network.player2 = GameObject.FindWithTag("RemotePlayer").GetComponent <Transform>(); //network.playerFsm2 = GameObject.FindWithTag("RemotePlayer").GetComponent<PlayerFSM2>(); remoteAni.anim = GameObject.FindWithTag("RemotePlayer").GetComponent <Animator>(); network.remoteFSM = GameObject.FindWithTag("RemotePlayer").GetComponent <RemoteFSM>(); remoteFSM.ChangeState(RemoteFSM.State.Idle, RemoteAni.ANI_IDLE); } } } }