Example #1
0
        private static void LoadAssetAsyncWithType <T> (string path, string groupName) where T : UnityEngine.Object
        {
            if (groupName == null)
            {
                groupName = Stage.currentSceneName;
            }

                        #if UNITY_EDITOR
            if (Common.IsDebug)
            {
                if (!File.Exists(Constants.ResDirPath + path))
                {
                    throw new LuaException(string.Format(Constants.E5001, path));
                }

                DispatchLuaEvent(EVENT_START, path);
                Common.looper.StartCoroutine(DispatchCompleteEvent(path,
                                                                   UnityEditor.AssetDatabase.LoadAssetAtPath <T> (Constants.ResDirPath + path)
                                                                   ));
                return;
            }

            string pathMD5 = GetPathMD5(path);
            if (!s_resDic.ContainsKey(pathMD5))
            {
                throw new LuaException(string.Format(Constants.E5001, path));
            }
                        #endif

            s_delayedUnloadList.Remove(groupName);

            ABI abi = GetAbiWithAssetPath(path);
            abi.AddAssetAsync(path, typeof(T));
            ABLoader.LoadAsync(abi, groupName);
        }
Example #2
0
        private static T LoadAssetWithType <T> (string path, string groupName) where T : UnityEngine.Object
        {
            if (groupName == null)
            {
                groupName = Stage.currentSceneName;
            }

                        #if UNITY_EDITOR
            if (Common.IsDebug)
            {
                if (!File.Exists(Constants.ResDirPath + path))
                {
                    throw new LuaException(string.Format(Constants.E5001, path));
                }
                return(UnityEditor.AssetDatabase.LoadAssetAtPath <T> (Constants.ResDirPath + path));
            }

            string pathMD5 = GetPathMD5(path);
            if (!s_resDic.ContainsKey(pathMD5))
            {
                throw new LuaException(string.Format(Constants.E5001, path));
            }
                        #endif

            s_delayedUnloadList.Remove(groupName);

            ABI abi = GetAbiWithAssetPath(path);
            ABLoader.Load(abi, groupName);
            return(abi.ab.LoadAsset <T> (Constants.ResDirPath + path));
        }
Example #3
0
        private static IEnumerator DoLoadSubSceneAsync(string sceneName)
        {
            if (!Common.IsDebug)
            {
                // 先异步加载场景对应的 AssetBundle
                ABI abi = ResManager.GetAbi(ResManager.GetPathMD5(sceneName));
                if (abi.ab == null)
                {
                    ABLoader.ParseFilePath(abi);
                    s_abcr = AssetBundle.LoadFromFileAsync(abi.filePath);
                    yield return(s_abcr);

                    abi.ab = s_abcr.assetBundle;
                    s_abcr = null;
                }
            }

            // 再异步加载 SubScene
            s_ao = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            s_ao.allowSceneActivation = false;
            while (!s_ao.isDone)
            {
                if (s_ao.progress >= 0.9f)
                {
                    s_ao.allowSceneActivation = true;
                }
                yield return(null);
            }
            s_ao           = null;
            s_subCoroutine = null;
            DispatchLuaEvent(EVENT_SUB_COMPLETE, sceneName);
        }
Example #4
0
        /// <summary>
        /// 同步加载场景
        /// </summary>
        /// <param name="sceneName">Scene path.</param>
        public static void LoadScene(string sceneName)
        {
            UnloadSubSceneAssetBundle();

                        #if UNITY_EDITOR
            if (Common.IsDebug)
            {
                // [ Editor Play Mode ] 请将要加载的场景(在 Assets/Res/Scene/ 目录下)加入到 [ Build Settings -> Scenes In Build ] 中
                SceneManager.LoadScene(sceneName);
                return;
            }
                        #endif

            // 这两个是随包走的场景
            if (sceneName != Constants.LauncherSceneName && sceneName != Constants.EmptySceneName)
            {
                ABI abi = ResManager.GetAbi(ResManager.GetPathMD5(sceneName));
                if (abi.ab == null)
                {
                    ABLoader.ParseFilePath(abi);
                    abi.ab = AssetBundle.LoadFromFile(abi.filePath);                     // 先加载场景对应的 AssetBundle
                }
            }

            Common.looper.StartCoroutine(UnloadSceneAssetBundle(s_sceneName));
            s_sceneName = sceneName;
            SceneManager.LoadScene(sceneName);             // 再载入场景
        }
