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 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 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(); }
public void StartLoad() { if (isLoading) { return; } var req = mMeta.util.RequestAB(mMeta.path); mReq = req; if (req == null) { 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); } FireComplishEvent(); } else { isLoading = true; req.completed += Complete; } }
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 } }
public static void RunOnMainThread <T1, T2> (System.Action <T1, T2> action, T1 arg1, T2 arg2, ETaskType type = ETaskType.task, int id = 0) { if (sInitilized && action != null) { lock (sInstance.mLock) { var task = sInstance.GetTaskWithArg2 <T1, T2>(id); task.Task = action; task.mArg1 = arg1; task.mArg2 = arg2; if (type == ETaskType.task) { sInstance.mTasks.Enqueue(task); } else if (type == ETaskType.lateTask) { sInstance.mLateTasks.Enqueue(task); } } } #if UNITY_EDITOR else if (!sInitilized && Application.isPlaying) { RTLog.LogError(LogCat.Game, "MainThread not initialized."); } #endif }
// 加载 AB private bool LoadAB <T>(string name, AbMeta ab, AssetHandler <T> handler, ErrorHandler errorhandler, bool loadDependencies = true) where T : Object { if (ab == null) { var error = string.Format("Can't find AssetBundle \"{0}\"", name); #if UNITY_EDITOR RTLog.LogError(LogCat.Asset, error); #endif if (errorhandler != null) { errorhandler(error); } return(false); } if (ab.assetBundle != null) { if (handler != null) { handler(ab.assetBundle as T); } return(false); } bool load = false; // 加载依赖包 if (loadDependencies) { var dependencies = mManifest.GetAllDependencies(ab.name); if (dependencies != null) { for (int i = 0; i < dependencies.Length; i++) { var id = HashAssetID(dependencies[i]); var dab = GlobalUtil.Binsearch(mAbs, id); load |= LoadAB <AssetBundle>(dependencies[i], dab, null, null, false); } } } // 加载 ab var assethandler = GetHandler(ab.Identify); if (assethandler == null) { assethandler = new ABObtain(ab); mHandlers.AddLast(assethandler); mLoaders++; load = true; assethandler.DoComplete(FinishAndLoadNextAsset); } if (handler != null) { assethandler.RegistHandler(handler); } if (errorhandler != null) { assethandler.RegistErrorHandler(errorhandler); } return(load); }
public virtual void Init(JsonData jobj) { #if UNITY_EDITOR if (jobj == null) { RTLog.LogError(LogCat.Table, string.Format("{0}.Init(JObject) must has an instance of JObject parameter", GetType())); return; } mFormatString = string.Format("<{0}>{1}", GetType().Name, jobj.ToJson()); #endif _id = (int)jobj["id"]; }
public static void RemoveLooper(ILooper looper) { if (sInitilized && looper != null) { sInstance.mLoopers.Remove(looper); } #if UNITY_EDITOR else if (!sInitilized && Application.isPlaying) { RTLog.LogError(LogCat.Game, "MainThread not initialized."); } #endif }
public static Coroutine RunCoroutine(IEnumerator cor) { if (sInitilized && cor != null) { return(sInstance.StartCoroutine(cor)); } else { #if UNITY_EDITOR if (!sInitilized && Application.isPlaying) { RTLog.LogError(LogCat.Game, "MainThread not initialized."); } #endif return(null); } }
private static void GenerateTransitions(SerializedObject target, Type type) { var fsm = target.targetObject as FStateMachineMono; var prop = target.FindProperty("m_Transitions"); object[] methods = Ref.GetMethodsWithAttribute <FStateTransitionAttribute>(type, true); if (methods == null) { prop.ClearArray(); return; } List <FiniteStateTransition> transitions = new List <FiniteStateTransition>(); for (int i = 0; i < methods.Length; i++) { System.Reflection.MethodInfo mtd = methods[i] as System.Reflection.MethodInfo; if (!Ref.MatchMethodRetAndParams(mtd, typeof(bool), null)) { RTLog.LogError(LogCat.AI, string.Format("{0} 不能作为状态方法,因为类型不能和 \" bool Method() \" 匹配.", mtd.Name)); continue; } object[] trans = mtd.GetCustomAttributes(typeof(FStateTransitionAttribute), true); for (int j = 0; j < trans.Length; j++) { FStateTransitionAttribute t = trans[j] as FStateTransitionAttribute; FiniteStateTransition ft = new FiniteStateTransition(); ft.m_FromState = t.From ?? ""; //if (!string.IsNullOrEmpty(ft.m_FromState) && !fsm.HasState(ft.m_FromState)) // continue; ft.m_ToState = t.To ?? ""; //if (!string.IsNullOrEmpty(ft.m_ToState) && !fsm.HasState(ft.m_ToState)) // continue; ft.m_ConditionMethod = mtd.Name ?? ""; transitions.Add(ft); } } GlobalUtil.Sort(transitions, (x, y) => string.IsNullOrEmpty(x.m_FromState) || string.IsNullOrEmpty(x.m_ToState) ? 1 : -1); prop.arraySize = transitions.Count; for (int i = 0; i < transitions.Count; i++) { var p = prop.GetArrayElementAtIndex(i); CopyTransitionToSerializedField(transitions[i], p); } }
private void Start() { mAllFree = m_FreeXAxis && m_FreeYAxis && m_FreeZAxis; mLocalTrans = transform.parent; if (!m_LoopTrans && transform.childCount > 0) { m_LoopTrans = transform.GetChild(0); } if (!m_LoopTrans || m_LoopTrans.parent != transform) { enabled = false; #if UNITY_EDITOR RTLog.LogError(LogCat.Game, "'LoopPose' 需要设置一个子节点作为 'Loop Trans'"); #endif return; } Matrix4x4 m = mLocalTrans ? mLocalTrans.worldToLocalMatrix : Matrix4x4.identity; mStartPos = m.MultiplyPoint(m_LoopTrans.position); }
public static ILooper AddLooper(LooperDelegate looper) { if (sInitilized && looper != null) { var loop = new Looper(looper); sInstance.mLoopers.AddLast(loop); return(loop); } else { #if UNITY_EDITOR if (!sInitilized && Application.isPlaying) { RTLog.LogError(LogCat.Game, "MainThread not initialized."); } #endif return(null); } }
public ABAssetsUtil(AssetSetting set) : base() { mHandlers = new LinkedList <IAssetHandler>(); mAssets = new Dictionary <int, AssetMeta>(set.initCapacity); var ab = AssetBundle.LoadFromFile(Path.Combine(set.abFolder, set.manifestName)); if (ab != null) { mManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } if (mManifest == null) { RTLog.LogError(LogCat.Asset, "Lost AssetBundle Manifest File."); mAbs = new AbMeta[0]; } else { var abs = mManifest.GetAllAssetBundles(); mAbs = new AbMeta[abs == null ? 0 : abs.Length]; for (int i = 0; i < mAbs.Length; i++) { mAbs[i] = new AbMeta(this, abs[i], Path.Combine(set.abFolder, abs[i])); } GlobalUtil.Sort(mAbs, (x, y) => x.Identify <= y.Identify ? -1 : 1); for (int i = 0; i < mAbs.Length; i++) { var dependencies = mManifest.GetAllDependencies(mAbs[i].name); if (dependencies == null || dependencies.Length == 0) { continue; } for (int j = 0; j < dependencies.Length; j++) { var meta = GlobalUtil.Binsearch(mAbs, HashAssetID(dependencies[j])); if (meta != null) { meta.AddReferenceTo(mAbs[i].Identify); } } } } }
public static AssetBinder NewSubBinder(AssetBinder binder) { if (binder == null || binder.mRunner == null) { return(null); } if (binder.DeepAsSubTree >= binder.Runner.MaxSubTreeDeep) { var error = string.Format("在创建子行为树是超过了支持的最大深度值:{0}", binder.Runner.MaxSubTreeDeep); #if UNITY_EDITOR UnityEditor.EditorUtility.DisplayDialog("Error", error, "OK"); #endif RTLog.LogError(LogCat.AI, error); return(null); } var subbind = new AssetBinder(binder); subbind.mParent = binder; binder.mSubAssets.Add(subbind); return(subbind); }
public static bool QueryTask(int id, ETaskType type = ETaskType.task) { if (sInitilized && id != 0) { lock (sInstance.mLock) { Queue <ITask> queue; if (type == ETaskType.task) { queue = sInstance.mTasks; } else if (type == ETaskType.lateTask) { queue = sInstance.mLateTasks; } else { queue = null; } if (queue != null) { foreach (var t in queue) { if (t.Identify == id) { return(true); } } } } } #if UNITY_EDITOR else if (!sInitilized && Application.isPlaying) { RTLog.LogError(LogCat.Game, "MainThread not initialized."); } #endif return(false); }
protected override void LoadAssetAsync <T>(string assetPath, AssetHandler <T> handler, ErrorHandler errorhandler = null) { var asset = LoadAsset <T>(assetPath); if (asset == null) { var error = string.Format("Can't load Asset: \"{0}\"", assetPath); #if UNITY_EDITOR if (typeof(T) != typeof(AssetBundle)) { RTLog.LogError(LogCat.Asset, error); } #endif if (errorhandler != null) { errorhandler(error); } } else if (handler != null) { handler(asset); } }
public void Abort() { RTLog.LogError(LogCat.Asset, "Invoke static method \"AssetsUtil.AbortLoadAssetAsync<T>()\" instead of Abort()."); }
private static void GenerateStates(SerializedObject target, Type type) { var prop = target.FindProperty("m_States"); object[] methods = Ref.GetMethodsWithAttribute <FStateAttribute>(type, true); if (methods == null) { prop.ClearArray(); return; } FiniteState tmp; FiniteState defaultState = null; FiniteState firstState = null; Dictionary <string, FiniteState> allstates = new Dictionary <string, FiniteState>(); for (int i = 0; i < methods.Length; i++) { System.Reflection.MethodInfo mtd = methods[i] as System.Reflection.MethodInfo; if (!Ref.MatchMethodRetAndParams(mtd, typeof(void), null)) { RTLog.LogError(LogCat.AI, string.Format("{0} 不能作为状态方法,因为类型不能和 \" void Method() \" 匹配.", mtd.Name)); continue; } object[] states = mtd.GetCustomAttributes(typeof(FStateAttribute), true); for (int j = 0; j < states.Length; j++) { FStateAttribute state = states[j] as FStateAttribute; string sname = state.Name; if (string.IsNullOrEmpty(sname)) { sname = mtd.Name; } if (!allstates.TryGetValue(sname, out tmp)) { tmp = new FiniteState(); tmp.m_StateName = sname; allstates[sname] = tmp; } if (firstState == null) { firstState = tmp; } if (state.IsDefault) { tmp.m_IsDefaultState = true; if (defaultState != null) { defaultState.m_IsDefaultState = false; } defaultState = tmp; } if (state.KeepInStack) { tmp.m_KeepInStack = true; } if (state.IsSubState) { tmp.m_UseSubState = true; } if ((state.Event & EStateEvent.OnBegin) != 0) { tmp.m_BeginMethod = mtd.Name; } if ((state.Event & EStateEvent.OnTick) != 0) { tmp.m_TickMethod = mtd.Name; } if ((state.Event & EStateEvent.OnEnd) != 0) { tmp.m_EndMethod = mtd.Name; } } } if (defaultState == null && firstState != null) { firstState.m_IsDefaultState = true; } prop.arraySize = allstates.Count; int num = 0; foreach (var stat in allstates.Values) { var p = prop.GetArrayElementAtIndex(num++); CopyStateToSerializedField(stat, p); } }
public void StartLoad() { if (isLoading) { return; } if (!mMeta.useAb) { var req = Resources.LoadAsync <T>(mMeta.assetPath); mReq = req; if (req == null) { var error = string.Format("\"{0}\" doesn't exist.", mMeta.assetPath); #if UNITY_EDITOR RTLog.LogError(LogCat.Asset, error); #endif if (OnErrorOccured != null) { OnErrorOccured(error); } FireComplishEvent(); } else { isLoading = true; req.completed += CompleteInnerAsset; } } else if (mMeta.abData != null && mMeta.abData.assetBundle != null) { var req = mMeta.abData.assetBundle.LoadAssetAsync <T>(mMeta.assetPath); if (req == null) { var error = string.Format("\"{0}\" doesn't exist (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(); } else { isLoading = true; req.completed += ComplteABAsset; } } else { var error = string.Format("\"{0}\" doesn't exist (requre 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(); } }