示例#1
0
        IEnumerator LoadSceneCoroutine(string sceneName)
        {
            foreach (var observer in OnBeginSceneLoad.Enumerate())
            {
                var task = observer.Do();
                yield return(new WaitUntil(() => task.IsCompleted));
            }

            foreach (var observer in OnCurrentSceneUnload.Enumerate())
            {
                observer.Do();
            }

            var operation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);

            while (!operation.isDone)
            {
                yield return(null);

                foreach (var observer in OnSceneLoadProgress.Enumerate())
                {
                    observer.Do(operation.progress);
                }
            }

            foreach (var observer in OnEndSceneLoad.Enumerate())
            {
                var task = observer.Do();
                yield return(new WaitUntil(() => task.IsCompleted));
            }
        }
示例#2
0
        public SceneHandler UnloadSceneAsync(string address,
                                             OnSceneLoadProgress progress,
                                             OnSceneLoadComplete complete,
                                             SystemObject userData)
        {
            if (assetLoader != null)
            {
                string scenePath = assetLoader.GetAssetPathByAddress(address);
                if (string.IsNullOrEmpty(scenePath))
                {
                    DebugLog.Error(AssetConst.LOGGER_NAME, "scenePath is null.address = " + address);
                    return(null);
                }
                SceneLoaderData data = new SceneLoaderData();
                data.InitUnloadData(address, scenePath, complete, progress, userData);
                loaderDatas.Add(data);

                return(data.handler);
            }
            else
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "assetloader is not init");
                return(null);
            }
        }
示例#3
0
 /// <summary>
 /// 加载场景
 /// </summary>
 /// <param name="pathOrAddress">路径/地址</param>
 /// <param name="completeCallback">场景加载完成委托</param>
 /// <param name="progressCallback">场景加载进度委托</param>
 /// <param name="loadMode">加载方式</param>
 /// <param name="activateOnLoad">是否激活场景,(没有到这个参数呀)</param>
 /// <param name="userData">携带参数</param>asa
 /// <returns></returns>
 public static SceneLoaderHandle LoadSceneAsync(string pathOrAddress,
                                                OnSceneLoadComplete completeCallback,
                                                OnSceneLoadProgress progressCallback,
                                                LoadSceneMode loadMode = LoadSceneMode.Single,
                                                bool activateOnLoad    = true,
                                                SystemObject userData  = null)
 {
     return(AssetMgr.GetInstance().LoadSceneAsync(pathOrAddress, completeCallback, progressCallback, loadMode, activateOnLoad, userData));
 }
示例#4
0
 /// <summary>
 /// 卸载指定的场景
 /// </summary>
 /// <param name="address">场景地址</param>
 /// <param name="complete">卸载完毕后回调</param>
 /// <param name="progress">卸载进度回调</param>
 /// <param name="userData">自定义参数</param>
 /// <returns></returns>
 public SceneHandler UnloadSceneAsync(string address,
                                      OnSceneLoadProgress progress,
                                      OnSceneLoadComplete complete,
                                      SystemObject userData = null)
 {
     if (sceneLoader == null)
     {
         DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::UnloadSceneAsync->loader hasn't been inited");
         return(null);
     }
     return(sceneLoader.UnloadSceneAsync(address, progress, complete, userData));
 }
示例#5
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="pathOrAddress">地址</param>
        /// <param name="completeCallback">完成后回调</param>
        /// <param name="progressCallback">加载进度回调</param>
        /// <param name="loadMode">场景加载模式</param>
        /// <param name="activateOnLoad">是否立即激活</param>
        /// <param name="userData">自定义数据</param>
        /// <returns></returns>
        public SceneLoaderHandle LoadSceneAsync(string pathOrAddress,
                                                OnSceneLoadComplete completeCallback,
                                                OnSceneLoadProgress progressCallback,
                                                LoadSceneMode loadMode = LoadSceneMode.Single,
                                                bool activateOnLoad    = true,
                                                SystemObject userData  = null)
        {
            bool isSceneLoaded = m_LoadedSceneHandles.Any((sHandle) =>
            {
                return(sHandle.PathOrAddress == pathOrAddress);
            });

            if (isSceneLoaded)
            {
                Debug.LogError($"SceneAssetLoader::LoadSceneAsync->Scene has been loaded.pathOrAddress={pathOrAddress}");
                return(null);
            }
            bool isSceneLoading = m_LoadingSceneDatas.Any((loadData) =>
            {
                return(loadData.PathOrAddress == pathOrAddress);
            });

            if (isSceneLoading)
            {
                Debug.LogError($"SceneAssetLoader::LoadSceneAsync->Scene is in loading.pathOrAddress={pathOrAddress}");
                return(null);
            }

            string assetPath = m_AssetLoader.GetAssetPath(pathOrAddress);
            string sceneName = Path.GetFileNameWithoutExtension(assetPath);

            SceneLoadData loaderData = new SceneLoadData();

            loaderData.PathOrAddress    = pathOrAddress;
            loaderData.AssetPath        = assetPath;
            loaderData.CompleteCallback = completeCallback;
            loaderData.ProgressCallback = progressCallback;
            loaderData.LoadMode         = loadMode;
            loaderData.ActivateOnLoad   = activateOnLoad;
            loaderData.UserData         = userData;

            SceneLoaderHandle handle = new SceneLoaderHandle();

            handle.PathOrAddress   = pathOrAddress;
            handle.AssetPath       = assetPath;
            handle.SceneName       = sceneName;
            loaderData.SceneHandle = handle;

            m_LoadingSceneDatas.Add(loaderData);

            return(handle);
        }
