Beispiel #1
0
    private void OnEnable()
    {
        UiStation foundUiStation = null;

        var sceneCount = SceneManager.sceneCount;
        var myScene    = gameObject.scene;

        for (var sceneIndex = 0; sceneIndex < sceneCount; sceneIndex++)
        {
            var scene = SceneManager.GetSceneAt(sceneIndex);
            if (scene == myScene)
            {
                continue;
            }

            var roots = scene.GetRootGameObjects();
            if (roots.Length != 1)
            {
                Debug.LogError("Incorrect scene count");
                Exit();
            }

            var uiStation = roots[0].GetComponent <UiStation>();
            if (uiStation == null)
            {
                Debug.LogError(
                    "Preset scene was missing UiStation component on root"
                    );
                Exit();
            }
            else if (foundUiStation != null)
            {
                Debug.LogError("Multiple Ui Stations");
                Exit();
            }
            else if (uiStation.presetId == -1)
            {
                Debug.LogError("Preset Id was -1");
                Exit();
            }

            foundUiStation = uiStation;
        }

        _activeUiStation = foundUiStation;
    }
Beispiel #2
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(0);
            return;
        }


        if (!NetworkManager.InstanceSet)
        {
            return;
        }

        if (_currentOperation != null)
        {
            if (!_currentOperation.isDone)
            {
                return;
            }
            _currentOperation = null;
        }

        if (StationId == -1)
        {
            if (_activeUiStation != null)
            {
                _currentOperation = SceneManager.UnloadSceneAsync(_activeUiStation.gameObject.scene);
            }
            return;
        }

        if (_myStationInfo == null)
        {
            UpdateStationInfo();
            return;
        }

        if (_activeUiStation == null)
        {
            _currentOperation = SceneManager.LoadSceneAsync(_myStationInfo.preset_index + 2, LoadSceneMode.Additive);
            if (_currentOperation == null)
            {
                Exit();
                return;
            }
            _currentOperation.completed += (_) =>
            {
                var loadedScene =
                    SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
                if (loadedScene.rootCount != 1)
                {
                    Debug.LogError("Invalid rootcount in loaded scene");
                    Exit();
                }

                var root = loadedScene.GetRootGameObjects()[0];
                _activeUiStation = root.GetComponent <UiStation>();
                if (_activeUiStation == null)
                {
                    Debug.LogError("Root object was missing UiStation");
                    Exit();
                    return;
                }

                if (_activeUiStation.presetId != _myStationInfo.preset_index)
                {
                    Debug.LogError($"Loaded preset doesn't match with preset index: {_activeUiStation.presetId} != {_myStationInfo.preset_index}");
                    Exit();
                    return;
                }

                UpdateActiveStation();
            };
            return;
        }

        if (_activeUiStation.presetId != _myStationInfo.preset_index)
        {
            _currentOperation =
                SceneManager.UnloadSceneAsync(
                    _activeUiStation.gameObject.scene
                    );
            return;
        }

        UpdateStationInfo();
    }