示例#1
0
    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);
    }
示例#2
0
 private void Start()
 {
     if (isServer)
     {
         NetworkManagerCustomGUI gui = GameObject.Find("Manager").GetComponent <NetworkManagerCustomGUI>();
         if (gui.StartArguments[0].Equals("new game"))
         {
             seedToGeneration = int.Parse(ServerEvents.singleton.SeedToGenerate);
             seedToSpawn      = int.Parse(ServerEvents.singleton.SeedToSpawn);
             GenerationInfo generation = GetGeneration(seedToGeneration == 0 ? rnd.Next() : seedToGeneration);
             seedToSpawn = seedToSpawn == 0 ? rnd.Next() : seedToSpawn;
             GenerationManager.SpawnGeneration(RoomLoader.loadedRooms, generation, seedToSpawn, false);
             MessageManager.GetGenServerMessage.SendToServer(new EmptyMessage());
             if (GameSettings.SettingVisualizeTestGeneration.Value)
             {
                 GenerationManager.VisualizeGeneration(generation);
             }
         }
         else if (gui.StartArguments[0].Equals("load game"))
         {
             SerializationManager.LoadWorld(gui.StartArguments[1]);
             GenerationInfo generation = GetGeneration(SerializationManager.World.Info.SeedToGenerate);
             GenerationManager.SpawnGeneration(RoomLoader.loadedRooms, generation, SerializationManager.World.Info.SeedToSpawn, false);
             MessageManager.GetGenServerMessage.SendToServer(new EmptyMessage());
             if (GameSettings.SettingVisualizeTestGeneration.Value)
             {
                 GenerationManager.VisualizeGeneration(generation);
             }
         }
         else if (gui.StartArguments[0].Equals("test mode"))
         {
             GenerationManager.SetCurrentRoom(RoomLoader.SpawnRoom(RoomLoader.loadedRooms.Find(x => x.fileName.Equals(GameSettings.SettingTestRoomName.Value)), Vector3.zero, false));
             GenerationManager.InitializeRoom(GenerationManager.currentRoom);
             GameObject player = Instantiate(LocalPlayer);
             Vector3    toPos  = Vector3.zero;
             Transform  parent = GenerationManager.currentRoom.transform.Find("Objects");
             for (int i = 0; i < parent.childCount; i++)
             {
                 if (parent.GetChild(i).name.Contains("playerPosition"))
                 {
                     toPos = parent.GetChild(i).position;
                 }
             }
             player.transform.position = toPos + new Vector3(18, 25);
             if (ServerEvents.singleton.ServerOnlyProfile != null)
             {
                 player.GetComponent <GameProfile>().Deserialize(ServerEvents.singleton.ServerOnlyProfile);
             }
             NetworkServer.AddPlayerForConnection(NetworkServer.connections[0], player, indexController++);
         }
         else if (gui.StartArguments[0].Equals("room editor"))
         {
             RoomLoader.Room room = RoomLoader.LoadRoom(Application.streamingAssetsPath + "/room.json", Encoding.UTF8);
             GenerationManager.SetCurrentRoom(RoomLoader.SpawnRoom(room, Vector3.zero, false));
             RoomLoader.loadedRooms.Add(room);
             GenerationManager.InitializeRoom(GenerationManager.currentRoom);
             string[] gateInfo = File.ReadAllLines(Application.streamingAssetsPath + "/gate.txt", Encoding.UTF8);
             GameObject.Find("startPosition").transform.position = new Vector3(int.Parse(gateInfo[0]), int.Parse(gateInfo[1]), -1f);
             doStartForce = bool.Parse(gateInfo[2]);
             GameObject player = Instantiate(LocalPlayer);
             player.transform.position = GameObject.Find("startPosition").transform.position;
             NetworkServer.AddPlayerForConnection(NetworkServer.connections[0], player, indexController++);
         }
     }
     else
     {
         MessageManager.GetGenServerMessage.SendToServer(new EmptyMessage());
     }
 }