public void RegisterDynamicWidthUnit(DynamicWidthUnitBase unit) { #if UNITY_EDITOR if (_UnitList.Contains(unit)) { VeerDebug.LogError(" try to register a existing DynamicWidthUnitBase..."); return; } #endif _UnitList.Add(unit); unit.transform.SetParent(UnitRoot); }
public ObjectBinderAttribute(string objectName, bool nullable = false) { #if UNITY_EDITOR if (!objectName.StartsWith(_StartWith)) { VeerDebug.LogError(" ObjectBinderAttribute objectName not start with " + _StartWith); } #endif ObjectName = objectName; bNullable = nullable; }
public static void SetTextConfig(Text targetText) { #if UNITY_EDITOR if (targetText == null) { VeerDebug.LogError(" SetTextConfig targetText is null..."); } #endif Instance.TestText.font = targetText.font; Instance.TestText.fontSize = targetText.fontSize; Instance.TestText.fontStyle = targetText.fontStyle; Instance.TestText.lineSpacing = targetText.lineSpacing; Instance.TestText.supportRichText = targetText.supportRichText; Instance.TestText.alignment = targetText.alignment; Instance.TestText.alignByGeometry = targetText.alignByGeometry; }
public static Task AsyncCreate(string jsonText, JSONObjectAsyncCreateCallback callback) { #if UNITY_EDITOR if (callback == null) { VeerDebug.LogError(" JSONObject AsyncCreate callback is null..."); return(null); } #endif Task task = Task <JSONObject> .Run(() => { JSONObject json = null; try { json = Create(jsonText); } catch { VeerDebug.LogWarning(" create json failed ..."); return(null); } return(json); }).ContinueInMainThreadWith((obj) => { if (obj == null) { VeerDebug.LogWarning(" async json object create timeout, maybe lost thread ..."); callback(false, null); return; } else if (obj.IsFaulted || obj.IsAborted || !obj.IsCompleted) { VeerDebug.LogWarning(" async json object create timeout, maybe lost thread ..."); callback(false, null); return; } else { callback(true, obj.Result); return; } }, 8f); return(task); }
public static Task AsyncDeserializeJson <T>(string jsonText, Action <bool, T> callback, float timeout = 6f) { #if UNITY_EDITOR if (callback == null) { VeerDebug.LogError(" AsyncDeserializeJson callback is null..."); return(null); } #endif Task task = Task <T> .Run(() => { return(Deserialize <T>(jsonText)); }).ContinueInMainThreadWith((obj) => { AsyncDeserializeJsonCallback(callback, obj); }, timeout); return(task); }
public static Task AsyncDeserializeJson(JSONObject json, Type type, Action <bool, object> callback, float timeout = 6f) { #if UNITY_EDITOR if (callback == null) { VeerDebug.LogError(" AsyncDeserializeJson callback is null..."); return(null); } #endif Task task = Task <object> .Run(() => { return(Deserialize(json, type)); }).ContinueInMainThreadWith((obj) => { AsyncDeserializeJsonCallback(callback, obj); }, timeout); return(task); }
public static void RunTimerTask(TimerTask timerTask, float delayTime, Action action, bool loop = false) { if (timerTask == null) { VeerDebug.LogError(" can not RunTimerTask with a null timerTask input ..."); return; } if (timerTask.bTaskRunning) { timerTask.StopTask(); return; } if (delayTime <= 0) { VeerDebug.LogError(" can not RunTimerTask with strange delay time ..."); return; } #if UNITY_EDITOR if (_RunningTimerTaskList.Contains(timerTask)) { VeerDebug.LogError(" strange ... a timer task in _RunningTimerTaskList is not running ..."); return; } #endif timerTask.bTaskRunning = true; timerTask.CoroutineTaskId = _TimerTaskId; timerTask.bPaused = false; timerTask.bLoop = loop; timerTask.TaskDelayTime = delayTime; timerTask.TaskTimer = delayTime; timerTask.TaskAction = action; _RunningTimerTaskList.Add(timerTask); }
internal void CheckExecuteTask() { foreach (var p in UnfinishedTaskDic) { DependentTask task = p.Value; if (task.Internal.bTaskRunning) { continue; } #if UNITY_EDITOR if (task.Internal.bTaskFinished) { VeerDebug.LogError(" a finished task is in unfinished task list : " + task.Internal.TaskName); continue; } #endif if (task.CheckAllDependentTaskFinished()) { task.ExecuteTask(); } } }
public static void BindObjectRecursive(Component root) { if (root == null) { VeerDebug.LogWarning(" BindObjectRecursive root is null ..."); return; } Type rootType = root.GetType(); FieldInfo[] fieldInfos = rootType.GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); bool bFieldIsComponentOrGameObject = false; foreach (var f in fieldInfos) { if (f.FieldType.IsSubclassOf(typeof(Component))) { bFieldIsComponentOrGameObject = true; } else if (f.FieldType.Equals(typeof(GameObject))) { bFieldIsComponentOrGameObject = false; } else { continue; } foreach (var attr in f.GetCustomAttributes(true)) { if (attr is ObjectBinderAttribute) { f.SetValue(root, null); ObjectBinderAttribute objectBinder = attr as ObjectBinderAttribute; string attrObjectName = objectBinder.ObjectName; if (string.IsNullOrEmpty(attrObjectName)) { VeerDebug.LogWarning(" ObjectBinderAttribute attrObjectName is null or empty ... " + f.Name); continue; } #if UNITY_EDITOR if (!attrObjectName.StartsWith(VeerYeastConst.Auto_Bind_Tag)) { VeerDebug.LogError(" ObjectBinderAttribute attrObjectName is not start with " + VeerYeastConst.Auto_Bind_Tag + " ... " + f.Name); continue; } #endif GameObject targetGameObject = root.gameObject.GetChildGoByName(attrObjectName, true); if (targetGameObject == null) { VeerDebug.LogWarning(" ObjectBinderAttribute targetGameObject is null ... " + f.Name); continue; } if (!bFieldIsComponentOrGameObject) { f.SetValue(root, targetGameObject); } else { Component targetMonoBehaviour = targetGameObject.GetComponent(f.FieldType) as Component; if (targetMonoBehaviour == null) { VeerDebug.LogWarning(" ObjectBinderAttribute targetMonoBehaviour is null ... " + f.Name); continue; } f.SetValue(root, targetMonoBehaviour); } } if (attr is ObjectBinderRootAttribute) { Component rootMonoBehaviour = f.GetValue(root) as Component; if (rootMonoBehaviour == null) { #if UNITY_EDITOR VeerDebug.LogWarning(" ObjectBinderRootAttribute root is null ... " + f.Name); #endif continue; } BindObjectRecursive(rootMonoBehaviour); } } } }