Beispiel #1
0
        private static void ExportPackages(string moduleFilename, string outputPath)
        {
            if (!File.Exists(moduleFilename))
            {
                CoreLogger.LogError("PackageManager", string.Format("unable to find file {0}", moduleFilename));
                return;
            }

            CoreLogger.LogDebug("PackageManager", string.Format("beginning export of package in file {0}", moduleFilename));

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(moduleFilename);

            if (xmlDoc.DocumentElement.Name != "module")
            {
                CoreLogger.LogError("PackageManager", string.Format("error in file {0}: root element of module file should be module!", moduleFilename));
                return;
            }

            if (!xmlDoc.DocumentElement.HasAttribute("packageName"))
            {
                CoreLogger.LogError("PackageManager", string.Format("error in file {0}: module element missing packageName attribute!", moduleFilename));
                return;
            }

            string packageName     = xmlDoc.DocumentElement.GetAttribute("packageName");
            string packageFilename = string.Format("{0}{1}{2}.unitypackage", outputPath, System.IO.Path.DirectorySeparatorChar, packageName);

            string[] folders = xmlDoc.DocumentElement.GetElementsByTagName("folder").Cast <XmlElement>().Where(e => e.HasAttribute("name")).Select(
                e => string.Format("Assets{0}{1}", System.IO.Path.DirectorySeparatorChar, e.GetAttribute("name"))).ToArray();

            foreach (string folder in folders)
            {
                CoreLogger.LogDebug("PackageManager", string.Format("including folder {0} and all its subfolders", folder));
            }

            CoreLogger.LogDebug("PackageManager", string.Format("exporting {0} folders to file {1}", folders.Length, packageFilename));

            AssetDatabase.ExportPackage(folders, packageFilename, ExportPackageOptions.Recurse);

            CoreLogger.LogDebug("PackageManager", "done!");
        }
        IEnumerator Load()
        {
            reactivate = true;

            Deactivate();

            float startRealtime = Time.realtimeSinceStartup;
            float startGametime = Time.time;
            int   startFrame    = Time.frameCount;

            ISceneLoadAction[] actions = GetComponentsInChildren(typeof(ISceneLoadAction)).Cast <ISceneLoadAction>().ToArray();
            float total = actions.Length + 1;
            float done  = 0;

            CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("SceneLoader beginning {0} actions...", actions.Length));

            foreach (ISceneLoadAction action in GetComponentsInChildren(typeof(ISceneLoadAction)))
            {
                float actionStart      = Time.realtimeSinceStartup;
                int   actionFrameStart = Time.frameCount;
                yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(action.Action));

                CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("performed load action {0} in {1} seconds and {2} frames",
                                                                             action.Name, Time.realtimeSinceStartup - actionStart, Time.frameCount - actionFrameStart));

                done     += 1;
                _progress = done / total;

                CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("progress is {0} ({1}/{2})", _progress, done, total));
            }

            CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("beginning to proxy-load scene {0}, actions took {1} seconds real time, {2} seconds game time, {3} frames",
                                                                          realScene, Time.realtimeSinceStartup - startRealtime, Time.time - startGametime, Time.frameCount - startFrame));
            startRealtime = Time.realtimeSinceStartup;
            startGametime = Time.time;
            startFrame    = Time.frameCount;

            while (Time.realtimeSinceStartup - startRealtime < minimumTime)
            {
                yield return(null);
            }

            bool  loaded = false;
            ITask loader = GameApplication.Instance.SceneManager.GetAdditiveLoader(realScene, sceneTransition, cleanup ? removals : null);

            CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("starting additive loader {0}", loader.Name));
            loader.Start(result => {
                if (!result.IsOk())
                {
                    CoreLogger.LogError(LoggerModules.SceneManager, string.Format("failed to load scene {0}!", realScene));
                }
                else
                {
                    CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("done proxy-loading of scene {0}: took {1} seconds real-time, {2} game time, {3} frames",
                                                                                  realScene, Time.realtimeSinceStartup - startRealtime, Time.time - startGametime, Time.frameCount - startFrame));
                }
                loaded    = true;
                _progress = 1f;

                Reactivate();
            }, loadTimeout);

            while (!loaded)
            {
                float loaderProgress = loader.Progress;
                _progress = (done + loaderProgress) / total;

                CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("progress is {0} ({1}/{2}); loading progress is {3}; yielding...", _progress, done, total, loaderProgress));

                yield return(null);
            }
        }
Beispiel #3
0
 public void should_call_logerror()
 {
     _coreLogger.LogError(_message);
     _logger.Validate(LogLevel.Error, _message);
 }
 override public void Cancel()
 {
     CoreLogger.LogError(LoggerModules.SceneManager, string.Format("cancel requested on loading of scene {0}, but is not supported!", _sceneName));
 }
        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 additive loader: {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));
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("starting additive async load of scene {0}", _sceneName));
            _operation = Application.LoadLevelAdditiveAsync(_sceneName);
            _operation.allowSceneActivation = false;
            _operation.priority             = 0;

            while (_progress < _additiveLoaderWatermark)
            {
                if (_cancel)
                {
                    InvokeDone(TaskEnding.Cancelled);
                    yield break;
                }

                yield return(null);

                _lastProgress = _progress;
                _progress     = _operation.progress;

                if (_progress < _lastProgress)
                {
                    //time travel - this can happen if we came back from background
                    CoreLogger.LogNotice(LoggerModules.SceneManager, "time travel in scene loader - loading the next scene and calling done");
                }
            }

            _progress = 1;
            yield return(null);

            yield return(new WaitForSeconds(_delay));

            SceneTransition sceneTransition = null;

            if (_sceneTransition != null)
            {
                sceneTransition = _sceneTransition.gameObject.GetComponent <SceneTransition>();
                if (sceneTransition != null)
                {
                    GameObject newInstance = GameObject.Instantiate(_sceneTransition.gameObject) as GameObject;
                    GameObject.DontDestroyOnLoad(newInstance);

                    sceneTransition = newInstance.GetComponent <SceneTransition>();
                    Debugger.Assert(sceneTransition != null, "sceneTransition cannot be null!");
                    if (sceneTransition != null)
                    {
                        GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.ExitSequence);

                        yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadeout));
                    }
                }
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("allowing scene additive load operation to complete"));

            _operation.allowSceneActivation = true;
            yield return(_operation);

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("done additive load of scene {0}", _sceneName));

            HandleRemovals();

            if (sceneTransition != null)
            {
                sceneTransition.OnLevelWasLoaded(Application.loadedLevel);
                CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} will now handle transition {1}", _sceneName, sceneTransition.name));
                yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadein));
            }

            if (_sceneManager.PendingLoadTask == this)
            {
                CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("resetting pending load from {0} to null", _name));
                _sceneManager.PendingLoadTask = null;
            }
            else
            {
                if (_sceneManager.PendingLoadTask == null)
                {
                    CoreLogger.LogError(LoggerModules.SceneManager, string.Format("{0}: pending load is null!", _name));
                }
                else
                {
                    CoreLogger.LogError(LoggerModules.SceneManager, string.Format("{0}: no need to reset pending since it is already somebody else: {1}", _name, _sceneManager.PendingLoadTask.Name));
                }
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} will now invoke done", _sceneName));
            InvokeDone(TaskEnding.Done);
            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} has invoked done", _sceneName));
        }