Exemple #1
0
        private UnityEngine.Object FirstSyncLoadAB(ABLoadTask task)
        {
            bool b = LoadAllDependAb(task);

            if (!task.IsScene)
            {
                if (LoadAssetBundle(b, task.AbPath, task.AbRealPath))
                {
                    ABReference abRef = ABReferenceMap[task.AbPath];
                    return(SyncLoadAsset(abRef, task));
                }
                else
                {
                    return(SyncLoadAsset(task));
                }
            }
            else
            {
                // 场景只加载ab
                if (LoadAssetBundle(b, task.AbPath, task.AbRealPath))
                {
                    ABReference abRef = ABReferenceMap[task.AbPath];
                    abRef.ReferenceAsc();
                }
            }
            return(null);
        }
Exemple #2
0
        private void FirstAsyncLoadAB(ABLoadTask task)
        {
            bool b = LoadAllDependAb(task);

            if (!task.IsScene)
            {
                if (LoadAssetBundle(b, task.AbPath, task.AbRealPath))
                {
                    ABReference abRef = ABReferenceMap[task.AbPath];
                    LauncherEngine.Instance.StartCoroutine(AsyncLoadAsset(abRef, task));
                }
                else
                {
                    LauncherEngine.Instance.StartCoroutine(AsyncLoadAsset(task));
                }
            }
            else
            {
                // 场景只加载ab
                if (LoadAssetBundle(b, task.AbPath, task.AbRealPath))
                {
                    ABReference abRef = ABReferenceMap[task.AbPath];
                    abRef.ReferenceAsc();
                }
            }
        }
Exemple #3
0
        private IEnumerator AsyncLoadAsset(ABReference abRef, ABLoadTask task)
        {
            AssetBundleRequest request;

            if (null != task.AbType)
            {
                request = abRef.TheAB.LoadAssetAsync(task.AbName, task.AbType);
            }
            else
            {
                request = abRef.TheAB.LoadAssetAsync(task.AbName);
            }
            while (!request.isDone)
            {
                if (null != task.Progress)
                {
                    task.Progress(request.progress);
                }
                yield return(null);
            }
            yield return(request);

            // 加载完成
            if (request.isDone)
            {
                UnityEngine.Object spawner = request.asset;

                abRef.ReferenceAsc();
                LoadComplete(spawner, task);
            }
        }
Exemple #4
0
        private void NotFirstAsyncLoadAb(ABLoadTask task)
        {
            ABReference abRef = ABReferenceMap[task.AbPath];

            if (!task.IsScene)
            {
                LauncherEngine.Instance.StartCoroutine(AsyncLoadAsset(abRef, task));
            }
            else
            {
            }
        }
