Ejemplo n.º 1
0
        private IEnumerator EnteringUnloadedZone(ZoneLoadStatus status, ZoneData from, ZoneData to, bool waitForConnections)
        {
            Freeze();

            if (to.State == ZoneState.Unloaded || to.State == ZoneState.Unloading)
            {
                yield return(LoadZone(to));
            }

            while (to.State == ZoneState.Loading)
            {
                yield return(null);
            }

            if (waitForConnections)
            {
                yield return(LoadConnections(to, from));
            }
            else
            {
                StartCoroutine(LoadConnections(to, from));
            }

            EnteringZone(to, from);
            status.IsDone = true;

            Thaw();
        }
Ejemplo n.º 2
0
        private IEnumerator UnloadZone(ZoneData data)
        {
            if (data.State != ZoneState.Loaded)
            {
                Debug.LogErrorFormat(this, _zoneNotLoadedError, data.Zone.name);
                yield break;
            }

            data.Unloading();
            data.State = ZoneState.Unloading;
            LoadedZones.Remove(data);

            var loader = SceneManager.UnloadSceneAsync(data.SceneIndex);

            if (loader == null)
            {
                Debug.LogErrorFormat(this, _zoneUnloadFailedError, data.Zone.name);
                yield break;
            }

            while (!loader.isDone)
            {
                yield return(null);
            }

            data.State = ZoneState.Unloaded;
        }
Ejemplo n.º 3
0
        private ZoneLoadStatus ChangeZone(ZoneData to, bool waitForConnections)
        {
            var from   = Player.Instance.Zone;
            var loader = new ZoneLoadStatus {
                IsDone = false
            };

            if (from != null)
            {
                LeaveZone(from, to);
            }

            if (to != null)
            {
                if (to.State == ZoneState.Loaded && !waitForConnections)
                {
                    EnteringLoadedZone(loader, to, from);
                }
                else
                {
                    StartCoroutine(EnteringUnloadedZone(loader, from, to, waitForConnections));
                }
            }
            else
            {
                loader.IsDone = true;
            }

            return(loader);
        }
Ejemplo n.º 4
0
        private void EnteringZone(ZoneData to, ZoneData from)
        {
            _context.SetStore(nameof(Zone), to);

            SceneManager.SetActiveScene(to.Zone.Scene.Scene);
            Player.Instance.Zone = to;
            to.Entering(from);
        }
Ejemplo n.º 5
0
        internal void Entering(ZoneData from)
        {
            IsActive = true;

            if (AudioManager.Instance && Zone.BackgroundMusic != null && (from == null || Zone.BackgroundMusic != from.Zone.BackgroundMusic))
            {
                AudioManager.Instance.Push(Zone.BackgroundMusic, 1.0f, 1.0f, 1.0f);
            }
        }
Ejemplo n.º 6
0
        private void LeaveZone(ZoneData from, ZoneData to)
        {
            from.Left(to);
            Player.Instance.Zone = null;
            SceneManager.SetActiveScene(gameObject.scene);

            UnloadConnections(from, to);

            _context.SetStore(nameof(Zone), null);
        }
Ejemplo n.º 7
0
        internal void Left(ZoneData to)
        {
            IsActive = false;

            _variables.ResetAvailability(Zone.ZoneActiveAvailability);

            if (AudioManager.Instance && Zone.BackgroundMusic != null && (to == null || Zone.BackgroundMusic != to.Zone.BackgroundMusic))
            {
                AudioManager.Instance.Pop(1.0f, 1.0f, 1.0f);
            }
        }
Ejemplo n.º 8
0
        private void UnloadConnections(ZoneData from, ZoneData to)
        {
            foreach (var index in from.Connections)
            {
                var data = Zones[index];

                if (to == null || (data != to && !to.Connections.Contains(data.SceneIndex)))
                {
                    StartCoroutine(UnloadZone(data));
                }
            }

            if (to == null || !to.Connections.Contains(from.SceneIndex))
            {
                StartCoroutine(UnloadZone(from));
            }
        }
