public void Reset()
            {
                var tid = ThreadLocalObj.GetThreadId();

                if (tid == ThreadSafeValues.UnityThreadID)
                {
                    ResetRaw();
                }
                else
                {
                    UnityThreadDispatcher.RunInUnityThread(ResetRaw);
                }
            }
            public void SetGlobal(string name, object val)
            {
                var tid = ThreadLocalObj.GetThreadId();

                if (tid == ThreadSafeValues.UnityThreadID)
                {
                    SetGlobalRaw(name, val);
                }
                else
                {
                    UnityThreadDispatcher.RunInUnityThread(() =>
                    {
                        SetGlobalRaw(name, val);
                    });
                }
            }
 public void UnregHandler(string cate, int refid)
 {
     if (cate != null)
     {
         var tid = ThreadLocalObj.GetThreadId();
         if (tid == ThreadSafeValues.UnityThreadID)
         {
             UnregHandlerRaw(cate, refid);
         }
         else
         {
             UnityThreadDispatcher.RunInUnityThread(() =>
             {
                 UnregHandlerRaw(cate, refid);
             });
         }
     }
 }
            public void HandleEvent(string cate, int refid)
            {
                var tid = ThreadLocalObj.GetThreadId();

                if (tid == ThreadSafeValues.UnityThreadID)
                {
                    var pars = CrossEvent.CurrentContext._P[CrossEvent.TOKEN_ARGS];
                    var rvs  = CrossEvent.CurrentContext._P[CrossEvent.TOKEN_RETS];
                    var l    = GlobalLua.L.L;
                    using (var lr = new LuaStateRecover(l))
                    {
                        object[] args = new object[pars.Count + 1];
                        for (int i = 0; i < pars.Count; ++i)
                        {
                            args[i + 1] = pars[i].Value;
                        }
                        args[0] = cate;

                        l.GetField(lua.LUA_REGISTRYINDEX, "___levt");
                        if (l.istable(-1))
                        {
                            l.PushString(cate);
                            l.gettable(-2);
                            if (l.istable(-1))
                            {
                                l.pushnumber(refid);
                                l.gettable(-2);
                                if (l.isfunction(-1))
                                {
                                    var luarvs = ((BaseDynamic)(new LuaOnStackFunc(l, -1))).Call(args);
                                    for (int j = rvs.Count; j < luarvs.Length; ++j)
                                    {
                                        rvs.Add(new CrossEvent.EventParam());
                                    }
                                    for (int j = 0; j < luarvs.Length; ++j)
                                    {
                                        var param = rvs[j];
                                        param.Value = luarvs[j];
                                        rvs[j]      = param;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var pars = CrossEvent.CurrentContext._P[CrossEvent.TOKEN_ARGS];
                    UnityThreadDispatcher.RunInUnityThread(() =>
                    {
                        var l = GlobalLua.L.L;
                        using (var lr = new LuaStateRecover(l))
                        {
                            object[] args = new object[pars.Count + 1];
                            for (int i = 0; i < pars.Count; ++i)
                            {
                                args[i + 1] = pars[i].Value;
                            }
                            args[0] = cate;

                            l.GetField(lua.LUA_REGISTRYINDEX, "___levt");
                            if (l.istable(-1))
                            {
                                l.PushString(cate);
                                l.gettable(-2);
                                if (l.istable(-1))
                                {
                                    l.pushnumber(refid);
                                    l.gettable(-2);
                                    if (l.isfunction(-1))
                                    {
                                        ((BaseDynamic)(new LuaOnStackFunc(l, -1))).Call(args);
                                    }
                                }
                            }
                        }
                    });
                }
            }