Exemple #1
0
        public void Initialize()
        {
            _levelParent = new GameObject("Locations");
            var path       = AssetsPathGameObject.Object[GameObjectType.Levels];
            var levelsData = Resources.LoadAll <LevelsData>(path);

            _levelsData             = levelsData[0];
            _defaultBootScreen      = Object.Instantiate((BootScreen)_levelsData.BootScreen, _levelParent.transform);
            _defaultBootScreen.name = "DefaultBootScreen";
            _defaultBootScreen.gameObject.SetActive(false);
            LoadLevel(_levelsData.GetGate);
        }
Exemple #2
0
        public void LoadLevel(IGate gate)
        {
            if (_activeLevel == null || _activeLevel.LevelName != gate.GoToLevelName)
            {
                LoadAndUnloadPrefabs(gate.GoToLevelName);
            }

            var bootLocation = _activeLevel.Locations.Find(l => l.LocationName == gate.GoToLocationName);

            if (!bootLocation)
            {
                Debug.LogError(_activeLevel.LevelName + " не содержит локации с именем " + gate.GoToLocationName);
            }

            _customBootScreen = bootLocation.CustomBootScreenInstance;

            if (gate.ThisLevelName != gate.GoToLevelName || gate.ThisLocationName != gate.GoToLocationName)
            {
                var bootScreen = _customBootScreen == null ? _defaultBootScreen : _customBootScreen;
                bootScreen.ShowBootScreen(_services, LoadLevelPart);
            }
            else
            {
                LoadLevelPart();
            }

            void LoadLevelPart()
            {
                var activeLocation = _activeLevel.Locations.Find(l => l.LocationActiveSelf);

                if (activeLocation)
                {
                    activeLocation.UnloadLocation();
                }

                var enterGate = bootLocation.Gates.Find(g => g.ThisGateId == gate.GoToGateId);

                if (!enterGate)
                {
                    Debug.LogError("В " + gate.GoToLevelName + " - " + gate.GoToLocationName +
                                   " нет Gate c ID = " + gate.GoToGateId);
                }

                _levelsData.SetLastLevelGate = gate;
                bootLocation.LoadLocation();
                _services.CameraServices.SetCamera(bootLocation);
            }
        }