示例#1
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());
     }
 }