Example #1
0
    async void LoadList()
    {
        AssetList al = await Addressables.LoadAssetAsync <AssetList>(sceneList).Task;

        //If you made an update to a scene, make sure that scene has been moved to a Remote Load group!
        Addressables.LoadSceneAsync(al.assets[0]);
    }
Example #2
0
    IEnumerator LoadScene(AssetReference addressableLevel)
    {
        LoginManager.LoadLevel();//switch to level load screen
        yield return(null);

        //Begin to load the Scene you specify
        AsyncOperationHandle asyncAssetLoad = Addressables.LoadSceneAsync(addressableLevel, LoadSceneMode.Single);//.Completed += SceneLoadComplete;

        //When the load is still in progress, output the Text and progress bar
        while (!asyncAssetLoad.IsDone)
        {
            //Output the current progress
            progressBar.value = asyncAssetLoad.PercentComplete;

            // Check if the load has finished
            if (asyncAssetLoad.PercentComplete >= 0.9f)
            {
                // hide the progress bar
                progressBar.gameObject.SetActive(false);
                //asyncAssetLoad.Completed += SceneLoadComplete;
            }

            //asyncOperation.allowSceneActivation = true;
            yield return(null);
        }
    }
        private IEnumerator InitState()
        {
            StateSceneAsyncOperationHandle = Addressables.LoadSceneAsync(gameSceneCatalogue.BoardScene, LoadSceneMode.Additive);
            yield return(StateSceneAsyncOperationHandle);

            signalBus.Fire <Match3Signals.CreateBoardSignal>();
        }
        //================ Basic

        public static AsyncOperationHandle <SceneInstance> LoadSceneAsync(string pAddress, LoadSceneMode pMode, Action <float> pProgress = null, Action <SceneInstance> pOnCompleted = null)
        {
            var operation = Addressables.LoadSceneAsync(pAddress, pMode);

            WaitLoadTask(operation, pProgress, pOnCompleted);
            return(operation);
        }
Example #5
0
    private void OnDownloadAR_scene(AsyncOperationHandle <IList <IResourceLocation> > obj)
    {
        AR_scene = new List <IResourceLocation>(obj.Result);

        Debug.Log(AR_scene[0]);

        downloadSize = Addressables.GetDownloadSizeAsync(AR_scene[0]);
        Debug.Log(downloadSize.Result);
        DownloadScene_Size1.text = downloadSize.Result.ToString();
        DownloadScene_Size2.text = downloadSize.Result.ToString();


        if (downloadSize.Result > 0)
        {
            // Delete old Bundle hahaha
            //Caching.ClearCache();

            Caching.ClearAllCachedVersions("remote_arscene_scenes_all");

            StartCoroutine(LoadRoutine());
        }
        else
        {
            Debug.Log("There is no Update");
            Addressables.LoadSceneAsync(AR_scene[0]);
        }
    }
Example #6
0
        public IEnumerator PreloadScene()
        {
            //Debug.Log($"Preloading {Scene}");
            if (Application.CanStreamedLevelBeLoaded(Scene))
            {
                aoNormal = SceneManager.LoadSceneAsync(Scene, LoadSceneMode.Single);
                aoNormal.allowSceneActivation = false;
                yield return(new WaitUntil(() =>
                {
                    //Debug.Log($"Normal progress {aoNormal.progress}");
                    return aoNormal.progress == 0.9f;
                }));
            }
            else
            {
#if HAS_AAS
                //Debug.Log($"AAS");
                var handle = Addressables.LoadSceneAsync(Scene, loadMode: LoadSceneMode.Single, activateOnLoad: false);
                aoAAS = handle;
                yield return(handle);

                //Debug.Log($"COMPLETE");
                aas = true;
#else
                throw new Exception($"The specified scene {Scene} could not be be loaded.");
#endif
            }
        }
        public ResourceHandle LoadSceneAsync <T>(string addressKey, Action <Scene> callback)
        {
            // @note:シーンのハンドルは保持しない
            var handle = new ResourceHandle(GenerateHandleId(), addressKey, typeof(Scene));

            handle.HandleScene            = Addressables.LoadSceneAsync(addressKey);
            handle.HandleScene.Completed += op =>
            {
                if (op.Status == AsyncOperationStatus.Succeeded)
                {
#if UNITY_EDITOR
                    Fwk.DebugSystem.Log.DebugUseResourceLog.Instance.Append("key:" + addressKey);
#endif
                    callback(op.Result.Scene);
                }
                else
                {
                    Debug.LogFormat("Status[{0}]: key => {1}", op.Status, handle.Key);
                }

                if (op.OperationException != null)
                {
                    Debug.LogWarningFormat("LoadScene is null => {0}", op.OperationException.ToString());
                }
            };

            return(handle);
        }