Ejemplo n.º 9
0
        private IEnumerator LoadZone(ZoneData data)
        {
            while (data.State == ZoneState.Unloading)
            {
                yield return(null);
            }

            if (data.State != ZoneState.Unloaded)
            {
                Debug.LogErrorFormat(this, _zoneAlreadyLoadedError, data.Zone.name);
                yield break;
            }

            var loader = SceneManager.LoadSceneAsync(data.Zone.Scene.Index, LoadSceneMode.Additive);

            if (loader == null)
            {
                Debug.LogErrorFormat(this, _zoneNotAssignedError, data.Zone.name);
                yield break;
            }

            _pendingLoads++;
            data.State = ZoneState.Loading;

            while (!loader.isDone)
            {
                yield return(null);
            }

            var valid = data.Loaded();

            if (valid)
            {
                data.State = ZoneState.Loaded;
                LoadedZones.Add(data);
            }
            else
            {
                SceneManager.UnloadSceneAsync(data.SceneIndex);
                data.State = ZoneState.Unloaded;
            }

            _pendingLoads--;
        }
Ejemplo n.º 10
0
        private void CreateZones()
        {
            Zones       = new ZoneData[SceneManager.sceneCountInBuildSettings];
            LoadedZones = new List <ZoneData>();

            foreach (var zone in World.Zones)
            {
                var index = zone.Scene.Index;

                if (index < 0)
                {
                    Debug.LogWarningFormat(zone, _missingZoneSceneWarning, zone.name);
                }
                else
                {
                    Zones[index] = CreateZone(zone, index);
                }
            }
        }
Ejemplo n.º 11
0
        private IEnumerator SpawnPlayer(ZoneData zone, SpawnPoint spawnPoint)
        {
            if (spawnPoint.IsNamed)
            {
                spawnPoint = zone.GetSpawnPoint(spawnPoint.Name);
            }
            else
            {
                spawnPoint = zone.SpawnPoints.Count > 0 ? zone.SpawnPoints.Values.First() : SpawnPoint.Default;
            }

            Player.Instance.Mover.WarpToPosition(spawnPoint.Position, spawnPoint.Direction, spawnPoint.Layer);

            yield return(TransitionManager.Instance.RunTransition(spawnPoint.Transition == null ? World.DefaultSpawnTransition : spawnPoint.Transition, TransitionPhase.In));            // Don't null coalesce these

            if (spawnPoint.Move)
            {
                Player.Instance.Mover.Move(spawnPoint.Direction);
            }
        }
Ejemplo n.º 12
0
        private IEnumerator LoadConnections(ZoneData to, ZoneData from)
        {
            foreach (var index in to.Connections)
            {
                var data = Zones[index];

                if (data.State == ZoneState.Unloaded || data.State == ZoneState.Unloading)
                {
                    StartCoroutine(LoadZone(data));
                }
            }

            while (_pendingLoads > 0)
            {
                yield return(null);
            }

            foreach (var loadedZone in LoadedZones)
            {
                var enabled = loadedZone.Zone.MapLayer == to.Zone.MapLayer;

                if (enabled && !loadedZone.IsEnabled)
                {
                    loadedZone.Enabled();
                    yield return(null);                    // wait for Start and OnEnabled calls

                    loadedZone.RestoreNpcData();
                }

                if (!enabled && loadedZone.IsEnabled)
                {
                    loadedZone.PersistNpcData();
                    loadedZone.Disabled();
                }
            }
        }
Ejemplo n.º 13
0
 protected static VariableValue GetName(ZoneData zone) => VariableValue.Create(zone.Zone.Name);
Ejemplo n.º 14
0
 protected static VariableValue GetPlayer(ZoneData zone) => VariableValue.Create(Player.Instance);
Ejemplo n.º 15
0
 protected static VariableValue GetWorld(ZoneData zone) => VariableValue.Create(zone.World);
Ejemplo n.º 16
0
 private void EnteringLoadedZone(ZoneLoadStatus status, ZoneData to, ZoneData from)
 {
     StartCoroutine(LoadConnections(to, from));
     EnteringZone(to, from);
     status.IsDone = true;
 }
Ejemplo n.º 17
0
 protected static VariableValue GetState(ZoneData zone) => VariableValue.Create(zone.State.ToString());
Ejemplo n.º 18
0
 protected static VariableValue GetIsActive(ZoneData zone) => VariableValue.Create(zone.IsActive);
Ejemplo n.º 19
0
 private void DestroyZone(ZoneData zone)
 {
     Destroy(zone);
 }