public static void RecieveBoatsFromServer(Packet packet) { Debug.Log("Recieving Boats"); int boatCount = packet.ReadInt(); for (int i = 1; i <= boatCount; i++) { int id = packet.ReadInt(); Vector3 pos = packet.ReadVector3(); Quaternion rot = packet.ReadQuaternion(); Boat boat = GameObject.Instantiate <Boat>(instance.boatPrefab, pos, rot); boat.Init(id); int boatEntityTypeCount = packet.ReadInt(); for (int ii = 1; ii <= boatEntityTypeCount; ii++) { BoatEntityType boatEntityType = (BoatEntityType)packet.ReadInt(); int entityOfTypeCount = packet.ReadInt(); for (int iii = 1; iii <= entityOfTypeCount; iii++) { int entiyId = packet.ReadInt(); Vector3 localPosition = packet.ReadVector3(); Quaternion localRotation = packet.ReadQuaternion(); Vector3 localScale = packet.ReadVector3(); BoatEntity entity = Instantiate <BoatEntity>(BoatEntityByType[boatEntityType], boat.transform); entity.id = entiyId; entity.transform.localPosition = localPosition; entity.transform.localRotation = localRotation; entity.transform.localScale = localScale; entity.ReadDataFromPacket(packet); boat.boatEntitiesByType[boatEntityType][entity.id] = entity; } } Boats.Add(boat.id, boat); } }
public static void HandleBoatTransformUpdate(Packet packet) { int id = packet.ReadInt(); Vector3 pos = packet.ReadVector3(); Quaternion rot = packet.ReadQuaternion(); if (!BoatManager.Boats.ContainsKey(id)) { return; } Boat boat = BoatManager.Boats[id]; boat.TargetPosition = pos; boat.transform.rotation = rot; int boatEntityTypeCount = packet.ReadInt(); for (int ii = 1; ii <= boatEntityTypeCount; ii++) { BoatEntityType boatEntityType = (BoatEntityType)packet.ReadInt(); int entityOfTypeCount = packet.ReadInt(); for (int iii = 1; iii <= entityOfTypeCount; iii++) { int entiyyId = packet.ReadInt(); Vector3 localPosition = packet.ReadVector3(); Quaternion localRotation = packet.ReadQuaternion(); Vector3 localScale = packet.ReadVector3(); BoatEntity entity = boat.boatEntitiesByType[boatEntityType][entiyyId]; entity.transform.localPosition = localPosition; entity.transform.localRotation = localRotation; entity.transform.localScale = localScale; entity.ReadDataFromPacket(packet); } } }