// The very start of the program public IEnumerator InitApplication() { // basic initialization Screen.fullScreen = false; appState = AppState.Initializing; Application.targetFrameRate = targetFrameRate; userManager = GetComponentInChildren <UserManager>(); playbackManager = GetComponentInChildren <PlaybackManager>(); scenarioEvents = GetComponentInChildren <ScenarioEvents>(); networkManager = (NetworkManager)FindObjectOfType(typeof(NetworkManager)); osc = networkManager.osc; uiHandler = (UIHandler)FindObjectOfType(typeof(UIHandler)); canvasHandler = uiHandler.GetComponentInChildren <CanvasHandler>(); fileInOut = (FileInOut)FindObjectOfType(typeof(FileInOut)); soundHandler = (SoundHandler)FindObjectOfType(typeof(SoundHandler)); clock = (Clock)FindObjectOfType(typeof(Clock)); canvasHandler.ChangeCanvas("initCanvas"); //_userRole = UserRole.Server; // base setting int t = 0; switch (_userRole) { case UserRole.Server: { t = 0; break; } case UserRole.Player: { t = 1;; break; } case UserRole.Viewer: { t = 2;; break; } case UserRole.Tracker: { t = 3;; break; } case UserRole.Playback: { t = 4; break; } } // load jsons fileInOut.LoadPreferencesFiles(this); if (gameData.runInLocal == 1) { gameData.OSC_LocalIP = "127.0.0.1"; } else { gameData.OSC_LocalIP = CheckIp(); } // change UI's server IP field uiHandler.FillServerIPField(gameData.runInLocal, gameData.OSC_ServerIP); userManager.keepNamesVisibleForPlayers = (gameData.showNamesAboveHead == 1); // adjust user's parameters // build is always for non vr use if (!Application.isEditor) { useVRHeadset = false; StartCoroutine(EnableDisableVRMode(false)); } else { useVRHeadset = (gameData.useVr == 1); StartCoroutine(EnableDisableVRMode(false)); } if (useVRHeadset) { uiHandler.SetPlayerNetworkType(1); } else { uiHandler.SetPlayerNetworkType(t); } // do we print sent and received messages if (gameData.DebugMode == 1) { Instantiate(debugPrefab); debugMode = true; } yield return(new WaitForSeconds(1)); InvokeRepeating("TimedUpdate", 0.5f, 1f / targetFrameRate); }
// Start the performance when button's pressed public void StartGame() { int ID = UnityEngine.Random.Range(0, 10000); if (clock != null) { clock.SetSceneStartTs(); } string tmpIp; if (gameData.runInLocal == 1) { tmpIp = gameData.OSC_LocalIP; if (_userRole != UserRole.Server && !(_userRole == UserRole.Playback && playbackManager.mode == PlaybackMode.Offline)) { gameData.OSC_ClientPort = UnityEngine.Random.Range(5555, 8888); } } else { tmpIp = uiHandler.OSCServerAddressInput.text; gameData.OSC_ServerIP = tmpIp; // put back written address into gamedata object } string uiChosenName = uiHandler.playerNameTextBox.GetComponentInChildren <UnityEngine.UI.InputField>().text; if (_userRole == UserRole.Server || _userRole == UserRole.Playback) { useVRHeadset = false; StartCoroutine(EnableDisableVRMode(false)); } _user = userManager.InitLocalUser(ID, uiChosenName, tmpIp, gameData.OSC_ServerPort, true, _userRole); networkManager.InitNetwork(_userRole, gameData, uiHandler.OSCServerAddressInput.text, playbackManager.mode); if (_userRole != UserRole.Playback) { userManager.ChangeVisualisationMode("0", this, false); } soundHandler.Init(gameData.OSC_SoundHandlerIP, gameData.OSC_SoundHandlerPort, _userRole, uiHandler.recordAudioAfterScenario.isOn, gameData.audioRecordLength); if (_userRole == UserRole.Server) { // load every scenario stored in scenario json //scenarioEvents.performanceRecorder.sessionID = int.Parse(uiHandler.sessionIDInputBox.text); uiHandler.PopulateScenariosDropdown(scenarioEvents.scenarios); appState = AppState.Running; canvasHandler.ChangeCanvas("serverCanvas"); // sonification } else if (_userRole == UserRole.Playback) { fileInOut.LoadPerformance(fileInOut.performanceDataFiles[uiHandler.switchPerformanceDataFile.value], playbackManager); if (playbackManager.mode == PlaybackMode.Online) // online { appState = AppState.WaitingForServer; InvokeRepeating("AskForRegistration", 0f, 1f); canvasHandler.ChangeCanvas("waitingCanvas"); } else if (playbackManager.mode == PlaybackMode.Offline) { appState = AppState.Running; canvasHandler.ChangeCanvas("playbackCanvasOff"); UserData p1 = userManager.AddNewUser(this, 776, "P1", osc.outIP, osc.outPort, UserRole.Playback, 0); UserData p2 = userManager.AddNewUser(this, 777, "P2", osc.outIP, osc.outPort, UserRole.Playback, 1); p1.ChangeLayers(p1.transform, "Player1"); p2.ChangeLayers(p2.transform, "Player2"); playbackManager.StartPlayback(); } } else { appState = AppState.WaitingForServer; InvokeRepeating("AskForRegistration", 0f, 1f); canvasHandler.ChangeCanvas("waitingCanvas"); } }