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; }
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--; }