Example #5
0
 /// <summary>
 /// 添加一个需要异步加载的资源
 /// </summary>
 /// <param name="path">Path.</param>
 public void AddAssetAsync(string path, Type type)
 {
     if (!loadAssetsAsync.Contains(path) && !ABLoader.LoadAssetListContains(path))
     {
         ABLoader.assetCount++;
         loadAssetsAsync.Add(path);
         loadAssetsTypeAsync.Add(type);
     }
 }
Example #6
0
        private static IEnumerator DelayedUnload(string groupName, float delay)
        {
            // 先添加到需要被延迟卸载到列表中,以防 delay 过程中该 groupName 又进行了加载
            s_delayedUnloadList.Add(groupName);

            yield return(new WaitForSeconds(delay));

            if (s_delayedUnloadList.Contains(groupName))
            {
                s_delayedUnloadList.Remove(groupName);
                ABLoader.RemoveReference(groupName);
            }
        }
Example #7
0
        /// <summary>
        /// 卸载资源
        /// </summary>
        /// <param name="groupName">Group name.</param>
        /// <param name="delay">Delay.</param>
        public static void Unload(string groupName, float delay = 0)
        {
                        #if UNITY_EDITOR
            if (Common.IsDebug)
            {
                return;
            }
                        #endif

            if (delay > 0)
            {
                Common.looper.StartCoroutine(DelayedUnload(groupName, delay));
            }
            else
            {
                ABLoader.RemoveReference(groupName);
            }
        }
Example #8
0
        /// <summary>
        /// 同步加载 Sub 场景
        /// </summary>
        /// <param name="sceneName">Scene name.</param>
        public static void LoadSubScene(string sceneName)
        {
            s_subSceneNames.Add(sceneName);

                        #if UNITY_EDITOR
            if (Common.IsDebug)
            {
                SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
                return;
            }
                        #endif

            // 先加载场景对应的 AssetBundle
            ABI abi = ResManager.GetAbi(ResManager.GetPathMD5(sceneName));
            if (abi.ab == null)
            {
                ABLoader.ParseFilePath(abi);
                abi.ab = AssetBundle.LoadFromFile(abi.filePath);
            }
            // 再载入场景
            SceneManager.LoadScene(sceneName);
        }
Example #9
0
        private static IEnumerator DoLoadSceneAsync()
        {
            DispatchLuaEvent(EVENT_START, s_sceneName);
            ABI abi = ResManager.GetAbi(ResManager.GetPathMD5(s_sceneName));

            if (abi.ab == null)
            {
                // 先异步加载场景对应的 AssetBundle
                ABLoader.ParseFilePath(abi);
                s_abcr = AssetBundle.LoadFromFileAsync(abi.filePath);
                yield return(s_abcr);

                abi.ab = s_abcr.assetBundle;
                s_abcr = null;
            }

            // 再异步加载场景
            s_ao = SceneManager.LoadSceneAsync(s_sceneName);
            yield return(s_ao);

            s_ao           = null;
            s_alcCoroutine = null;
            DispatchLuaEvent(EVENT_COMPLETE, s_sceneName);
        }
Example #10
0
 /// <summary>
 /// 获取当前异步加载总进度 0~1
 /// </summary>
 /// <returns>The progress.</returns>
 public static float GetProgress()
 {
     return(ABLoader.GetProgress());
 }