示例#6
0
 /// <summary>
 /// 加载场景
 /// </summary>
 /// <param name="pathOrAddress">路径/地址</param>
 /// <param name="completeCallback">场景加载完成委托</param>
 /// <param name="progressCallback">场景加载进度委托</param>
 /// <param name="loadMode">加载方式</param>
 /// <param name="activateOnLoad">是否激活场景,(没有到这个参数呀)</param>
 /// <param name="userData">携带参数</param>
 /// <returns></returns>
 public SceneLoaderHandle LoadSceneAsync(string pathOrAddress,
                                         OnSceneLoadComplete completeCallback,
                                         OnSceneLoadProgress progressCallback,
                                         LoadSceneMode loadMode = LoadSceneMode.Single,
                                         bool activateOnLoad    = true,
                                         SystemObject userData  = null)
 {
     if (m_SceneLoader == null)
     {
         Debug.LogError("AssetManager::LoadSceneAsync->sceneLoader has not been inited");
         return(null);
     }
     return(m_SceneLoader.LoadSceneAsync(pathOrAddress, completeCallback, progressCallback, loadMode, activateOnLoad, userData));
 }
示例#7
0
        /// <summary>
        /// 异步加载并初始化场景。场景的加载分为两步,一是加载场景资源及其依赖资源,二是初始化场景
        /// </summary>
        /// <param name="address">场景地址</param>
        /// <param name="complete">加载及初始化完成后回调</param>
        /// <param name="progress">加载进度回调</param>
        /// <param name="mode">加载模式<see cref="LoadSceneMode"/></param>
        /// <param name="activateOnLoad">场景加载完毕后是否立即激活所有的根结点</param>
        /// <param name="userData">自定义参数</param>
        /// <returns></returns>
        public SceneHandler LoadSceneAsync(string address,
                                           OnSceneLoadProgress progress,
                                           OnSceneLoadComplete complete,
                                           LoadSceneMode mode    = LoadSceneMode.Single,
                                           bool activateOnLoad   = true,
                                           SystemObject userData = null)
        {
            if (sceneLoader == null)
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::LoadSceneAsync->loader hasn't been inited");
                return(null);
            }

            return(sceneLoader.LoadSceneAsync(address, progress, complete, mode, activateOnLoad, userData));
        }
示例#8
0
        public void InitUnloadData(
            string address,
            string path,
            OnSceneLoadComplete complete,
            OnSceneLoadProgress progress,
            SystemObject userData)
        {
            this.address     = address;
            this.scenePath   = path;
            this.sceneName   = Path.GetFileNameWithoutExtension(path);
            completeCallback = complete;
            progressCallback = progress;
            this.userData    = userData;

            handler = new SceneHandler(address, sceneName, scenePath);
            state   = SceneLoaderDataState.Unload;
        }
示例#9
0
        public void InitLoadData(
            string address,
            string path,
            OnSceneLoadComplete complete,
            OnSceneLoadProgress progress,
            LoadSceneMode sceneMode,
            bool isActive,
            SystemObject userData)
        {
            this.address            = address;
            this.scenePath          = path;
            this.sceneName          = Path.GetFileNameWithoutExtension(path);
            completeCallback        = complete;
            progressCallback        = progress;
            this.sceneMode          = sceneMode;
            this.isActiveWhenLoaded = isActive;
            this.userData           = userData;

            handler = new SceneHandler(address, sceneName, scenePath);
            state   = SceneLoaderDataState.Load;
        }