AddMainThreadCall() public static method

在子线程执行一个函数,让其回到主线程再执行的
public static AddMainThreadCall ( System.Action call ) : void
call System.Action
return void
コード例 #1
0
        public static void CreateDebugObject(object obj)
        {
            if (!Application.isEditor || !Application.isPlaying || IsApplicationQuited)
            {
                return;
            }

            KAsync.AddMainThreadCall(() =>
            {
                try
                {
                    var newDebugger =
                        new GameObject(string.Format("{0}-{1}", obj.ToString(), obj.GetType()))
                        .AddComponent <KObjectDebugger>();
                    newDebugger.WatchObject = obj;

                    KDebuggerObjectTool.SetParent(ContainerName, obj.GetType().Name, newDebugger.gameObject);

                    Cache[obj] = newDebugger;
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            });
        }
コード例 #2
0
        public static void RemoveDebugObject(object obj)
        {
            if (!Application.isEditor || !Application.isPlaying || IsApplicationQuited)
            {
                return;
            }

            KAsync.AddMainThreadCall(() =>
            {
                try
                {
                    KObjectDebugger debuger;
                    if (KObjectDebugger.Cache.TryGetValue(obj, out debuger))
                    {
                        GameObject.Destroy(debuger.gameObject);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            });
        }