public static void OnGateEnter(GameObject player, GameObject gateObject, bool fromMessage) { if (!fromMessage && !NetworkManagerCustom.IsServer) { return; } Vector2Int localPosition = GateInfo.RoomObjectToLocalPosition(gateObject.transform.localPosition); Vector2Int nextCoord = GateInfo.LocalPositionToVector(localPosition) + currentRoomCoords + (localPosition.x == 1 ? new Vector2Int(0, currentRoom.GetComponent <Room>().Size.y - 1) : localPosition.x == 3 ? new Vector2Int(currentRoom.GetComponent <Room>().Size.x - 1, 0) : Vector2Int.zero); bool buffer = spawnedRooms != null && nextCoord.x >= 0 && nextCoord.x < spawnedRooms.GetLength(0) && nextCoord.y >= 0 && nextCoord.y < spawnedRooms.GetLength(1); if (buffer) { Vector3 toPlayerCoords = localPosition.x == 0 ? new Vector3(0, -85f) : localPosition.x == 1 ? new Vector3(0, 85f) : localPosition.x == 2 ? new Vector3(-45f, 0) : new Vector3(45f, 0); player.transform.position += toPlayerCoords; if (localPosition.x == 1) { player.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 15000f)); } } ApplyActiveRooms(); if (buffer && player.GetComponent <NetworkIdentity>().isLocalPlayer) { SetCurrentRoom(nextCoord); } if (!fromMessage && (!NetworkManagerCustom.IsServer || !player.GetComponent <NetworkIdentity>().isLocalPlayer)) { MessageManager.GateEnterClientMessage.SendToClient(player.GetComponent <NetworkIdentity>().connectionToClient, new StringMessage(localPosition.x + ";" + localPosition.y)); } }
private static GameObject SpawnRoom(RoomLoader.Room room, RoomInfo position, Transform parent, bool onServer) { GameObject spawnedRoom = RoomLoader.SpawnRoom(room, new Vector3(position.Position.x * 495, position.Position.y * 277, 0), onServer); spawnedRoom.GetComponent <Room>().Position = position.Position; if (NetworkManagerCustom.IsServer && SerializationManager.World != null && SerializationManager.World.Objects[position.Position.x, position.Position.y] != null) { spawnedRoom.GetComponent <Room>().Initialized = true; } spawnedRoom.transform.parent = parent; List <GameObject> gates = Utils.GetComponentsRecursive <GateObject>(spawnedRoom).ConvertAll(x => x.gameObject); gates.ForEach(x => x.transform.Find("trigger").GetComponent <GateTrigger>().GetEventSystem <GateTrigger.EnterGateEvent>() .SubcribeEvent(y => OnGateEnter(y.Player, y.Sender, false))); foreach (GameObject gateObject in gates) { Vector2Int localPosition = GateInfo.RoomObjectToLocalPosition(gateObject.transform.localPosition); if (gateObject.GetComponent <GateObject>().gateType == 0) { gateObject.GetComponent <GateObject>().Enable = position.Gates.Exists(x => x.LocalPosition == localPosition); } } for (int x = 0; x < position.Size.x; x++) { for (int y = 0; y < position.Size.y; y++) { spawnedRooms[x + position.Position.x, y + position.Position.y] = spawnedRoom; } } spawnedRoom.SetActive(false); return(spawnedRoom); }
public static bool IsRoomValid(RoomLoader.Room room, RoomInfo position) { if (room != null && room.size == position.Size) { List <RoomObject> gatesObject = room.objects.Where(x => x.prefabName.Contains("Gate")).ToList(); foreach (RoomObject gateObject in gatesObject) { Vector2Int localPosition = GateInfo.RoomObjectToLocalPosition(gateObject.coords); int type = int.Parse(gateObject.data[0]); if (type == 1 && !position.Gates.Exists(x => x.LocalPosition == localPosition)) { return(false); } if (type == 2 && position.Gates.Exists(x => x.LocalPosition == localPosition)) { return(false); } } return(true); } return(false); }