Example #8
0
        IEnumerator LoadScene(string sceneName)
        {
            Debug.Log($"[Client] <b>Loading level</b> '<i>{sceneName}</i>'");

            EventHub <StartedLoading> .Emit(new StartedLoading());

            // Cleanup
            currentReplicaPossess = ReplicaId.Invalid;

            Client.replicaManager.Reset();

            if (sceneHandle.IsValid())
            {
                yield return(Addressables.UnloadSceneAsync(sceneHandle));
            }

            // New map
#if !UNITY_EDITOR
            sceneHandle            = Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            sceneHandle.Completed += ctx => {
                SendLoadSceneDone();
                EventHub <EndedLoading> .Emit(new EndedLoading());
            };
#else
            SendLoadSceneDone();
            EventHub <EndedLoading> .Emit(new EndedLoading());
#endif
        }
        private IEnumerator SceneChange(AssetReference scene)
        {
            bool transitionLoaded = _screenTransition != null;

            if (transitionLoaded)
            {
                _screenTransition.FadeOut();
            }

            _loadOperation = Addressables.LoadSceneAsync(scene, LoadSceneMode.Single, activateOnLoad: false);

            yield return(_loadOperation);

            if (transitionLoaded)
            {
                yield return(new WaitUntil(() => _screenTransition.Faded));
            }

            yield return(_loadOperation.Result.ActivateAsync());

            if (transitionLoaded)
            {
                _screenTransition.FadeIn();
                yield return(new WaitUntil(() => !_screenTransition.Faded));
            }
        }
Example #10
0
    private IEnumerator LoadSceneRoutine(string sceneName, LoadSceneMode mode, Action <SceneInstance> onSuccess, Action <float> onChangeProgress, Action <string> onFail)
    {
        Debug.Log("LoadSceneRoutine start");
        var loadSceneOperationHandle = Addressables.LoadSceneAsync(sceneName, mode, true);
        var oldProgress = -1f;

        while (loadSceneOperationHandle.IsValid() && !loadSceneOperationHandle.IsDone)
        {
            if (loadSceneOperationHandle.Status == AsyncOperationStatus.Failed)
            {
                Debug.LogError("Operation failed");
                StopLoadScene();
                onFail("Operation failed");
                yield break;
            }
            if (loadSceneOperationHandle.OperationException != null)
            {
                Debug.LogError(loadSceneOperationHandle.OperationException);
                StopLoadScene();
                onFail.Invoke(loadSceneOperationHandle.OperationException.Message);
                yield break;
            }

            if (oldProgress != loadSceneOperationHandle.PercentComplete)
            {
                oldProgress = loadSceneOperationHandle.PercentComplete;
                onChangeProgress.Invoke(oldProgress);
            }

            yield return(null);
        }
        Debug.Log("LoadScene Complete!");
        StopLoadScene();
        onSuccess.Invoke(loadSceneOperationHandle.Result);
    }
 public static void LoadScene(IKeyEvaluator scene, Action callBack = null)
 {
     Addressables.LoadSceneAsync(scene).Completed += (loadComplete) =>
     {
         callBack?.Invoke();
     };
 }
 /// <summary>
 /// Load the specified addressable resource
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="name"></param>
 /// <param name="resourceLoadedCallback"></param>
 public async Task <T> LoadResourceAsync <T>(string name)
 {
     //If we already loaded the resource
     if (resources.ContainsKey(name + typeof(T).ToString()))
     {
         //Use it directly
         return((T)resources[name]);
     }
     else
     {
         //Load it
         if (typeof(T) == typeof(SceneInstance))
         {
             //If it is scene, load it to switch current scene
             handles.Add(Addressables.LoadSceneAsync(name));
             T result = default(T);
             return(result);
         }
         else
         {
             var handle = Addressables.LoadAssetAsync <T>(name);
             handles.Add(handle);
             await handle;
             var   resource = handle.Result;
             resources[name + typeof(T).ToString()] = resource;
             return(resource);
         }
     }
 }
