Beispiel #1
0
    IEnumerator createBundleAsset(Asset asset, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData, bool persistent = false, bool loadAsync = false)
    {
        yield return(StartCoroutine(makeBundleCached(asset)));

        WWW bundle = GetBundle(asset);

        if (bundle == null)
        {
            Log.Asset.Print("AssetLoader.createBundleAsset() - bundle is not in cache");
            yield return(null);
        }
        else
        {
            Object target = bundle.assetBundle.Load(asset.Name);
            if (target == null)
            {
                Log.Asset.Print("AssetLoader.createBundleAsset() - load res from bundle error,asset name is:" + asset.Name);
                yield return(null);
            }
            else
            {
                CacheAsset(asset, target);
                if (callback != null)
                {
                    callback(asset.Name, target, callbackData);
                }
            }
        }
    }
Beispiel #2
0
 public void AddRequester(AssetLoader.ObjectCallback callback, object callbackData)
 {
     AssetCache.ObjectRequester item = new AssetCache.ObjectRequester {
         m_callback     = callback,
         m_callbackData = callbackData
     };
     this.m_requesters.Add(item);
 }
Beispiel #3
0
 public void OnLoadComplete(string name, UnityEngine.Object asset)
 {
     foreach (AssetCache.ObjectRequester requester in this.m_requesters)
     {
         AssetLoader.ObjectCallback callback = requester.m_callback;
         if (GeneralUtils.IsCallbackValid(callback))
         {
             callback(name, asset, requester.m_callbackData);
         }
     }
 }
Beispiel #4
0
 public void OnLoadComplete(string name, UnityEngine.Object asset)
 {
     foreach (AssetCache.ObjectRequester current in this.m_requesters)
     {
         AssetLoader.ObjectCallback callback = current.m_callback;
         if (callback != null)
         {
             callback(name, asset, current.m_callbackData);
         }
     }
 }
Beispiel #5
0
    private bool LoadObject(string assetName, AssetFamily family, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData, bool persistent = false, bool loadAsync = false)
    {
        if (string.IsNullOrEmpty(assetName))
        {
            Log.Asset.Print("AssetLoader.LoadObject() - name was null or empty");
            return(false);
        }
        Asset  asset  = Asset.Create(assetName, family, persistent, loadAsync, false);
        Object target = getInCache(asset);

        if (target != null)        //got in cache
        {
            if (callback != null)
            {
                callback(asset.Name, target, callbackData);
            }
            return(true);
        }
        else
        {
            if (asset.loadModel() == Asset.LoadModel.FromBundle)
            {
                StartCoroutine(createBundleAsset(asset, callback, progressCallback, callbackData, persistent, loadAsync));
            }
            else if (asset.loadModel() == Asset.LoadModel.FromResources)
            {
                Object obj = Resources.Load(asset.GetPath());
                if (obj == null)
                {
                    Log.Asset.Print("AssetLoader.LoadObject() - load object from Resources was failed ,path is:" + asset.GetPath());
                }
                else
                {
                    CacheAsset(asset, obj);
                    if (callback != null)
                    {
                        callback(asset.Name, obj, callbackData);
                    }
                }
            }
        }
        return(true);
    }
Beispiel #6
0
 public bool LoadUIScreen(string screenName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback)
 {
     return(this.LoadUIScreen(screenName, callback, progressCallback, null));
 }
Beispiel #7
0
 public bool LoadUIScreen(string screenName, AssetLoader.ObjectCallback callback, object callbackData)
 {
     return(this.LoadUIScreen(screenName, callback, null, callbackData));
 }
Beispiel #8
0
 public bool LoadTexture(string textureName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback)
 {
     return(this.LoadTexture(textureName, callback, progressCallback, null));
 }
Beispiel #9
0
 public bool LoadTexture(string textureName, AssetLoader.ObjectCallback callback, object callbackData)
 {
     return(this.LoadTexture(textureName, callback, null, callbackData));
 }
Beispiel #10
0
 public bool LoadGameObject(string name, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData, bool persistent, bool loadAsync)
 {
     return(this.LoadObject(name, AssetFamily.GameObject, callback, progressCallback, callbackData, persistent, loadAsync));
 }
Beispiel #11
0
 public bool LoadGameObject(string name, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback)
 {
     return(this.LoadGameObject(name, callback, progressCallback, null));
 }
Beispiel #12
0
 public bool LoadSound(string soundName, AssetLoader.ObjectCallback callback)
 {
     return(this.LoadSound(soundName, callback, null));
 }
Beispiel #13
0
 public bool LoadConfig(string fileName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback)
 {
     return(this.LoadConfig(fileName, callback, progressCallback, null, false));
 }
Beispiel #14
0
 public bool LoadConfig(string fileName, AssetLoader.ObjectCallback callback, object callbackData)
 {
     return(this.LoadConfig(fileName, callback, null, callbackData, false));
 }
Beispiel #15
0
 public bool LoadConfig(string fileName, AssetLoader.ObjectCallback callback)
 {
     return(this.LoadConfig(fileName, callback, null));
 }
Beispiel #16
0
 public bool LoadUIScreen(string screenName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData)
 {
     return(this.LoadObject(screenName, AssetFamily.Texture, callback, progressCallback, callbackData, false, false));
 }
Beispiel #17
0
 public bool LoadGameObject(string name, AssetLoader.ObjectCallback callback, object callbackData)
 {
     return(this.LoadGameObject(name, callback, null, callbackData));
 }
Beispiel #18
0
 public bool LoadSound(string soundName, AssetLoader.ObjectCallback callback, object callbackData)
 {
     return(this.LoadSound(soundName, callback, null, callbackData, false));
 }
Beispiel #19
0
 public bool LoadGameObject(string name, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData, bool persistent)
 {
     return(this.LoadGameObject(name, callback, progressCallback, callbackData, persistent, false));
 }
Beispiel #20
0
 public bool LoadSound(string soundName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback)
 {
     return(this.LoadSound(soundName, callback, progressCallback, null, false));
 }
Beispiel #21
0
 public bool LoadSound(string soundName, AssetLoader.ObjectCallback callback, AssetLoader.ProgressCallback progressCallback, object callbackData, bool persistent)
 {
     return(this.LoadObject(soundName, AssetFamily.Config, callback, progressCallback, callbackData, persistent, false));
 }
    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());
    }