Exemple #5
0
        private UnityEngine.Object NotFirstSyncLoadAb(ABLoadTask task)
        {
            ABReference abRef = ABReferenceMap[task.AbPath];

            if (!task.IsScene)
            {
                return(SyncLoadAsset(abRef, task));
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        public void Unload(string abPath)
        {
            if (null == ABReferenceMap)
            {
                return;
            }
            abPath = abPath.ToLower();
            ABReference abRef = null;

            ABReferenceMap.TryGetValue(abPath, out abRef);
            if (null != abRef)
            {
                abRef.ReferenceDec();
            }
        }
Exemple #7
0
        private void FirstAsyncLoadAB(ABLoadTask task)
        {
            LoadAllDependAb(task);
            if (!task.IsScene)
            {
                LoadAssetBundle(task.AbPath);

                ABReference abRef = ABReferenceMap[task.AbPath];
                StartCoroutine(AsyncLoadAsset(abRef, task));
            }
            else
            {
                LoadAssetBundle(task.AbPath);
            }
        }
Exemple #8
0
        private UnityEngine.Object FirstSyncLoadAB(ABLoadTask task)
        {
            LoadAllDependAb(task);
            if (!task.IsScene)
            {
                LoadAssetBundle(task.AbPath);

                ABReference abRef = ABReferenceMap[task.AbPath];
                return(SyncLoadAsset(abRef, task));
            }
            else
            {
                // 场景只加载ab
                LoadAssetBundle(task.AbPath);
            }
            return(null);
        }
Exemple #9
0
        private UnityEngine.Object SyncLoadAsset(ABReference abRef, ABLoadTask task)
        {
            UnityEngine.Object spawner = null;

            if (null != task.AbType)
            {
                spawner = abRef.TheAB.LoadAsset(task.AbName, task.AbType);
            }
            else
            {
                spawner = abRef.TheAB.LoadAsset(task.AbName);
            }

            abRef.ReferenceAsc();
            LoadComplete(spawner, task);

            return(spawner);
        }
Exemple #10
0
        private void AsyncLoadAB(ABLoadTask task)
        {
            ABReference outAbRef = null;

            ABReferenceMap.TryGetValue(task.AbPath, out outAbRef);
            if (null == outAbRef)
            {
                FirstAsyncLoadAB(task);
            }
            else if (null == outAbRef.TheAB)
            {
                ABReferenceMap.Remove(task.AbPath);
                FirstAsyncLoadAB(task);
            }
            else
            {
                NotFirstAsyncLoadAb(task);
            }
        }
Exemple #11
0
        private UnityEngine.Object SyncLoadAB(ABLoadTask task)
        {
            ABReference outAbRef = null;

            ABReferenceMap.TryGetValue(task.AbPath, out outAbRef);
            if (null == outAbRef)
            {
                return(FirstSyncLoadAB(task));
            }
            else if (null == outAbRef.TheAB)
            {
                ABReferenceMap.Remove(task.AbPath);
                return(FirstSyncLoadAB(task));
            }
            else
            {
                return(NotFirstSyncLoadAb(task));
            }
        }
Exemple #12
0
        private void LoadAssetBundle(string abPath)
        {
            string fullPath = ABVersion.CurVersionInfo.GetABFullPath(abPath);

            if (string.IsNullOrEmpty(fullPath))
            {
                Debug.Log("ab路径:" + abPath);
                return;
            }
            Debug.Log("加载热更ab:" + abPath);
            AssetBundle ab = AssetBundle.LoadFromFile(fullPath);

            if (null == ab)
            {
                Debug.LogError("ab load fail : path is :" + fullPath);
            }

            ABReference abRef = new ABReference(ab, abPath);

            ABReferenceMap.Add(abPath, abRef);
        }
Exemple #13
0
        private bool LoadAllDependAb(ABLoadTask task)
        {
            List <string> dependAbs = null;

            ABManifest.TryGetValue(task.AbPath, out dependAbs);

            int length = 0;

            if (null != dependAbs)
            {
                length = dependAbs.Count;
            }

            List <string> needABRef = new List <string>();
            ABReference   outAbRef  = null;

            for (int i = 0; i < length; i++)
            {
                outAbRef = null;
                ABReferenceMap.TryGetValue(dependAbs[i], out outAbRef);
                if (null == outAbRef)
                {
                    needABRef.Add(dependAbs[i]);
                }
                else if (null == outAbRef.TheAB)
                {
                    needABRef.Add(dependAbs[i]);
                    ABReferenceMap.Remove(dependAbs[i]);
                }
            }
            // 加载ab
            foreach (string path in needABRef)
            {
                LoadAssetBundle(false, path);
            }

            return(length > 0);
        }
Exemple #14
0
        private IEnumerator AsyncLoadAsset(ABReference abRef, ABLoadTask task)
        {
            if (null == abRef.TheAB)
            {
                abRef.ReferenceAsc();
                LoadComplete(null, task);
                yield break;
            }

            AssetBundleRequest request;

            if (null != task.AbType)
            {
                request = abRef.TheAB.LoadAssetAsync(task.AbName, task.AbType);
            }
            else
            {
                request = abRef.TheAB.LoadAssetAsync(task.AbName);
            }
            while (!request.isDone)
            {
                if (null != task.Progress)
                {
                    task.Progress(request.progress);
                }
                yield return(null);
            }
            yield return(request);

            // 加载完成
            if (request.isDone)
            {
                abRef.ReferenceAsc();
                LoadComplete(request.asset, task);
            }
        }