void ComplteABAsset(AsyncOperation oper) { var req = oper as AssetBundleRequest; if (req != null && req.asset != null) { mMeta.assetInstence = req.asset; #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "\"{0}\" was loaded(AssetBundle: {1}).", mMeta.assetPath, mMeta.abData == null ? "Unkown" : mMeta.abData.name); #endif if (OnHandleAsset != null) { OnHandleAsset(mMeta.assetInstence as T); } } else { var error = string.Format("\"{0}\" load faild(AssetBundle: {1}).", mMeta.assetPath, mMeta.abData == null ? "Unkown" : mMeta.abData.name); #if UNITY_EDITOR RTLog.LogError(LogCat.Asset, error); #endif if (OnErrorOccured != null) { OnErrorOccured(error); } } FireComplishEvent(); }
void OnTableThread(object state) { #if UNITY_EDITOR RTLog.LogFormat(LogCat.Table, "Begin Thread[{0}]", mThreadState.name); #endif try { while (mThreadState.isAlive) { ITableLoader loader = null; lock (mLock) { IsLoading = mLoaders.Count > 0; if (!IsLoading) { //mThread = null; mThreadState.isAlive = false; break; } loader = mLoaders.Dequeue(); mTaskQueue.Remove(loader.Identify); } if (mThreadState.isAlive) { MainThread.RunOnMainThread(loader.StartLoad); } while (mThreadState.isAlive && !loader.IsReady) { #if UNITY_EDITOR if (!MainThread.IsInitilized) { mThreadState.isAlive = false; } MainThread.RunOnMainThread((x) => { if (!Application.isPlaying) { x.isAlive = false; } }, mThreadState); #endif Thread.Sleep(200); } if (mThreadState.isAlive) { loader.LoadAsTable(); } } } catch (System.Exception e) { RTLog.LogError(LogCat.Table, e.ToString()); } finally { Abort(); MainThread.RunOnMainThread(NotifyComplete); #if UNITY_EDITOR RTLog.LogFormat(LogCat.Table, "End Thread[{0}]", mThreadState.name); #endif } }
void CompleteInnerAsset(AsyncOperation oper) { isLoading = false; var req = oper as ResourceRequest; if (req != null && req.asset != null) { mMeta.assetInstence = req.asset; #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "\"{0}\" was loaded.", mMeta.assetPath); #endif if (OnHandleAsset != null) { OnHandleAsset(mMeta.assetInstence as T); } } else { var error = string.Format("\"{0}\" load faild.", mMeta.assetPath); #if UNITY_EDITOR RTLog.LogError(LogCat.Asset, error); #endif if (OnErrorOccured != null) { OnErrorOccured(error); } } FireComplishEvent(); }
void Complete(AsyncOperation oper) { AssetBundleCreateRequest req = oper as AssetBundleCreateRequest; if (req != null && req.assetBundle != null) { mMeta.SetAssetBundle(req.assetBundle); #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "AssetBundle \"{0}\" was loaded.", mMeta.name); #endif if (OnHandleAsset != null) { OnHandleAsset(mMeta.assetBundle); } } else { var error = string.Format("Can't find AssetBundle[{0}]", mMeta.name); #if UNITY_EDITOR RTLog.LogError(LogCat.Asset, error); #endif if (OnErrorOccured != null) { OnErrorOccured(error); } } isLoading = false; FireComplishEvent(); }
protected override void UnloadAsset(string assetPath) { var id = HashAssetID(assetPath); var ab = GlobalUtil.Binsearch(mAbs, id); if (ab != null) { ab.Unload(); } else { var meta = GetMeta(id); if (meta != null && meta.assetInstence != null) { if (!meta.useAb) { Resources.UnloadAsset(meta.assetInstence); } meta.assetInstence = null; #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "Unload asset: \"{0}\"", assetPath); #endif } } }
public static void Release() { if (mInstance != null) { mInstance.OnDestroy(); #if UNITY_EDITOR RTLog.LogFormat(LogCat.Game, "Release Singleton<{0}>.", mInstance.GetType()); #endif mInstance = null; } }
public static T GetOrNewInstance() { if (mInstance == null) { #if UNITY_EDITOR mNewInstance = true; #endif mInstance = new T(); mInstance.OnInit(); #if UNITY_EDITOR mNewInstance = false; RTLog.LogFormat(LogCat.Game, "Instance Singleton<{0}>.", mInstance.GetType()); #endif } return(mInstance); }
protected override T LoadAsset <T>(string assetPath) { if (typeof(T) == typeof(AssetBundle)) { var ab = GlobalUtil.Binsearch(mAbs, HashAssetID(assetPath)); #if UNITY_EDITOR if (ab == null || ab.assetBundle == null) { RTLog.LogErrorFormat(LogCat.Asset, "Faild to load AssetBundle[{0}], sync load ab only support for cached assets.", assetPath); } #endif return(ab == null ? null : ab.assetBundle as T); } else { var meta = GetOrNewMeta(assetPath); var holder = GetHandler(meta.Identify); if (holder != null) { #if UNITY_EDITOR RTLog.LogErrorFormat(LogCat.Asset, "Faild to load asset \"{0}\", because of another async loading of this asset.", assetPath); #endif return(null); } if (meta.assetInstence == null) { if (!meta.useAb) { meta.assetInstence = Resources.Load <T>(assetPath); } else if (meta.abData != null && meta.abData.assetBundle != null) { meta.assetInstence = meta.abData.assetBundle.LoadAsset <T>(assetPath); } #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "\"{0}\" was loaded(AssetBundle: {1}).", meta.assetPath, meta.abData == null ? "Unkown" : meta.abData.name); #endif } return(meta.assetInstence as T); } }
public void LoadAsTable() { if (!string.IsNullOrEmpty(mData)) { if (mMerge) { TableSet <T> .MergeTo(TableSet <T> .LoadAsNew(mFile, mData), mTable); } else { TableSet <T> .LoadTo(mFile, mData, mTable); } #if UNITY_EDITOR RTLog.LogFormat(LogCat.Table, "{0} Table<{1}> @ {2}", mMerge ? "Merge" : "Load", typeof(T).Name, AssetPath); #endif } else { TableSet <T> .LoadComplete(mTable, mMerge); } }
public void Unload() { if (assetBundle != null) { foreach (var meta in util.mAssets.Values) { if (meta.abData == this) { #if UNITY_EDITOR if (meta.assetInstence != null) { RTLog.LogFormat(LogCat.Asset, "Unload asset: \"{0}\"", meta.assetPath); } #endif meta.assetInstence = null; } } assetBundle.Unload(true); assetBundle = null; #if UNITY_EDITOR RTLog.LogFormat(LogCat.Asset, "Unload ab: \"{0}\"", name); #endif } }