Exemplo n.º 1
0
            public void Reset()
            {
                var tid = ThreadLocalObj.GetThreadId();

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

                if (tid == ThreadSafeValues.UnityThreadID)
                {
                    SetGlobalRaw(name, val);
                }
                else
                {
                    UnityThreadDispatcher.RunInUnityThread(() =>
                    {
                        SetGlobalRaw(name, val);
                    });
                }
            }
Exemplo n.º 3
0
 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);
             });
         }
     }
 }
Exemplo n.º 4
0
            public object GetGlobal(string name)
            {
                var tid = ThreadLocalObj.GetThreadId();

                if (tid == ThreadSafeValues.UnityThreadID)
                {
                    var l = GlobalLua.L.L;
                    if (l.GetHierarchicalRaw(lua.LUA_GLOBALSINDEX, name))
                    {
                        object rv = null;
                        if (l.istable(-1))
                        {
                            rv = GetParams(l, -1);
                        }
                        else
                        {
                            rv = l.GetLua(-1);
                        }
                        l.pop(1);
                        return(rv);
                    }
                }
                return(null);
            }
Exemplo n.º 5
0
        public static System.IO.Stream GetLuaStream(string name, out string location)
        {
#if UNITY_EDITOR
            try
            {
                if (!string.IsNullOrEmpty(name))
                {
                    if (name.Length > 0 && name[0] == '?')
                    {
                        var    real = name.Substring("?raw.".Length);
                        string mod  = null;
                        string norm = real;
                        if (real.StartsWith("mod."))
                        {
                            if (real.StartsWith("mod.\""))
                            {
                                var mindex = real.IndexOf('\"', "mod.\"".Length);
                                if (mindex > 0)
                                {
                                    mod  = real.Substring("mod.\"".Length, mindex - "mod.\"".Length);
                                    norm = real.Substring(mindex + 2);
                                }
                            }
                            else
                            {
                                var mindex = real.IndexOf('.', "mod.".Length);
                                if (mindex > 0)
                                {
                                    mod  = real.Substring("mod.".Length, mindex - "mod.".Length);
                                    norm = real.Substring(mindex + 1);
                                }
                            }
                        }
                        norm = norm.Replace('.', '/');
                        bool isFileExist = false;
                        if (mod == null)
                        {
                            real = "Assets/CapsSpt/" + norm + ".lua";
                        }
                        else
                        {
                            string package;
                            ResManager.EditorResLoader.ResRuntimeCache.ModToPackage.TryGetValue(mod, out package);
                            if (!string.IsNullOrEmpty(package))
                            {
                                real = "Packages/" + package + "/CapsSpt/" + norm + ".lua";
                                //real = EditorToClientUtils.GetPathFromAssetName(real);
                                isFileExist = !string.IsNullOrEmpty(real) && PlatDependant.IsFileExist(real);
                            }
                            if (!isFileExist)
                            {
                                real = "Assets/Mods/" + mod + "/CapsSpt/" + norm + ".lua";
                            }
                        }
                        if (isFileExist || PlatDependant.IsFileExist(real))
                        {
                            location = real;
                            return(PlatDependant.OpenRead(real));
                        }
                    }
                    else
                    {
                        var    file = "CapsSpt/" + name.Replace('.', '/') + ".lua";
                        string found;
                        if (ThreadLocalObj.GetThreadId() == ThreadSafeValues.UnityThreadID)
                        {
                            found = ResManager.EditorResLoader.CheckDistributePath(file, true);
                        }
                        else
                        {
                            found = ResManager.EditorResLoader.CheckDistributePathSafe(file);
                        }
                        //if (found != null)
                        //{
                        //    if (found.StartsWith("Packages/"))
                        //    {
                        //        found = EditorToClientUtils.GetPathFromAssetName(found);
                        //    }
                        //}
                        if (found != null)
                        {
                            location = found;
                            return(PlatDependant.OpenRead(found));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PlatDependant.LogError(e);
            }
#elif UNITY_ENGINE || UNITY_5_3_OR_NEWER
            try
            {
                if (name.Length > 0 && name[0] == '?')
                {
                    if (name.StartsWith("?raw."))
                    {
                        if (_RuntimeRawManifest != null)
                        {
                            var real = name.Substring("?raw.".Length);
                            real = real.Replace("\"", "");
                            string archreal = Environment.Is64BitProcess ? "@64." + real : "@32." + real;
                            CapsResManifestNode node;
                            if (_RuntimeRawManifest.TryGetItemIgnoreExt(archreal, out node, _LuaRequireSeperateChars) || _RuntimeRawManifest.TryGetItemIgnoreExt(real, out node, _LuaRequireSeperateChars))
                            {
                                if (node != null && node.Item != null)
                                {
                                    var item = node.Item;
                                    while (item.Ref != null)
                                    {
                                        item = item.Ref;
                                    }
                                    return(GetLuaStream(item, out location));
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (_RuntimeManifest != null)
                    {
                        var node = _RuntimeManifest.GetItem(name, _LuaRequireSeperateChars);
                        if (node != null && node.Item != null)
                        {
                            var item = node.Item;
                            while (item.Ref != null)
                            {
                                item = item.Ref;
                            }
                            return(GetLuaStream(item, out location));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PlatDependant.LogError(e);
            }
#else
            try
            {
                if (!string.IsNullOrEmpty(name))
                {
                    if (name.Length > 0 && name[0] == '?')
                    {
                        var    real = name.Substring("?raw.".Length);
                        string mod  = null;
                        string norm = real;
                        if (real.StartsWith("mod."))
                        {
                            if (real.StartsWith("mod.\""))
                            {
                                var mindex = real.IndexOf('\"', "mod.\"".Length);
                                if (mindex > 0)
                                {
                                    mod  = real.Substring("mod.\"".Length, mindex - "mod.\"".Length);
                                    norm = real.Substring(mindex + 2);
                                }
                            }
                            else
                            {
                                var mindex = real.IndexOf('.', "mod.".Length);
                                if (mindex > 0)
                                {
                                    mod  = real.Substring("mod.".Length, mindex - "mod.".Length);
                                    norm = real.Substring(mindex + 1);
                                }
                            }
                        }
                        norm = norm.Replace('.', '/');
                        if (mod == null)
                        {
                            real = "/spt/" + norm + ".lua";
                        }
                        else
                        {
                            real = "/mod/" + mod + "/spt/" + norm + ".lua";
                        }
                        var stream = ResManager.LoadFileRelative(real);
                        if (stream != null)
                        {
                            location = real;
                            return(stream);
                        }
                    }
                    else
                    {
                        var    file = "/spt/" + name.Replace('.', '/') + ".lua";
                        string real, mod, dist;
                        real = ResManager.FindFile(file, out mod, out dist);
                        if (real != null)
                        {
                            try
                            {
                                var stream = PlatDependant.OpenRead(real);
                                if (stream != null)
                                {
                                    location = file;
                                    if (!string.IsNullOrEmpty(dist))
                                    {
                                        location = "/dist/" + dist + location;
                                    }
                                    if (!string.IsNullOrEmpty(mod))
                                    {
                                        location = "/mod/" + mod + location;
                                    }
                                    return(stream);
                                }
                            }
                            catch (Exception e)
                            {
                                PlatDependant.LogError(e);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PlatDependant.LogError(e);
            }
#endif
            location = "";
            return(null);
        }
Exemplo n.º 6
0
            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);
                                    }
                                }
                            }
                        }
                    });
                }
            }