Exemplo n.º 1
0
 public override AssetAsyncLoad LoadAssetAsync(string assetName, UnityAction <Object> loadedCallback, UnityAction <float> progressCallback, AssetLoadPriority priority = AssetLoadPriority.Normal)
 {
     if (m_CurrentLoadTask != null)
     {
         if (m_AssetLoadList[(int)priority].ContainsKey(assetName))
         {
             var loadTask = m_AssetLoadList[(int)priority][assetName];
             loadTask.AssetName = assetName;
             var asyncLoad = new AssetAsyncLoad(assetName);
             loadTask.AddCallback(asyncLoad, loadedCallback, progressCallback);
             return(asyncLoad);
         }
         else
         {
             var loadTask = AssetLoadTask.GetAssetLoadTask();
             loadTask.AssetName = assetName;
             var asyncLoad = new AssetAsyncLoad(assetName);
             loadTask.AddCallback(asyncLoad, loadedCallback, progressCallback);
             m_AssetLoadList[(int)priority].Add(assetName, loadTask);
             return(asyncLoad);
         }
     }
     else
     {
         var loadTask = AssetLoadTask.GetAssetLoadTask();
         loadTask.AssetName = assetName;
         var asyncLoad = new AssetAsyncLoad(assetName);
         loadTask.AddCallback(asyncLoad, loadedCallback, progressCallback);
         m_CurrentLoadTask = loadTask;
         StartLoadAsset();
         return(asyncLoad);
     }
 }
Exemplo n.º 2
0
        IEnumerator LoadAsset(string assetName)
        {
            var loadRequest = Resources.LoadAsync(assetName);

            if (m_CurrentLoadTask.HasProgressCallback)
            {
                while (!loadRequest.isDone)
                {
                    m_CurrentLoadTask.SafeInvokeAllProgressCallback(loadRequest.progress);
                    yield return(null);
                }
            }
            else
            {
                yield return(loadRequest);
            }


            m_AssetLoadDoneEvent.Invoke(assetName, loadRequest.asset);
            m_CurrentLoadTask.SafeInvokeAllCallback(loadRequest.asset);

            AssetLoadTask.ReleaseAssetLoadTask(m_CurrentLoadTask);
            m_CurrentLoadTask = PopAssetLoadTask();

            while (m_CurrentLoadTask != null)
            {
                var asset = AssetManager.Instance.ContainAsset(m_CurrentLoadTask.AssetName);
                if (asset == null)
                {
                    break;
                }

                m_CurrentLoadTask.SafeInvokeAllCallback(asset);
                m_CurrentLoadTask = PopAssetLoadTask();
            }

            if (m_CurrentLoadTask != null)
            {
                StartLoadAsset();
            }
        }
Exemplo n.º 3
0
        IEnumerator LoadAsset(string assetName)
        {
            GetAssetDependencesForAysnc(assetName);
            Object asset = null;

            var progress = 0f;
            var count    = m_AssetAsyncLoadOrder.Count;

            for (int i = 0; i < count; ++i)
            {
                var loadAssetName = m_AssetAsyncLoadOrder[i];
                asset = AssetManager.Instance.ContainAsset(loadAssetName);
                if (asset != null)
                {
                    continue;
                }

                var assetBundlePath = m_AssetDependences[loadAssetName].AssetBundlePath;
                var assetBundle     = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                AssetBundleRequest assetbundleRequest = null;
                if (assetBundle != null)
                {
                    if (m_CurrentLoadTask.HasProgressCallback)
                    {
                        var deltaProgress = 1f / count;
                        assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                        while (!assetbundleRequest.isDone)
                        {
                            var tempProgress = progress + deltaProgress * assetbundleRequest.progress;
                            m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                            yield return(null);
                        }

                        progress += deltaProgress;
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress);
                    }
                    else
                    {
                        assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                        yield return(assetbundleRequest);
                    }

                    asset = assetbundleRequest.asset;
                    m_AssetLoadDoneEvent(loadAssetName, asset);
                    m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath);
                    continue;
                }

                WWW www = null;
                if (m_CurrentLoadTask.HasProgressCallback)
                {
                    var deltaProgress = 1f / count;
                    www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath));
                    while (!www.isDone)
                    {
                        var tempProgress = progress + deltaProgress * 0.5f * www.progress;
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                        yield return(null);
                    }

                    assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                    if (assetBundle == null)
                    {
                        assetBundle = www.assetBundle;
                    }
                    assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));

                    while (!assetbundleRequest.isDone)
                    {
                        var tempProgress = progress + deltaProgress * 0.5f * (1 + assetbundleRequest.progress);
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                        yield return(null);
                    }

                    progress += deltaProgress;
                    m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress);
                }
                else
                {
                    www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath));
                    yield return(www);

                    assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                    if (assetBundle == null)
                    {
                        assetBundle = www.assetBundle;
                    }
                    assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                    yield return(assetbundleRequest);
                }

                asset = assetbundleRequest.asset;
                m_AssetLoadDoneEvent(loadAssetName, asset);

                m_AssetBundleCollector.AddAssetBundle(assetBundlePath, assetBundle);
                m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath);
            }

            m_AssetLoadDoneEvent.Invoke(assetName, asset);
            m_CurrentLoadTask.SafeInvokeAllCallback(asset);

            AssetLoadTask.ReleaseAssetLoadTask(m_CurrentLoadTask);
            m_CurrentLoadTask = PopAssetLoadTask();

            while (m_CurrentLoadTask != null)
            {
                asset = AssetManager.Instance.ContainAsset(m_CurrentLoadTask.AssetName);
                if (asset == null)
                {
                    break;
                }

                m_CurrentLoadTask.SafeInvokeAllCallback(asset);
                m_CurrentLoadTask = PopAssetLoadTask();
            }

            if (m_CurrentLoadTask != null)
            {
                StartLoadAsset();
            }
        }
Exemplo n.º 4
0
 public static void ReleaseAssetLoadTask(AssetLoadTask target)
 {
     s_AssetLoadTasks.Release(target);
 }