少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-27 45c82c513c67130bb52cb5e7f2f10c957e463cf1
4340 【前端】支持xlua方便IOS提审
3个文件已修改
46 ■■■■ 已修改文件
Core/GameEngine/DataToCtl/PackageRegedit.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/CSharpCallLua.cs 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/WindowBase/ModelCenter.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/GameEngine/DataToCtl/PackageRegedit.cs
@@ -417,6 +417,7 @@
        try
        {
            packToBusinessTable[_package.cmd].Done(_package);
            CSharpCallLua.OnRecieveCSharpNetPackage(_package.cmd);
        }
        catch (Exception ex)
        {
Lua/CSharpCallLua.cs
@@ -9,29 +9,39 @@
public class CSharpCallLua
{
    [CSharpCallLua]
    public delegate void ByteArrayDelegate(ushort cmd, byte[] bytes);
    public delegate void LuaNetPackage(ushort cmd, byte[] bytes);
    static LuaNetPackage onRecieveLuaNetPackage;
    static ByteArrayDelegate onRecieveNetPackage;
    [CSharpCallLua]
    public delegate void CSharpNetPackage(ushort cmd);
    static CSharpNetPackage onCSharpNetPackage;
    public static void Init()
    {
        LuaUtility.DoString("protocol.ProtocalRegister");
        onRecieveNetPackage = LuaUtility.Global.Get<ByteArrayDelegate>("OnRecieveNetPackage");
        LuaUtility.DoString("protocol.LuaProtocalRegister");
        onRecieveLuaNetPackage = LuaUtility.Global.Get<LuaNetPackage>("OnRecieveNetPackage");
        LuaUtility.DoString("protocol.CSharpProtocalEvent");
        onCSharpNetPackage = LuaUtility.Global.Get<CSharpNetPackage>("OnCSharpNetEvent");
    }
    public static void CallLua(ushort cmd, byte[] bytes)
    public static void OnRecieveLuaNetPackage(ushort cmd, byte[] bytes)
    {
        if (onRecieveNetPackage != null)
        if (onRecieveLuaNetPackage != null)
        {
            onRecieveNetPackage(cmd, bytes);
            onRecieveLuaNetPackage(cmd, bytes);
        }
    }
    public class Test
    public static void OnRecieveCSharpNetPackage(ushort cmd)
    {
        public int a = 0;
        public int b = 2;
        public int c = 3;
        if (onCSharpNetPackage != null)
        {
            onCSharpNetPackage(cmd);
    }
    }
}
System/WindowBase/ModelCenter.cs
@@ -58,6 +58,7 @@
        bool inited = false;
        Dictionary<int, Model> models = new Dictionary<int, Model>();
        Dictionary<string, Model> nameToModels = new Dictionary<string, Model>();
        public ModelCenter()
        {
@@ -221,15 +222,27 @@
            return model;
        }
        public Model GetModel(string name)
        {
            if (nameToModels.ContainsKey(name))
            {
                return nameToModels[name];
            }
            return null;
        }
        T RegisterModel<T>() where T : Model, new()
        {
            T model = null;
            var token = typeof(T).MetadataToken;
            var name = typeof(T).Name;
            if (!models.ContainsKey(token))
            {
                model = new T();
                models[token] = model;
                nameToModels[name] = model;
                model.Init();
            }