Example #13
0
 public void LoadGameplayScene()
 {
     // 场景异步加载
     // m_SceneAddressToLoad:场景名称
     // 场景内所有的 Assets 都会被异步加载
     Addressables.LoadSceneAsync(m_SceneAddressToLoad, UnityEngine.SceneManagement.LoadSceneMode.Single).Completed += OnSceneLoaded;
 }
    public void LoadScene(string tag)
    {
        Debug.Log("Addressables Procedure Started for Loading Scene: " + tag + "@" + Time.time);
        Addressables.ClearDependencyCacheAsync(tag);
        Addressables.InitializeAsync().Completed += delegate {
            Debug.Log("Addressables.InitializeAsync.Completed:@" + Time.time);
            Addressables.GetDownloadSizeAsync(tag).Completed += delegate(AsyncOperationHandle <long> obj)
            {
                Debug.Log("Addressables.GetDownloadSizeAsync.Completed:@" + Time.time);
                float downloadSizeInMB = (float)obj.Result / 1024 / 1024;
                Debug.Log("GetDownloadSizeAsync: " + obj.Result + " bytes, which is " + downloadSizeInMB + " MB");

                if (size)
                {
                    size.text += System.Environment.NewLine + "Size of download: " + downloadSizeInMB.ToString();
                }

                Addressables.DownloadDependenciesAsync(tag).Completed += delegate(AsyncOperationHandle opDownloadDependencies)
                {
                    Debug.Log("Addressables.DownloadDependenciesAsync.Completed:" + opDownloadDependencies.Status + "@" + Time.time);
                    Addressables.LoadSceneAsync(tag).Completed += delegate(AsyncOperationHandle <SceneInstance> opLoadScene) {
                        Debug.Log("LoadSceneAsync.Completed: " + opLoadScene.Status + "@" + Time.time);
                        if (opLoadScene.Status == AsyncOperationStatus.Succeeded)
                        {
                        }
                    };
                };
            };
        };
    }
Example #15
0
 public static void LoadSceneAsync(string sceneName, Action <SceneInstance> callback)
 {
     Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Single).Completed += (args) =>
     {
         callback?.Invoke(args.Result);
     };
 }
Example #16
0
        /// <summary>
        /// Reset replication, instruct all clients to load the new scene, actually
        /// load the new scene on the server and finally create a new GameMode instance.
        /// </summary>
        /// <param name="sceneName"></param>
        public void LoadScene(string sceneName)
        {
            // Cleanup
            if (gameMode != null)
            {
                gameMode.StartToLeaveMap();
            }

            IsLoadingScene = true;
            ++loadSceneGeneration;
            numLoadScenePlayerAcks = 0;
            loadSceneName          = sceneName;

            server.ReplicaManager.Reset();
            if (sceneHandle.IsValid())
            {
                Addressables.UnloadSceneAsync(sceneHandle);
            }



            // Instruct clients
            var bs = new BitStream();

            bs.Write((byte)MessageId.LoadScene);
            bs.Write(sceneName);
            bs.Write(loadSceneGeneration);

            server.NetworkInterface.BroadcastBitStream(bs, PacketReliability.ReliableSequenced);

            // Disable ReplicaViews during level load
            foreach (var connection in server.connections)
            {
                var replicaView = server.ReplicaManager.GetReplicaView(connection);
                if (replicaView == null)
                {
                    continue;
                }

                replicaView.IsLoadingLevel = true;
            }

            // Load new map
            Debug.Log($"[Server] Loading level {sceneName}");
#if UNITY_EDITOR
            if (SceneManager.GetSceneByName(sceneName).isLoaded)
            {
                SceneManager.UnloadScene(sceneName);
            }
#endif
            sceneHandle            = Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            sceneHandle.Completed += ctx => {
                IsLoadingScene = false;

                gameMode = CreateGameModeForScene(sceneName);
                Assert.IsNotNull(gameMode);

                Debug.Log($"[Server] New GameMode <i>{gameMode}</i>");
            };
        }
