public ITask GetAdditiveLoader(string sceneName, SceneTransition sceneTransition = null, IEnumerable <GameObject> removals = null) { if (sceneTransition == null) { sceneTransition = defaultSceneTransition; } //FIXME: Implement Additive for non unity pro #if UNITY_PRO_LICENSED ITask task = new AdditiveSceneLoaderTask(this, sceneName, additiveLoaderWatermark, sceneTransition, removals, additiveLoaderDelay); task.Done += result => { if (result.IsOk()) { Logger.LogDebug(LoggerModules.SceneManager, string.Format("loaded scene {0}", sceneName)); SceneLoaded(sceneName); } }; return(task); #else CoreLogger.LogWarning("Warning - attempting to additively load a scene without Unity Pro License - currently unsupported action"); return(new SceneLoaderTask(this, sceneName, sceneTransition, null)); #endif }
IEnumerator LoadAsset(AssetManager assetManager, string path) { if (!assetManager.CatalogReady) { yield return(_coroutineFactory.StartCoroutine(() => assetManager.CatalogWaiter())); } string bundleName = assetManager.GetBundleName(path); if (bundleName != "") { yield return(_coroutineFactory.StartCoroutine(() => WaitForBundle(assetManager, bundleName))); } else { CoreLogger.LogWarning(assetManager.LoggerModule, string.Format("unable to find asset bundle for asset {0}", path)); } if (_bundle == null) { //unable to retrieve bundle if (bundleName != "") { CoreLogger.LogWarning(assetManager.LoggerModule, string.Format("unable to load bundle {0} for asset {1} - will try to load locally", bundleName, path)); } _request = Resources.LoadAsync(path); yield return(_request); _result = _request.asset as T; if (_result != null) { InvokeResultSet(); } yield break; } string assetName = assetManager.GetAssetName(path); _bundleRequest = _bundle.LoadAssetAsync(assetName, typeof(T)); CoreLogger.LogInfo(assetManager.LoggerModule, string.Format("requesting load of asset {0} from bundle {1} - waiting...", assetName, bundleName)); yield return(_bundleRequest); _result = _bundleRequest.asset as T; if (_result == null) { CoreLogger.LogWarning(assetManager.LoggerModule, string.Format("failed to retrieve asset {0} from bundle {1} - will try to load locally", path, bundleName)); _request = Resources.LoadAsync(path); yield return(_request); _result = _request.asset as T; yield break; } InvokeResultSet(); CoreLogger.LogInfo(assetManager.LoggerModule, string.Format("finished loading asset {0}", path)); }
override protected void Awake() { base.Awake(); if (s_activeControllers.Count > 0) { if (s_activeControllers.FirstOrDefault(c => c.SceneName == SceneName) != null) { CoreLogger.LogWarning(LoggerModules.SceneManager, string.Format("scene controller with name {0} already active!", SceneName)); } else { CoreLogger.LogWarning(LoggerModules.SceneManager, string.Format("scene controller {0} awakening while there are other active controllers!", SceneName)); } } s_activeControllers.Add(this); CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("scene controller for scene {0} awakening and setting itself current instead of {1}", SceneName, s_current.Target == null ? "null" : s_current.Target.SceneName)); s_current.Target = this; #if UNITY_EDITOR //a testing scene would not be a part of the build if (sceneType == SceneType.Testing) { if (s_jumpToInitOnTestScenes) { s_jumpToInitOnTestScenes = false; string temp = forceInitScene; forceInitScene = ""; GameApplication.RequestingScene = Application.loadedLevelName; Application.LoadLevel(temp); return; } } if (Application.loadedLevel != 0 && GameApplication.RequestingScene == "") { GameApplication.RequestingScene = Application.loadedLevelName; if (forceInitScene != "") { Application.LoadLevel(forceInitScene); } else { Application.LoadLevel(0); } } #endif }
public void OnSceneClosing() { if (_readyToUnload) { CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("scene {0} received SceneClosing", SceneName)); } else { CoreLogger.LogWarning(LoggerModules.SceneManager, string.Format("scene {0} received SceneClosing without being ready!", SceneName)); //FIXME: better terminate all exits and stuff? } }
IEnumerator Init() { return(LoadValue( string.Format("http://{0}/api/assetcatalogs", assetServerAddress), data => { if (data as DataArray != null) { CoreLogger.LogInfo(_loggerModule, string.Format("received catalog: {0}", data)); _catalog = new AssetCatalog(data[0]); } else { CoreLogger.LogWarning(_loggerModule, "response is not a json array - no catalog will be available"); _catalog = new AssetCatalog(); } } )); }
public T GetResource <T>(string name, bool isCascading) where T : Object { Object obj = null; if (isCascading) { obj = GameApplication.LoadFrameworkResource(name) as T; } if (obj == null) { obj = Resources.Load(name); } if (obj == null) { CoreLogger.LogWarning("UnityResourceManager", string.Format("resource {0} not found in framework paths!", name)); } return(obj as T); }
IEnumerator LoadValue(string url, System.Action <DataElement> handler) { CoreLogger.LogInfo(_loggerModule, string.Format("url {0} requested", url)); WWW www = new WWW(url); yield return(www); if (www.error != null) { CoreLogger.LogWarning(_loggerModule, string.Format("failed to retrieve url - {0}", www.error)); handler(null); yield break; } CoreLogger.LogTrace(_loggerModule, string.Format("requested url {0} returned {1}", url, www.text)); DataElement dataElement = DataElement.Parse(www.text); handler(dataElement); }
public ITask Start(System.Action <TaskEnding> resultHandler, float timeout = -1f) { _taskState = TaskState.Started; Done += resultHandler; _resource = Resources.Load(_asset) as T; if (_resource == null) { CoreLogger.LogWarning("UnityResourceManager", string.Format("resource {0} not found in project!", _asset)); } _startTime = Time.time; Done(TaskEnding.Done); if (_resource != null) { ResultSet(_resource); } _taskState = TaskState.Done; return(this); }
public IEnumerator DownloadAndCache(string bundleName, System.Action <AssetBundle> handler, int version) { LoadedBundle loadedBundle; if (_bundles.TryGetValue(bundleName, out loadedBundle)) { if (loadedBundle != null) { if (loadedBundle.version == version) { loadedBundle.lastRequest = Time.time; loadedBundle.numRequests++; handler(loadedBundle.bundle); yield break; } } } // Wait for the Caching system to be ready while (!Caching.ready) { yield return(null); } if (!maintainBundleCache) { #if UNITY_2017_1_OR_NEWER Caching.ClearCache(); #else Caching.CleanCache(); #endif } // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache string bundleUrl = GetBundleUrl(bundleName); CoreLogger.LogInfo("BundleManager", string.Format("for bundle {0}, full url is {1}", bundleName, bundleUrl)); using (WWW www = WWW.LoadFromCacheOrDownload(bundleUrl, version)) { yield return(www); if (www.error != null) { CoreLogger.LogWarning(name, string.Format("unable to retrieve bundle {0}:{1}", bundleUrl, www.error)); handler(null); yield break; } CoreLogger.LogDebug("BundleManager", string.Format("successfully retrieved bundle {0} from {1}", bundleName, bundleUrl)); if (loadedBundle != null) { CoreLogger.LogDebug("BundleManager", string.Format("New version ({0}) of bundle {1} retrieved - unloading old version ({2}) and caching new one", version, bundleName, loadedBundle.version)); loadedBundle.bundle.Unload(false); loadedBundle.bundle = www.assetBundle; } else { CollectGarbage(); CoreLogger.LogDebug("BundleManager", string.Format("caching version {0} of bundle {1}", version, bundleName)); _bundles[bundleName] = new LoadedBundle() { bundle = www.assetBundle, version = version }; } handler(www.assetBundle); } }
public void should_call_logwarning() { _coreLogger.LogWarning(_message); _logger.Validate(LogLevel.Warning, _message); }
override protected IEnumerator Controller() { ISceneLoaderTask pending = _sceneManager.PendingLoadTask; if (pending != null) { if (pending.SceneName == _sceneName) { CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: pending request for the same scene ({1}); ending operation", _name, _sceneName)); InvokeDone(TaskEnding.Done); yield break; } } CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("setting pending load to {0}", _name)); _sceneManager.PendingLoadTask = this; if (pending != null) { CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1}...", _name, pending.Name)); yield return(GameApplication.Instance.CoroutineFactory.Wait(pending)); CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1} done!", _name, pending.Name)); } float startTime = Time.realtimeSinceStartup; //check to see if the current scene has a TabTale controller (all scenes are supposed to have one) ISceneController currentSceneController = SceneController.Current; if (currentSceneController != null) { if (_sceneTransition != null) { if (currentSceneController == null) { CoreLogger.LogNotice(LoggerModules.SceneManager, "no controller found in scene - injection of transitions is not possible!"); } else { CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("injecting effect {0} into the scene", _sceneTransition.name)); InjectTransition(_sceneTransition, currentSceneController); } } //tell the current scene it is about to be unloaded currentSceneController.PrepareToUnload(); CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("{0}: waiting for current scene {1} to be ready to unload", _name, currentSceneController.SceneName)); //async. waiting for either the old scene's signal that it's ready, or the timeout while (!currentSceneController.ReadyToUnload && (Time.realtimeSinceStartup - startTime <= _sceneManager.sceneUnloadTimeout)) { yield return(null); } CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("scene {0} done - wait took {1} seconds", currentSceneController.SceneName, Time.realtimeSinceStartup - startTime)); //tell the current scene it is being unloaded currentSceneController.OnSceneClosing(); } else { CoreLogger.LogWarning(LoggerModules.SceneManager, "Unable to find TabTale Scene Controller!"); } _levelLoadStart = Time.realtimeSinceStartup; _levelLoadStartFrame = Time.frameCount; if (_sceneManager.asyncPreloading) { yield return(_sceneManager.PreloadActions(_preloadActions)); } else { _sceneManager.HandlePreloadActions(_preloadActions); } if (_sceneManager.asyncLoading && !Application.platform.IsEditor()) { CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("Loading new scene {0} asynchronously...", _sceneName)); SceneLoadStarted(); _asyncLoadOperation = Application.LoadLevelAsync(_sceneName); yield return(_asyncLoadOperation); _asyncLoadOperation = null; } else { //start loading the new scene - note that even though this is a blocking call, //it actually starts a background thing, and from this moment on everything //is in Limbo Application.LoadLevel(_sceneName); _progress = 1; CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("Loading new scene {0} synchronously...", _sceneName)); yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); SceneLoadStarted(); } GameApplication.Instance.ApplicationEvents.LevelLoaded -= OnLevelLoaded; if (_sceneManager.PendingLoadTask == this) { CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("resetting pending load from {0} to null", _name)); _sceneManager.PendingLoadTask = null; } }
public void Cancel() { CoreLogger.LogWarning(LoggerModules.SceneManager, string.Format("resource loader {0} received Cancel, which is not supported!", _name)); }