public override IEnumerator OnReceive(Session session, Gamnet.Packet packet) { Bar bar = session.bar; Room room = session.room; { Packet.MsgCliSvr_SyncBar_Ntf ntf = packet.Deserialize <Packet.MsgCliSvr_SyncBar_Ntf>(); bar.destination = ntf.destination; } { Packet.MsgSvrCli_SyncBar_Ntf ntf = new Packet.MsgSvrCli_SyncBar_Ntf(); ntf.objectId = bar.id; ntf.destination = bar.destination; foreach (Session s in room.sessions) { if (session == s) { continue; } s.Send(ntf); } } yield break; }
private void Update() { Gamnet.Session.EventLoop.Update(); deltaTime += Time.deltaTime; while (deltaTime >= Time.fixedDeltaTime) { deltaTime -= Time.fixedDeltaTime; physicsScene.Simulate(Time.fixedDeltaTime); } if (Room.State.Ready == room.state) { if (true == Input.GetMouseButtonUp(MOUSE_BUTTON_LEFT)) { room.state = Room.State.Play; ball.transform.SetParent(room.transform); ball.rigidBody.useGravity = false; Packet.MsgCliSvr_Start_Ntf ntf = new Packet.MsgCliSvr_Start_Ntf(); Network.Send(ntf); } } // https://gamedevbeginner.com/how-to-convert-the-mouse-position-to-world-space-in-unity-2d-3d/#screen_to_world_3d if (Room.State.Init != room.state) { if (true == Input.GetMouseButton(MOUSE_BUTTON_LEFT)) { /* * Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit hit; * if (true == Physics.Raycast(ray, out hit, Mathf.Infinity)) * { * Bar bar = hit.transform.GetComponent<Bar>(); * if (null != bar) * { * isTouched = true; * } * } */ float distance; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (true == backPlane.Raycast(ray, out distance)) { Vector3 worldPosition = ray.GetPoint(distance); // 월드 좌표를 로컬 좌표로 이동 bar.destination = room.transform.InverseTransformPoint(worldPosition); Packet.MsgCliSvr_SyncBar_Ntf ntf = new Packet.MsgCliSvr_SyncBar_Ntf(); ntf.destination = bar.destination; Network.Send(ntf); } } //bar.rigidBody.velocity = Vector3.zero; } }