Esempio n. 1
0
    IEnumerator LoadAssetBundle(string relativeUrl)
    {
        XLoadCache loadCache;    
        if (!AssetBundlesCache.TryGetValue(RelativeResourceUrl, out loadCache))
        {
            loadCache = new XLoadCache() { RelativeUrl = RelativeResourceUrl, Ab = null };
            AssetBundlesCache[RelativeResourceUrl] = loadCache;

            CWWWLoader wwwLoader = new CWWWLoader(FullUrl);
            while (!wwwLoader.IsFinished)
                yield return null;

            // 解密
            CAssetBundleParser parser = new CAssetBundleParser(RelativeResourceUrl, wwwLoader.Www.bytes);
            while (!parser.IsFinished)
            {
                yield return null;
            }

            if (parser.Bundle == null)
                CBase.LogError("WWW.assetBundle is NULL: {0}", FullUrl);

            loadCache.Ab = parser.Bundle;

        }
        else
        {
            if (loadCache.IsLoadedFinish)
            {
                yield return null;  // 确保每一次异步都延迟一帧
            }

            while (!loadCache.IsLoadedFinish)
            {
                yield return null; //Wait
            }
        }

        Bundle = loadCache.Ab;

        if (Callback != null)
            Callback(FullUrl, Bundle, CallbackArgs);
    }