Example #17
0
        private IEnumerator LoadScene(string name, string suffix, bool isAssetBundle, params string[] types)
        {
#if AssetBundle
            if (isAssetBundle)
            {
#if !UNITY_EDITOR
                string path = GetAssetPath(name, types);
                AsyncOperationHandle <SceneInstance> handler = Addressables.LoadSceneAsync($"Assets/Bundles/{path}{suffix}");
                yield return(handler);
#else
                async = SceneManager.LoadSceneAsync(name);
                async.allowSceneActivation = false;
                yield return(async);
#endif
            }
            else
            {
                async = SceneManager.LoadSceneAsync(name);
                async.allowSceneActivation = false;
                yield return(async);
            }
#else
            async = SceneManager.LoadSceneAsync(name);
            async.allowSceneActivation = false;
            yield return(async);
#endif
        }
Example #18
0
 public void LoadAdresseableScene(string sceneName, bool unloadLastScene)
 {
     if (unloadLastScene)
     {
         Addressables.UnloadSceneAsync(handle, true);
     }
     Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive, true).Completed += AdresseableSceneLoadComplete;
 }
Example #19
0
        public ETTask LoadSceneActive(string sceneName)
        {
            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            var asset = Addressables.LoadSceneAsync(sceneName);

            asset.Completed += op => { tcs.SetResult(); };
            return(tcs.Task);
        }
Example #20
0
 /// <summary>
 /// Addressable 加载场景
 /// </summary>
 /// <param name="key"></param>
 /// <param name="run"></param>
 public void LoadSceneRun(string key, LoadObj <Scene> run = null)
 {
     Addressables.LoadSceneAsync(key).Completed += (obj) =>
     {
         run?.Invoke(obj.Result.Scene);
         Addressables.Release(obj);
     };
 }
        /// <summary>
        /// <para>指定されたアドレスに紐づくシーンに遷移します</para>
        /// </summary>
        public AddressablesControllerHandle LoadSceneAsync
        (
            object address,
            LoadSceneMode loadMode
        )
        {
            var source = new TaskCompletionSource <AddressablesControllerResultCode>();

            if (!m_isInitialized)
            {
                source.TrySetResult(AddressablesControllerResultCode.FAILURE_NOT_INITIALIZED);
                return(new AddressablesControllerHandle(source.Task));
            }

            var isFailure     = false;
            var isNotExistKey = false;

            void OnComplete(AsyncOperationHandle handle)
            {
                m_exceptionHandler -= ExceptionHandler;

                if (isFailure)
                {
                    var resultCode = isNotExistKey
                                                        ? AddressablesControllerResultCode.FAILURE_KEY_NOT_EXIST
                                                        : AddressablesControllerResultCode.FAILURE_CANNOT_CONNECTION
                    ;

                    source.TrySetResult(resultCode);
                    return;
                }

                if (handle.Status != AsyncOperationStatus.Succeeded)
                {
                    source.TrySetResult(AddressablesControllerResultCode.FAILURE_UNKNOWN);
                    return;
                }

                source.TrySetResult(AddressablesControllerResultCode.SUCCESS);
            }

            void ExceptionHandler(Exception exception)
            {
                isFailure     = true;
                isNotExistKey = exception.Message.Contains(nameof(InvalidKeyException));

                m_exceptionHandler -= ExceptionHandler;
            }

            m_exceptionHandler += ExceptionHandler;

            var result = Addressables.LoadSceneAsync(address, loadMode);

            result.Completed += handle => OnComplete(handle);

            return(new AddressablesControllerHandle(result, source.Task));
        }
