예제 #1
0
    //异步加载
    public void LoadAssetAsync <T>(string path, UnityAction <T> onLoadComplate) where T : Object
    {
        CacheDataInfo info = queryCache(path);

        if (info != null)
        {
            info.UpdateTick();
            if (onLoadComplate != null)
            {
                onLoadComplate(info.CacheObj as T);
            }
        }
        else
        {
            switch (LoadMode)
            {
            case AssetLoadMode.Editor:
                StartCoroutine(editorLoader.LoadAssetAsync <T>(path, onLoadComplate));
                break;

            case AssetLoadMode.AssetBundler:
                StartCoroutine(abLoader.LoadAssetAsync <T>(path, onLoadComplate));
                break;
            }
        }
    }
예제 #2
0
        /// <summary>
        /// Sets the asynchronous.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="item">The item.</param>
        /// <param name="keepAlive">The keep alive.</param>
        /// <returns></returns>
        public async Task SetAsync(string name, object item, TimeSpan?keepAlive = null)
        {
            var cInfo = new CacheDataInfo <object>
            {
                CachedDateTime = DateTime.Now,
                KeepAlive      = keepAlive ?? TimeSpan.Zero,
                NewCacheData   = item,
            };

            await _container.SetAsync(name, _serialier.Serialize(cInfo), keepAlive);
        }
예제 #3
0
    //加入缓冲区
    public void pushCache(string path, Object obj)
    {
        Debug.Log("[AssetManager]加入缓存:" + path);

        lock (cacheDataDic) {
            if (cacheDataDic.ContainsKey(path))
            {
                cacheDataDic[path].UpdateTick();
            }
            else
            {
                CacheDataInfo info = new CacheDataInfo(path, obj);
                cacheDataDic.Add(path, info);
                info.UpdateTick();
            }
        }
    }
예제 #4
0
    //同步加载
    public T LoadAsset <T>(string path) where T : Object
    {
        CacheDataInfo info = queryCache(path);

        if (info != null)
        {
            info.UpdateTick();
            return(info.CacheObj as T);
        }
        else
        {
            switch (LoadMode)
            {
            case AssetLoadMode.Editor:
                return(editorLoader.LoadAsset <T>(path));

            case AssetLoadMode.AssetBundler:
                return(abLoader.LoadAsset <T>(path));
            }
            return(null);
        }
    }
예제 #5
0
 /// <summary>
 /// Determines whether the specified c information has expired.
 /// </summary>
 /// <param name="cInfo">The c information.</param>
 /// <returns>
 ///   <c>true</c> if the specified c information has expired; otherwise, <c>false</c>.
 /// </returns>
 private bool HasExpired(CacheDataInfo cInfo)
 {
     return(cInfo.KeepAlive != TimeSpan.Zero && DateTime.Now.Subtract(cInfo.CachedDateTime) >= cInfo.KeepAlive);
 }