/// <summary> /// 移除事件 /// </summary> /// <param name="eventKey">事件的key,可以是对象,字符</param> /// <param name="hander">事件处理者</param> public void RemoveListener(object eventKey, CFAction <object, GameEventArgs> hander) { if (eventMap.ContainsKey(eventKey)) { eventMap[eventKey] -= hander; } }
/// <summary> /// 注册对象池 /// </summary> /// <param name="objKey"></param> /// <param name="spawnItem"></param> /// <param name="onSpawn"></param> /// <param name="onDespawn"></param> public void RegisterSpawnPool(object objKey, GameObject spawnItem, CFAction <GameObject> onSpawn, CFAction <GameObject> onDespawn) { if (!spawnPool.ContainsKey(objKey)) { spawnPool.Add(objKey, new ObjectSpawnPool(spawnItem, onSpawn, onDespawn)); } }
public static void IsNull(object obj, CFAction nullCallBack) { if (obj == null) { nullCallBack?.Invoke(); } }
public void AddListener(CFAction act, UpdateType type) { switch (type) { case UpdateType.FixedUpdate: if (((short)CheckActionsState(fixedUpdateCount, MonoManager._FixedUpdateCapacity)) == 1) { return; } fixedUpdateActions += act; ++fixedUpdateCount; break; case UpdateType.Update: if (((short)CheckActionsState(updateCount, MonoManager._UpdateCapacity)) == 1) { return; } updateActions += act; ++updateCount; break; case UpdateType.LateUpdate: if (((short)CheckActionsState(lateUpdateCount, MonoManager._LateUpdateCapacity)) == 1) { return; } lateUpdateActions += act; ++lateUpdateCount; break; } }
public void ParseXml(TextAsset ta, CFAction <XmlDocument> callBack) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(ta.text); callBack(xmlDoc); }
public void RemoveListener(CFAction act, UpdateType type) { switch (type) { case UpdateType.FixedUpdate: if (((short)CheckActionsState(fixedUpdateCount, MonoManager._FixedUpdateCapacity)) != -1) { return; } fixedUpdateActions -= act; --fixedUpdateCount; break; case UpdateType.Update: if (((short)CheckActionsState(updateCount, MonoManager._UpdateCapacity)) != -1) { return; } updateActions -= act; --updateCount; break; case UpdateType.LateUpdate: if (((short)CheckActionsState(lateUpdateCount, MonoManager._LateUpdateCapacity)) != -1) { return; } lateUpdateActions -= act; --lateUpdateCount; break; } }
/// <summary> /// Assert断言仅用于测试环境调试 /// 条件委托是否为true /// </summary> /// <param name="handler">条件委托</param> /// <param name="trueCallBack">true时候的回调</param> public static void Predicate(CFPredicateAction handler, CFAction trueCallBack) { if (handler.Invoke()) { trueCallBack?.Invoke(); } }
/// <summary> /// Assert断言仅用于测试环境调试 /// 是否为继承 /// </summary> /// <typeparam name="T1">super</typeparam> /// <typeparam name="T2">sub</typeparam> /// <param name="callBack">若不为继承,则启用回调</param> public static void IsAssignable <T1, T2>(CFAction callBack) { if (!typeof(T1).IsAssignableFrom(typeof(T2))) { callBack?.Invoke(); } }
/// <summary> /// 初始化条件任务的新实例。 /// </summary> public ConditionalTask() { m_Condition = null; m_CompleteAction = null; m_FailureAction = null; m_CancelAction = null; }
public void ParseJson <T>(string jsonFullPath, CFAction <T> callBack) where T : new() { TextAsset ta = Facade.Instance.Load <TextAsset>(jsonFullPath); dataProcess.ParseJson <T>(ta, callBack); }
public Coroutine DelayCoroutine(float delay, CFAction callBack) { if (monoControllerCount == 0) { CreateMonoController(); } return((monoMap[monoControllerCount] as MonoController).DelayCoroutine(delay, callBack)); }
/// <summary> /// 嵌套协程 /// </summary> /// <param name="routine">执行条件</param> /// <param name="callBack">执行条件结束后自动执行回调函数</param> /// <returns>Coroutine</returns> public Coroutine StartCoroutine(Coroutine routine, CFAction callBack) { if (monoControllerCount == 0) { CreateMonoController(); } return((monoMap[monoControllerCount] as MonoController).StartCoroutine(routine, callBack)); }
protected IEnumerator EnumCollect(float delay, CFAction <object> action, object arg) { int tempFlag = Utility.Int(arg); yield return(new WaitForSeconds(delay)); action?.Invoke(tempFlag); }
/// <summary> /// 同步加载 index /// </summary> /// <param name="sceneIndex"></param> /// <param name="action"></param> public void LoadScene(int sceneIndex, CFAction action = null) { UnityEngine.SceneManagement.SceneManager.LoadScene(sceneIndex); if (action != null) { action(); } }
protected IEnumerator EnumCollect(float delay, CFAction action = null) { Utility.DebugLog("BeforeEnumCollectYield"); yield return(new WaitForSeconds(delay)); action?.Invoke(); Utility.DebugLog("AfterEnumCollectYield"); }
/// <summary> /// 同步加载 name /// </summary> /// <param name="sceneName"></param> /// <param name="action"></param> public void LoadScene(string sceneName, CFAction action = null) { UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName); if (action != null) { action(); } }
/// <summary> /// 移除监听者 /// </summary> /// <param name="act"></param> /// <param name="type"></param> /// <param name="key'">委托所在的序号</param> public void RemoveListener(CFAction act, UpdateType type, short monoID) { if (!monoMap.ContainsKey(monoID)) { Utility.DebugError("MonoController ID" + monoID + " does not exist!"); return; } monoMap[monoID].RemoveListener(act, type); }
IEnumerator EnumLoadResAssetAsync <T>(string path, CFAction <T> callBack = null) where T : UnityEngine.Object { ResourceRequest req = Resources.LoadAsync <T>(path); yield return(req); callBack?.Invoke(req.asset as T); }
IEnumerator EnumAction(object arg, CFAction handler) { yield return(new WaitForSeconds(Utility.Float(arg))); handler?.Invoke(); if (loop) { tempRoutine = Facade.Instance.StartCoroutine(EnumAction(Interval, () => action.Invoke())); } }
/// <summary> /// 解析Json /// </summary> /// <param name="callBack">回调函数,自定义解析Json</param> public void ParseJosn <T>(TextAsset ta, CFAction <T> callBack) { string jsonStr = ta.text; T jsonObj = JsonUtility.FromJson <T>(jsonStr); if (callBack != null) { callBack(jsonObj); } }
/// <summary> /// 解析Json /// </summary> /// <param name="ta">载入的TextAsset类型对象</param> /// <param name="parsedCallBack">回调函数,这里返回JsonData,数据由回调函数解析</param> public void ParseJson(TextAsset ta, CFAction <JsonData> parsedCallBack) { string jsonStr = ta.text; JsonData jsonObj = JsonMapper.ToObject(jsonStr); if (parsedCallBack != null) { parsedCallBack(jsonObj); } }
IEnumerator EnumLoadSceneAsync(string sceneName, CFAction <float> callBack = null) { AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName); while (!ao.isDone) { callBack?.Invoke(ao.progress); yield return(ao.progress); } yield return(null); }
/// <summary> /// Assert断言仅用于测试环境调试 /// 条件委托, /// 若handler返回true,则run callBack /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <param name="arg">对象</param> /// <param name="handler">处理者</param> /// <param name="callBack">回调</param> public static void Predicate <T>(T arg, Predicate <T> handler, CFAction <T> callBack) { if (handler == null) { return; } if (handler.Invoke(arg)) { callBack?.Invoke(arg); } }
/// <summary> /// Assert断言仅用于测试环境调试 /// 普通异常处理捕捉者 /// </summary> /// <param name="handler">处理者函数</param> /// <param name="exceptionHandler">异常处理函数</param> public static void ExceptionCatcher(CFAction handler, CFAction exceptionHandler) { try { handler?.Invoke(); } catch { exceptionHandler?.Invoke(); } }
/// <summary> /// Assert断言仅用于测试环境调试 /// 判断不为空 /// 若不为空,则执行回调 /// </summary> /// <typeparam name="T">泛型类型</typeparam> /// <param name="arg">泛型对象</param> /// <param name="callBack">若不为空,则执行回调</param> public static void NotNull(object obj, CFAction notNullCallBack) { if (obj == null) { throw new ArgumentNullException("object" + obj.ToString() + "is null !"); } else { notNullCallBack?.Invoke(); } }
/// <summary> /// 解析Json /// 通过回调函数获取对象 /// </summary> /// <param name="callBack">回调函数,直接映射</param> public void ParseJson <T>(TextAsset ta, CFAction <T> callBack) where T : new() { string jsonStr = ta.text; JsonData jsonObj = JsonMapper.ToObject(jsonStr); if (callBack != null) { callBack(JsonMapper.ToObject <T>(jsonObj.ToJson())); } }
/// <summary> /// Assert断言仅用于测试环境调试 /// 判断不为空 /// </summary> /// <param name="obj"></param> /// <param name="notNullCallBack">不为空的回调</param> /// <param name="nullCallBack">为空时候的回调</param> public static void NotNull(object obj, CFAction notNullCallBack, CFAction nullCallBack) { if (obj == null) { nullCallBack?.Invoke(); } else { notNullCallBack?.Invoke(); } }
/// <summary> /// 异步加载迭代器 index /// </summary> /// <param name="sceneIndex"></param> /// <param name="callBack"></param> /// <returns></returns> IEnumerator EnumLoadSceneAsync(int sceneIndex, CFAction callBack = null) { AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneIndex); while (!ao.isDone) { yield return(ao.progress); } yield return(ao.progress); callBack?.Invoke(); }
/// <summary> /// 初始化版本资源列表处理器的新实例。 /// </summary> /// <param name="resourceManager">资源管理器。</param> public VersionListProcessorComponent(ResourceComponent resourceManager) { m_ResourceManager = resourceManager; m_DownloadManager = null; m_VersionListLength = 0; m_VersionListHashCode = 0; m_VersionListZipLength = 0; m_VersionListZipHashCode = 0; VersionListUpdateSuccess = null; VersionListUpdateFailure = null; }
IEnumerator EnumLoadSceneAsync(int sceneIndex, CFAction <AsyncOperation> callBack = null) { AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneIndex); while (!ao.isDone) { callBack?.Invoke(ao); yield return(null); //yield return ao.progress; } //yield return null; }