Example #22
0
        /// <summary>
        /// Loads a scene from an AssetReference
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="loadSceneMode"></param>
        /// <param name="activateOnLoad"></param>
        /// <param name="priority"></param>
        /// <param name="progress"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async UniTask <Scene> LoadSceneFromReferenceAsync(AssetReference reference, LoadSceneMode loadSceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100, IProgress <float> progress = null, CancellationToken cancellationToken = default)
        {
            var asyncOperation = Addressables.LoadSceneAsync(reference, loadSceneMode, activateOnLoad, priority);
            var sceneInstance  = await GetAsyncOperationResultAsync(asyncOperation, progress, cancellationToken);

            Logger.Log($"Loaded Scene: {sceneInstance.Scene.name}".ColoredLog(Colors.Pink));

            return(sceneInstance.Scene);
        }
Example #23
0
        public override void Init()
        {
            Addressables.LoadSceneAsync("Menu");
            view.start.onClick.AddListener(ToStart);
            view.setting.onClick.AddListener(Setting);
            view.quit.onClick.AddListener(Quit);

            Refresh();
        }
Example #24
0
        public void Start()
        {
            if (Handle.IsValid())
            {
                throw new InvalidOperationException();
            }

            Handle = Addressables.LoadSceneAsync(_reference(), LoadSceneMode.Additive);
        }
Example #25
0
    public void Load()
    {
        if (Loaded || _loading)
        {
            return;
        }

        _loading = true;
        Addressables.LoadSceneAsync(ChunkName, LoadSceneMode.Additive).Completed += OnSceneLoaded;
    }
Example #26
0
    public static void LoadSceneAdditive(string key, System.Action onComplete)
    {
        var handle = Addressables.LoadSceneAsync(key, UnityEngine.SceneManagement.LoadSceneMode.Additive);

        handle.Completed += (scene) =>
        {
            onComplete();
            cacheScene.Add(key, handle.Result);
        };
    }
 // Start is called before the first frame update
 public void Load(AssetReference scene)
 {
     Debug.Log("loading level");
     if (!unloaded)
     {
         unloaded = true;
         UnloadScene();
     }
     Addressables.LoadSceneAsync(scene, UnityEngine.SceneManagement.LoadSceneMode.Additive).Completed += SceneLoadCompleted;
 }
 // Start is called before the first frame update
 private void Start()
 {
     JsDictionary = new Dictionary <string, string>();
     Addressables.LoadAssetsAsync <TextAsset>(javaScriptLabelReference, js =>
     {
         JsDictionary.Add(js.name, js.text);
     }).Completed += handle =>
     {
         Addressables.LoadSceneAsync("SampleScene");
     };
 }
    public override void OnEvent(EventData photonEvent)
    {
        byte eventCode = photonEvent.Code;

        if (eventCode != InitGameplayLoadingCode)
        {
            return;
        }

        Addressables.LoadSceneAsync("Gameplay").Completed += SceneLoadComplete;
    }
Example #30
0
        public AsyncOperationHandle <SceneInstance> LoadSceneAsync(
            AssetReferenceSceneAsset sceneReference,
            LoadSceneMode loadMode,
            Action <DiContainer> extraBindings,
            LoadSceneRelationship containerMode,
            Action <DiContainer> extraBindingsLate)
        {
            PrepareForLoadScene(loadMode, extraBindings, extraBindingsLate, containerMode);

            return(Addressables.LoadSceneAsync(sceneReference, loadMode));
        }