Пример #1
0
    private UnityEngine.Object LoadBundle(string family, string bundlePathName, string assetName, bool persistent, AssetLoader.ObjectCallback callback, AssetLoader.OnDownloading onDownloading, object callbackData)
    {
        if (string.IsNullOrEmpty(assetName))
        {
            return(null);
        }
        long  num   = TimeUtils.BinaryStamp();
        Asset asset = Asset.Create(assetName, family, persistent, false, false);

        AssetCache.CachedAsset        cachedAsset = new AssetCache.CachedAsset();
        AssetCache.ObjectCacheRequest objectCacheRequest;
        if (!AssetCache.HasRequest(asset))
        {
            objectCacheRequest = new AssetCache.ObjectCacheRequest();
            AssetCache.AddRequest(asset, objectCacheRequest);
        }
        else
        {
            objectCacheRequest = AssetCache.GetRequest <AssetCache.ObjectCacheRequest>(asset);
        }
        objectCacheRequest.AddRequester(callback, onDownloading, callbackData);
        AssetCache.StartLoading(asset.Family.ToString());
        if (AssetCache.HasItem(asset))
        {
            cachedAsset = AssetCache.Find(asset);
            cachedAsset.LastRequestTimestamp = num;
            asset = cachedAsset.GetAsset();
        }
        else if (this.m_assetBundleDict.ContainsKey(asset.Family) && this.m_assetBundleDict[asset.Family] != null)
        {
            if (!this.m_assetBundleDict[asset.Family].Contains(asset.Name))
            {
                return(null);
            }
            UnityEngine.Object assetObject = this.m_assetBundleDict[family].Load(assetName, AssetBundleInfo.FamilyInfo[family].TypeOf);
            cachedAsset.SetAsset(asset);
            cachedAsset.SetAssetObject(assetObject);
            cachedAsset.CreatedTimestamp     = num;
            cachedAsset.LastRequestTimestamp = num;
            AssetCache.Add(asset, cachedAsset);
        }
        else if (AssetCache.CanLoadBundle(asset.Family))
        {
            this.LoadBundleFromDisk(asset, objectCacheRequest, cachedAsset);
        }
        if (cachedAsset.GetAssetObject() != null)
        {
            objectCacheRequest.OnProgressUpdate(assetName, 1f);
            objectCacheRequest.OnLoadSucceed();
            objectCacheRequest.OnLoadComplete(assetName, cachedAsset.GetAssetObject());
            AssetCache.RemoveRequest(asset);
            AssetCache.StopLoading(assetName);
        }
        return(cachedAsset.GetAssetObject());
    }
Пример #2
0
    private void LoadBundleFromDisk(Asset asset, AssetCache.ObjectCacheRequest request, AssetCache.CachedAsset cache)
    {
        if (asset == null || request == null || cache == null || this.m_assetBundleDict == null)
        {
            UnityEngine.Debug.LogError("LoadBundleFromDisk some null!");
            return;
        }
        string family = asset.Family;
        string path   = Application.persistentDataPath + "/" + AssetBundleInfo.FamilyInfo[family].BundleName;

        if (!File.Exists(path))
        {
            return;
        }
        AssetBundle value = AssetBundle.CreateFromFile(path);

        if (this.m_assetBundleDict.ContainsKey(family))
        {
            this.m_assetBundleDict[family] = value;
        }
        else
        {
            this.m_assetBundleDict.Add(family, value);
        }
        long num = TimeUtils.BinaryStamp();

        string[] requestDictKeys = AssetCache.GetRequestDictKeys(family);
        for (int i = 0; i < requestDictKeys.Length; i++)
        {
            Asset asset2 = Asset.Create(requestDictKeys[i], family, asset.Persistent, false, false);
            UnityEngine.Object assetObject = this.m_assetBundleDict[family].Load(asset2.Name, AssetBundleInfo.FamilyInfo[family].TypeOf);
            cache.SetAsset(asset2);
            cache.SetAssetObject(assetObject);
            cache.CreatedTimestamp     = num;
            cache.LastRequestTimestamp = num;
            AssetCache.Add(asset2, cache);
            if (cache.GetAssetObject() == null)
            {
                request.OnLoadFailed(asset2.Name);
                AssetCache.RemoveRequest(asset2);
                AssetCache.StopLoading(family.ToString());
            }
        }
        request.OnProgressUpdate(family.ToString(), 1f);
    }