public void MoveByJoystick(float horizontal, float vertical, bool pressed) { if (Singleton <RoleManager> .Instance.mainCamera == null) { return; } if (!pressed) { if (this.moveType == MoveController.MoveType.Joystick) { this.moveType = MoveController.MoveType.None; this._self.move.StopPath(); PositionSync.SyncSelfPosition(); } return; } Vector3 point = new Vector3(horizontal, 0f, vertical); Vector3 forward = Singleton <RoleManager> .Instance.mainCamera.transform.forward; forward.y = 0f; Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, forward); Vector3 vecDir = rotation * point; if (!vecDir.Equals(Vector3.zero)) { this.moveType = MoveController.MoveType.Joystick; this._self.move.WalkOnDirection(vecDir); } }
public static void PlayerRotation(Packet _packet) { int _id = _packet.ReadInt(); Quaternion _rotation = _packet.ReadQuaternion(); // GameManager.players[_id].transform.rotation = _rotation; PositionSync.SyncRot(_id, _rotation); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Debug.Log("Instance already exists, destroying object!"); Destroy(this); } }
void PositionSync() { if (positionQue.Count == 0) { return; } PositionSync temp = positionQue[0]; int i = 0; bool t = false; while (i < netObjs.Count) { if (netObjs[i].ID == temp.ID) { if (ID != temp.ID) { //netObjs[i].obj.transform.position = Vector3.Lerp(netObjs[i].obj.transform.position, temp.position, 0.5f); //netObj[i].transform.position = temp.position; //netObjs[i].followVec = temp.position; NetObj netObj = netObjs[i]; netObj.followVec = temp.position; netObjs[i] = netObj; } t = true; break; } i++; } if (t == false && ID.Equals(temp.ID) == false) { Debug.Log("Receive new Player"); GameObject tempObj = Instantiate <GameObject>(Resources.Load <GameObject>("NetObj")); NetObj tempNetObj = new NetObj { obj = tempObj, ID = temp.ID, followVec = temp.position }; tempObj.name = temp.ID.ToString() + "_NetObj"; netObjs.Add(tempNetObj); } positionQue.RemoveAt(0); }
private static int SyncSelfPosition(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 0); PositionSync.SyncSelfPosition(); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
private static int Clear(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 1); PositionSync positionSync = (PositionSync)ToLua.CheckObject(L, 1, typeof(PositionSync)); positionSync.Clear(); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
private static int DeleteObjectPosition(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 2); PositionSync positionSync = (PositionSync)ToLua.CheckObject(L, 1, typeof(PositionSync)); string id = ToLua.CheckString(L, 2); positionSync.DeleteObjectPosition(id); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
private static int SetProtoInterval(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 2); PositionSync positionSync = (PositionSync)ToLua.CheckObject(L, 1, typeof(PositionSync)); int protoInterval = (int)LuaDLL.luaL_checknumber(L, 2); positionSync.SetProtoInterval(protoInterval); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
private static int set_positionSync(IntPtr L) { object obj = null; int result; try { obj = ToLua.ToObject(L, 1); EntityCreate entityCreate = (EntityCreate)obj; PositionSync positionSync = (PositionSync)ToLua.CheckUnityObject(L, 2, typeof(PositionSync)); entityCreate.positionSync = positionSync; result = 0; } catch (Exception ex) { result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index positionSync on a nil value"); } return(result); }
private static int get_positionSync(IntPtr L) { object obj = null; int result; try { obj = ToLua.ToObject(L, 1); EntityCreate entityCreate = (EntityCreate)obj; PositionSync positionSync = entityCreate.positionSync; ToLua.Push(L, positionSync); result = 1; } catch (Exception ex) { result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index positionSync on a nil value"); } return(result); }
public override void Update() { stateInfo = animator.GetCurrentAnimatorStateInfo(0); // 需要使用 // Find Player,Run,Shoot timer += Time.deltaTime; if (timer > 2f) { timer = 0; PlayerInfo playerInfo = new PlayerInfo("player", player.position); PlayerInfo enemyInfo = new PlayerInfo("enemy", GameObjectInScene.transform.position); List <PlayerInfo> players = new List <PlayerInfo>(); players.Add(playerInfo); players.Add(enemyInfo); PositionSync.SendPosList(players); if (target != Vector3.up) { // 射击 animator.SetTrigger(animShoot); CoroutineMgr.Instance.StartCoroutine(Attack()); } } }
void ReceivePosition() { byte[] buffer = new byte[1400]; IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint senderRemote = (EndPoint)sender; if (positionSync_socket.Poll(0, SelectMode.SelectRead)) { int recvSize = positionSync_socket.ReceiveFrom(buffer, SocketFlags.None, ref senderRemote); if (recvSize > 0) { GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); PositionSync temp = (PositionSync)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(PositionSync)); gch.Free(); positionSyncs_Que.Add(temp); //Debug.Log("Receive position:" + temp.position); } } state = State.SendMessage; }
public void MoveByKeyboard() { if (UICamera.inputHasFocus) { return; } this.bUpState = (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)); this.bDownState = (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)); this.bLeftState = (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)); this.bRightState = (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)); if (!this.bUpState && !this.bDownState && !this.bLeftState && !this.bRightState) { if (this.moveType == MoveController.MoveType.Keyboard) { this.moveType = MoveController.MoveType.None; this._self.move.StopPath(); PositionSync.SyncSelfPosition(); } return; } if (Camera.main == null) { return; } this.moveType = MoveController.MoveType.Keyboard; Vector3 v = Camera.main.transform.rotation * Vector3.forward; v.y = 0f; v.Normalize(); float y = 0f; if (this.bUpState) { if (this.bLeftState) { y = -45f; } else if (this.bRightState) { y = 45f; } } else if (this.bDownState) { if (this.bLeftState) { y = -135f; } else if (this.bRightState) { y = 135f; } else { y = 180f; } } else if (this.bLeftState) { y = -90f; } else if (this.bRightState) { y = 90f; } Matrix4x4 matrix4x = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0f, y, 0f)), Vector3.one); this._self.move.WalkOnDirection(matrix4x.MultiplyVector(v)); }