예제 #1
0
        private IEnumerator AsyncLoadAsset(ABLoadTask task)
        {
            ResourceRequest request;

            if (null == task.AbType)
            {
                request = Resources.LoadAsync(ABHelper.GetFileFullPathWithoutFtype(task.AbPath));
            }
            else
            {
                request = Resources.LoadAsync(ABHelper.GetFileFullPathWithoutFtype(task.AbPath), task.AbType);
            }
            while (!request.isDone)
            {
                if (null != task.Progress)
                {
                    task.Progress(request.progress);
                }
                yield return(null);
            }
            yield return(request);

            // 加载完成
            if (request.isDone)
            {
                LoadComplete(request.asset, task);
            }
        }
예제 #2
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);
        }
예제 #3
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();
                }
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        private void NotFirstAsyncLoadAb(ABLoadTask task)
        {
            ABReference abRef = ABReferenceMap[task.AbPath];

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

            if (!task.IsScene)
            {
                return(SyncLoadAsset(abRef, task));
            }
            else
            {
                return(null);
            }
        }
예제 #7
0
        public UnityEngine.Object SyncLoad(string abPath, string abName, Type type, bool isScene = false)
        {
            if (!m_isInitialized)
            {
                return(null);
            }
            // 新建任务
            ABLoadTask task = NewLoadTask(abPath, abName, type, null, null, isScene);

            // 任务累加
            m_nowLoadTaskCount++;
            // 进行加载
            return(SyncLoadAB(task));
        }
예제 #8
0
 private UnityEngine.Object SyncLoadAsset(ABLoadTask task)
 {
     UnityEngine.Object spawner;
     if (null == task.AbType)
     {
         spawner = Resources.Load(ABHelper.GetFileFullPathWithoutFtype(task.AbPath));
     }
     else
     {
         spawner = Resources.Load(ABHelper.GetFileFullPathWithoutFtype(task.AbPath), task.AbType);
     }
     LoadComplete(spawner, task);
     return(spawner);
 }
예제 #9
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);
            }
        }
예제 #10
0
        public bool AsyncLoad(string abPath, string abName, Type type, Action <string, UnityEngine.Object> complete, Action <float> progress = null, bool isScene = false)
        {
            if (!m_isInitialized)
            {
                return(false);
            }
            // 新建任务
            ABLoadTask task = NewLoadTask(abPath, abName, type, complete, progress, isScene);

            // 进队列
            m_loadTaskList.Enqueue(task);
            // 开始load
            NextLoadTask();

            return(true);
        }
예제 #11
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);
        }
예제 #12
0
        private void LoadComplete(UnityEngine.Object obj, ABLoadTask task)
        {
            if (null != task.Complete)
            {
                task.Complete(task.AbPath, obj);
            }
            task.ClearAction();

            m_nowLoadTaskCount--;
            NextLoadTask();

            // 回收
            if (!m_loadTaskRecycle.Contains(task))
            {
                m_loadTaskRecycle.Add(task);
            }
        }
예제 #13
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);
        }
예제 #14
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));
            }
        }
예제 #15
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);
            }
        }
예제 #16
0
        private ABLoadTask NewLoadTask(string abPath, string abName, Type type, Action <UnityEngine.Object> complete = null, Action <float> progress = null, bool isScene = false)
        {
            abPath = abPath.ToLower();
            abName = (null == abName) ? ABHelper.GetFileNameWithoutSuffix(abPath) : abName.ToLower();

            // 新建任务
            ABLoadTask task = null;

            if (m_loadTaskRecycle.ContainsKey(abPath) && m_loadTaskRecycle[abPath].Count > 0)
            {
                task = m_loadTaskRecycle[abPath][0];
                m_loadTaskRecycle[abPath].RemoveAt(0);
            }
            else
            {
                task = new ABLoadTask();
            }
            task.Reset(abPath, abName, type, complete, progress, isScene);
            return(task);
        }
예제 #17
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);
        }
예제 #18
0
        private ABLoadTask NewLoadTask(string abPath, string abName, Type type, Action <string, UnityEngine.Object> complete = null, Action <float> progress = null, bool isScene = false)
        {
            bool   fromNativePath = true;
            string abRealPath     = ABVersion.CurVersionInfo.GetABFullPath(abPath, ref fromNativePath);

            abPath = abPath.ToLower();
            abName = (null == abName) ? ABHelper.GetFileNameWithoutSuffix(abPath) : abName.ToLower();

            // 新建任务
            ABLoadTask task = null;

            if (m_loadTaskRecycle.Count > 0)
            {
                task = m_loadTaskRecycle[0];
                m_loadTaskRecycle.RemoveAt(0);
            }
            else
            {
                task = new ABLoadTask();
            }
            task.Reset(abPath, abName, abRealPath, type, complete, progress, isScene);
            return(task);
        }
예제 #19
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);
            }
        }