Exemplo n.º 1
0
        protected override async Task OnUnloadAsync(string id, Scene scene, ISceneInfo info, ISceneUnloadParameters parameters, IContext context)
        {
            LogSceneUnload(id, info, parameters, scene, UnloadUnusedAfterUnload, true);

            var provider = ProviderInstance.Get <IProvider <Scene, AsyncOperation> >();

            AsyncOperation operation = SceneManager.UnloadSceneAsync(scene, parameters.Options);

            provider.Add(scene, operation);

            while (!operation.isDone)
            {
                await Task.Yield();
            }

            provider.Remove(scene);

            if (RegisterApplication)
            {
                OnUnregisterApplication(scene);
            }

            if (UnloadUnusedAfterUnload)
            {
                operation = Resources.UnloadUnusedAssets();

                while (!operation.isDone)
                {
                    await Task.Yield();
                }
            }

            LogSceneUnloaded(id, info, parameters, UnloadUnusedAfterUnload, true);
        }
        public IEnumerator Load(string moduleName, string id, bool unload)
        {
            IApplication application = CreateApplication(moduleName);

            application.Initialize();

            var   module = application.GetModule <ISceneModule>();
            Scene scene  = module.Load(id);

            Assert.Contains(scene, module.Instances.Entries.Keys.ToArray());
            Assert.Contains(scene, ProviderInstance.Get <IProvider <Scene, IApplication> >().Entries.Keys.ToArray());
            Assert.Contains(application, ProviderInstance.Get <IProvider <Scene, IApplication> >().Entries.Values.ToArray());

            yield return(null);

            Assert.True(scene.IsValid(), "Load: scene.IsValid()");
            Assert.True(scene.isLoaded, "Load: scene.isLoaded");
            Assert.AreEqual(module.Scenes.Get(id).Address, "Assets/UGF.Module.Scenes.Runtime.Tests/Resources/SceneTest.unity");
            Assert.Contains(scene, module.Instances.Entries.Keys.ToArray());

            if (unload)
            {
                module.Unload(id, scene);

                Assert.IsEmpty(module.Instances.Entries.Keys);
                Assert.IsEmpty(ProviderInstance.Get <IProvider <Scene, IApplication> >().Entries.Keys);
                Assert.IsEmpty(ProviderInstance.Get <IProvider <Scene, IApplication> >().Entries.Values);

                yield return(null);

                Assert.False(scene.IsValid(), "Unload: scene.IsValid()");
                Assert.False(scene.isLoaded, "Unload: scene.isLoaded");
            }
        }
Exemplo n.º 3
0
        public static void Activate(this Scene scene, bool clearOperation = true)
        {
            var            provider  = ProviderInstance.Get <IProvider <Scene, AsyncOperation> >();
            AsyncOperation operation = provider.Get(scene);

            operation.allowSceneActivation = true;

            if (clearOperation)
            {
                provider.Remove(scene);
            }
        }
Exemplo n.º 4
0
        protected override async Task <Scene> OnLoadAsync(string id, ISceneInfo info, ISceneLoadParameters parameters, IContext context)
        {
            LogSceneLoading(id, info, parameters, true);

            var provider = ProviderInstance.Get <IProvider <Scene, AsyncOperation> >();
            var options  = new LoadSceneParameters(parameters.AddMode, parameters.PhysicsMode);

            AsyncOperation operation = SceneManager.LoadSceneAsync(info.Address, options);
            Scene          scene     = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);

            if (RegisterApplication)
            {
                OnRegisterApplication(scene, context);
            }

            operation.allowSceneActivation = parameters.AllowActivation;
            provider.Add(scene, operation);

            if (operation.allowSceneActivation)
            {
                while (!operation.isDone)
                {
                    await Task.Yield();
                }

                provider.Remove(scene);
            }
            else
            {
                while (operation.progress < 0.9F)
                {
                    await Task.Yield();
                }
            }

            LogSceneLoaded(id, info, parameters, scene, true);

            return(scene);
        }
Exemplo n.º 5
0
 public static bool TryGetOperation(this Scene scene, out AsyncOperation operation)
 {
     return(ProviderInstance.Get <IProvider <Scene, AsyncOperation> >().TryGet(scene, out operation));
 }
Exemplo n.º 6
0
 public static AsyncOperation GetOperation(this Scene scene)
 {
     return(ProviderInstance.Get <IProvider <Scene, AsyncOperation> >().Get(scene));
 }