Пример #1
0
    // // Update is called once per frame
    // void Update ()
    // {
    //
    // }

    public void Load(string name, ResourceDelegate completeDel)
    {
        if (GameDefines.USE_ASSET_BUNDLE)
        {
            // Parse the relative path
            string url     = string.Empty;
            int    version = -1;
            if (name.IndexOf("file://") == 0)
            {
                // Local download bundle
                url     = name;
                version = -1;
            }
            else
            {
                name    = name.Substring(name.LastIndexOf("/") + 1);
                url     = GameDefines.GetUrlBase() + GetCachePath(name) + name + ".assetbundle";
                version = GetCacheID(name);
            }

            LoadBundle(url, version, completeDel);
        }
        else
        {
            // Use the path relative to Resources
            LoadLocal(name, completeDel);
        }
    }
Пример #2
0
 public void LoadAllAssetBundles()
 {
     foreach (string name in m_resourceList)
     {
         int    cacheID = GetCacheID(name);
         string url     = GameDefines.GetUrlBase() + GetCachePath(name) + name + ".assetbundle";
         if (Caching.IsVersionCached(url, cacheID))
         {
             Debug.Log("----url=" + url + " cached");
         }
         else
         {
             LoadAssetBundle(name, null);
         }
     }
 }
Пример #3
0
    IEnumerator DoLoadAssetBundle(string name, LoaderCallback callback)
    {
        if (GameDefines.IsUseStream())
        {
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(name, out ab))
            {
                string url = GameDefines.GetUrlBase() + name + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                //int cacheID = GetCacheID(name);
                int cacheID = GameDefines.AssetBundleVersion;
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    yield return(0);
                }
                if (www.error != null)
                {
                    Debug.Log("Error: " + name + " " + www.error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + name + "" + www.assetBundle.ToString());

                    if (!m_mBundle.ContainsKey(name))
                    {
                        m_mBundle.Add(name, www.assetBundle);
                    }

                    if (callback != null)
                    {
                        ab = www.assetBundle;
                        bool useMainAsset = true;
                        if (useMainAsset)
                        {
                            callback(ab.mainAsset);
                        }
                        else
                        {
                            callback(ab.LoadAsset(name));
                        }
                    }

                    yield break;
                }
            }
            else
            {
                if (callback != null)
                {
                    bool useMainAsset = true;
                    if (useMainAsset)
                    {
                        callback(ab.mainAsset);
                    }
                    else
                    {
                        callback(ab.LoadAsset(name));
                    }
                }
                yield break;
            }
        }
        else
        {
            Object o = Resources.Load(name);
            if (callback != null)
            {
                callback(o);
            }
            yield break;
        }
    }
Пример #4
0
    public IEnumerator GetLoader(string bundName, string name, bool useMainAsset, LoaderCallback callback)
    {
        if (GameDefines.IsUseStream())
        {
            string url    = "";
            string bundle = bundName;
            if (useMainAsset)
            {
                bundle += "_" + name;
            }
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(bundle, out ab))
            {
                url = GameDefines.GetUrlBase() + GetCachePath(bundle) + bundle + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                int cacheID = GetCacheID(bundle);
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    yield return(0);
                }
                if (www.error != null)
                {
                    Debug.Log("Error: " + www.error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + bundle + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundle, www.assetBundle);
                    ab = www.assetBundle;
                }
            }
            if (useMainAsset)
            {
                if (callback != null)
                {
                    callback(ab.mainAsset);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(ab.LoadAsset(name));
                }
            }
        }
        else
        {
            string res = bundName + "/" + name;
            Object o   = Resources.Load(res);
            if (callback != null)
            {
                callback(o);
            }
            yield break;
        }
    }
Пример #5
0
    public IEnumerator GetUILoader(string name, System.Action <string> callback)
    {
        if (GameDefines.IsUseStream())
        {
            string      url    = "";
            string      bundle = "GUI_" + name;
            AssetBundle ab     = null;
            m_loadingPub.NotifyLoadingName(bundle);
            m_loadingPub.NotifyPhase(1, 1);
            if (!m_mBundle.TryGetValue(bundle, out ab))
            {
                url = GameDefines.GetUrlBase() + GetCachePath(bundle) + bundle + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                int cacheID = GetCacheID(bundle);
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    m_loadingPub.NotifyProgress(www.progress);
                    yield return(0);
                }
                if (www.error != null)
                {
                    m_loadingPub.NotifyProgress(1.0f);
                    Debug.Log("Error: " + www.error);
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + bundle + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundle, www.assetBundle);
                    ab = www.assetBundle;
                }
            }

            m_loadingPub.NotifyProgress(1.0f);
            if (callback != null)
            {
                callback(name);
            }
        }
        else
        {
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(name, out ab))
            {
                m_mBundle.Add(name, ab);
                yield return(null);
            }
            if (callback != null)
            {
                callback(name);
            }
        }
    }
Пример #6
0
    IEnumerator DoLoadBundle(bool bUseCache)
    {
        Debug.Log("Start Load Bundle...");
        bool bSuccess = true;

        int c = 1;

        foreach (string bundName in m_preLoadList)
        {
            m_loadingPub.NotifyLoadingName(bundName);
            m_loadingPub.NotifyPhase(c++, m_preLoadList.Length);
            if (GameDefines.IsUseStream())
            {
                string url = GameDefines.GetUrlBase() + GetCachePath(bundName) + bundName + ".assetbundle";
                Debug.Log("url:" + url);
                WWW www = null;


                int cacheID = GetCacheID(bundName);
                if (cacheID >= 0 && bUseCache)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    m_loadingPub.NotifyProgress(www.progress);
                    yield return(0);
                }
                if (www.error != null)
                {
                    m_loadingPub.NotifyProgress(1.0f);
                    Debug.Log("Error: " + bundName + " " + www.error);
                    bSuccess = false;
                    break;
                }
                else
                {
                    Debug.Log("OK: " + bundName + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundName, www.assetBundle);
                }
            }
            else
            {
                m_loadingPub.NotifyProgress(1.0f);
                Debug.Log("Downloading Local " + bundName.ToLower());
                yield return(new WaitForSeconds(0.05f));
            }
        }

        Debug.Log("work flow end");
        m_preLoadList = null;
        if (bSuccess)
        {
            m_bIsDone = LoadResultEnum.SUCC;
        }
        else
        {
            m_bIsDone = LoadResultEnum.FAIL;
        }

        Debug.Log("Load Result is " + m_bIsDone);
    }