public void Process(string json) { /* Debug.Log(json); */ JArray result = JArray.Parse(json.Trim()); if (stateMachine.State == StateType.NON_INITIALIZED) { foreach (JObject obj in result) { var id = obj["Id"].ToObject <string>(); TestModel newModel = ProcessModel(obj); if (id == PlayerPrefs.GetString("id")) { playerSpawnManager.SpawnPlayer(newModel); } else { spawnManager.SpawnPlayer(newModel); } } starter.StartGame(); } else if (stateMachine.State == StateType.INITIALIZED || stateMachine.State == StateType.OB) { foreach (JObject obj in result) { TestModel model = ProcessModel(obj); if (playerSpawnManager.IsPlayer(model)) { continue; } // check if current player has been spawned or not if (model.CommandType == 0 && !spawnManager.Exists(model) ) { spawnManager.SpawnPlayer(model); } else if (model.CommandType == 1) { SyncOnlinePlayers(model); } else if (model.CommandType == 10) { SyncOnlinePlayers(model); } } } }
public void BeginGame(string _matchID) { // Spawn in GameManager; GameObject newSpawnManager = Instantiate(spawnManagerPrefab); NetworkServer.Spawn(newSpawnManager); newSpawnManager.GetComponent <NetworkMatchChecker>().matchId = _matchID.ToGuid(); PlayerSpawnManager spawnManager = newSpawnManager.GetComponent <PlayerSpawnManager>(); for (int i = 0; i < matches.Count; i++) { if (matches[i].matchID == _matchID) { foreach (var player in matches[i].players) { Player _player = player.GetComponent <Player>(); Debug.Log($"Spawning player {_player.playerName}"); spawnManager.SpawnPlayer(); } break; } } }