Пример #1
0
    public void SetLuaModule(LuaTable module, LuaTable data = null)
    {
        mLuaModule      = module;
        mLuaStart       = module.Get <string, MonoBehaviourEvent>("Start");
        mLuaUpdate      = module.Get <string, MonoBehaviourEvent>("Update");
        mLuaFixedUpdate = module.Get <string, MonoBehaviourEvent>("FixedUpdate");
        mLuaLateUpdate  = module.Get <string, MonoBehaviourEvent>("LateUpdate");
        mLuaOnDisable   = module.Get <string, MonoBehaviourEvent>("OnDisable");
        mLuaOnEnable    = module.Get <string, MonoBehaviourEvent>("OnEnable");
        mLuaOnDestroy   = module.Get <string, MonoBehaviourEvent>("OnDestroy");
        mLuaOnGUI       = module.Get <string, MonoBehaviourEvent>("OnGUI");

        mLuaObject = LuaMgr.Instance.Env.NewTable();
        mLuaObject.Set <string, GameObject>("gameObject", gameObject);
        mLuaObject.Set <string, Transform>("transform", transform);
        mLuaObject.Set <string, LuaTable>("data", data);
        mLuaObject.Set <string, LuaBehaviour>("view", this);
    }
Пример #2
0
    public static XLua.LuaTable getSimpleEnvTable()
    {
        XLua.LuaTable scriptEnv = LuaManager.LuaEnv.NewTable();
        // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
        XLua.LuaTable meta = LuaManager.LuaEnv.NewTable();
        meta.Set("__index", LuaManager.LuaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        return(scriptEnv);
    }
Пример #3
0
        public MessageLua(XLua.LuaEnv luaEnv, UInt32 clsId, String clsName, UInt32 signId, String type, List <Attr> attrs)
        {
            _luaEnv   = luaEnv;
            _luaTable = _luaEnv.NewTable();
            _type     = type;
            _luaTable.Set(s_sSelf, this);

            if (_type.Equals(s_sEnum))
            {
                foreach (var v in attrs)
                {
                    _luaTable.Set(v.name, Int32.Parse(v.defVal));
                }
            }
            else
            {
                _clsId   = clsId;
                _clsName = clsName;
                _signId  = signId;
                _attrs   = attrs;

                _luaTable.Set("ClsName", _clsName);
                _luaTable.Set("ClsId", _clsId);
                _luaTable.Set("SignId", _signId);

                _luaTable.Set <String, DelegateCreate>("Create", this.Create);
            }
        }
Пример #4
0
    void onUploadReccordFileComplete(IGCloudVoice.GCloudVoiceCompleteCode code, string filepath, string fileid)
    {
        if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_UPLOAD_RECORD_DONE)
        {
            Debug.Log("OnUploadReccordFileComplete succ, filepath:" + filepath + " fileid len=" + fileid.Length + " fileid:" + fileid + " fileid len=" + fileid.Length);

            XLua.LuaTable tab = AppMng.luaEnv.NewTable();
            tab.Set <string, string> ("fileid", fileid);
            EventTool.Run("niuniu", "playroom.sendchat", tab);
        }
        else
        {
            Debug.Log("OnUploadReccordFileComplete error");
        }
    }
Пример #5
0
    public static XLua.LuaTable getInterpreterEnvTable(GameInterpreter interpreter)
    {
        XLua.LuaTable scriptEnv = LuaManager.LuaEnv.NewTable();
        // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
        XLua.LuaTable meta = LuaManager.LuaEnv.NewTable();
        meta.Set("__index", LuaManager.LuaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("self", interpreter);
        scriptEnv.Set("gameVariables", GameTemp.gameVariables);
        scriptEnv.Set("gameSwitches", GameTemp.gameSwitches);
        scriptEnv.Set("gameSelfSwitches", GameTemp.gameSelfSwitches);
        scriptEnv.Set("gamePlayer", GameTemp.gamePlayer);
        scriptEnv.Set("gameMap", GameTemp.gameMap);

        return(scriptEnv);
    }
Пример #6
0
    public void Init()
    {
        print("===============" + gameObject);

        print(table);
        table.Set("gameObject", gameObject);
        _Awake = table.Get <LuaObjectAction>("Awake");
        _Start = table.Get <LuaObjectAction>("Start");

        _Update = table.Get <LuaObjectAction>("Update");
        if (_Awake != null)
        {
            if (args != null)
            {
                _Awake(table, args);
            }
            else
            {
                _Awake(table);
            }
            //this.gameObject.AddComponent("Lua")
        }
    }
    //----------------------------------------------------------------------------
    // PlayState.Playingに変更されたときに呼び出される
    public override void OnBehaviourPlay(
        UnityEngine.Playables.Playable playable,
        UnityEngine.Playables.FrameData info
        )
    {
        if (textAsset != null)
        {
            scriptEnv = LuaEngine.LuaEnv.NewTable();
            // スクリプトごとに別々の環境を設定すると、スクリプト間でのグローバル変数と関数の競合をある程度防ぐことができます。
            XLua.LuaTable meta = LuaEngine.LuaEnv.NewTable();
            meta.Set("__index", LuaEngine.LuaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            scriptEnv.Set("self", owner);
            LuaEngine.LuaEnv.DoString(textAsset.text, textAsset.GetHashCode().ToString(), scriptEnv);

            Action luaAwake = scriptEnv.Get <Action>("awake");
            scriptEnv.Get("update", out luaUpdate);
            scriptEnv.Get("ondestroy", out luaOnDestroy);

            luaAwake?.Invoke();
        }
    }
Пример #8
0
 /// <summary>
 /// 添加LuaTable
 /// </summary>
 /// <param name="tableName"></param>
 /// <param name="luaTable"></param>
 public void AddTable(string tableName, LuaTable luaTable)
 {
     _luaTableMap.Add(tableName, luaTable);
     tableMap.Set(tableName, luaTable);
 }
Пример #9
0
        public void Decode(XLua.LuaTable luaTable, BinaryReader stream)
        {
            var dictionary = new Dictionary <String, object>();

            foreach (var v in _attrs)
            {
                try
                {
                    if (v.type.Equals(_sString))
                    {
                        String value = "";
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sInt32))
                    {
                        Int32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sUint32))
                    {
                        UInt32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sEnum))
                    {
                        Int32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sUint8))
                    {
                        UInt8 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sUint16))
                    {
                        UInt16 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }

                    else if (v.type.Equals(_sUint64))
                    {
                        UInt64 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sInt8))
                    {
                        Int8 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sInt16))
                    {
                        Int16 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }

                    else if (v.type.Equals(_sInt64))
                    {
                        Int64 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sDouble))
                    {
                        Double value = 0.0f;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sFloat))
                    {
                        Float value = 0.0f;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(_sBool))
                    {
                        Bool value = false;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else
                    {
                        //var table = _luaEnv.Global.GetInPath<CfgLua>(v.type);
                        //var ml = table.Get<String, CfgLua>(_sSelf);
                        var cl = _luaEnv.Global.GetInPath <CfgLua>(v.type);

                        cl.LoadCfg();

                        var indexValue = ReadValue(stream, cl.IndexType);
                        dictionary.Add(v.name, cl.GetItem(indexValue));
                    }
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
            }

            luaTable.Set(dictionary);
        }
Пример #10
0
        public CfgLua(XLua.LuaEnv luaEnv, UInt32 clsId, String clsName, UInt32 signId, List <Attr> attrs, String index = "", String cfgPath = "")
        {
            _luaEnv = luaEnv;
            _index  = index;

            _cfgPath  = cfgPath;
            _luaTable = _luaEnv.NewTable();
            _luaTable.Set(_sSelf, this);

            _clsId   = clsId;
            _clsName = clsName;
            _signId  = signId;
            _attrs   = attrs;

            _luaTable.Set("ClsName", _clsName);
            _luaTable.Set("ClsId", _clsId);
            _luaTable.Set("SignId", _signId);

            _keys  = new List <object>();
            _items = new List <LuaTable>();

            _luaTable.Set <String, List <object> >("Keys", this.Keys);
            _luaTable.Set <String, List <LuaTable> >("Items", this.Items);
            _luaTable.Set <String, DelegateGetItem>("GetItem", this.GetItem);

            if (index.Equals(_sString))
            {
                _keyTypeConvert = new KeyTypeConvert <String>();
            }
            else if (index.Equals(_sInt32))
            {
                _keyTypeConvert = new KeyTypeConvert <Int32>();
            }
            else if (index.Equals(_sUint32))
            {
                _keyTypeConvert = new KeyTypeConvert <UInt32>();
            }
            else if (index.Equals(_sUint8))
            {
                _keyTypeConvert = new KeyTypeConvert <UInt8>();
            }
            else if (index.Equals(_sUint16))
            {
                _keyTypeConvert = new KeyTypeConvert <UInt16>();
            }
            else if (index.Equals(_sUint64))
            {
                _keyTypeConvert = new KeyTypeConvert <UInt64>();
            }
            else if (index.Equals(_sInt8))
            {
                _keyTypeConvert = new KeyTypeConvert <Int8>();
            }
            else if (index.Equals(_sInt16))
            {
                _keyTypeConvert = new KeyTypeConvert <Int16>();
            }

            else if (index.Equals(_sInt64))
            {
                _keyTypeConvert = new KeyTypeConvert <Int64>();
            }
            else if (index.Equals(_sDouble))
            {
                _keyTypeConvert = new KeyTypeConvert <Double>();
            }
            else if (index.Equals(_sFloat))
            {
                _keyTypeConvert = new KeyTypeConvert <Float>();
            }
            else if (index.Equals(_sBool))
            {
                _keyTypeConvert = new KeyTypeConvert <Bool>();
            }
        }
Пример #11
0
        public void Decode(XLua.LuaTable luaTable, BinaryReader stream)
        {
            var dictionary = new Dictionary <String, object>();

            foreach (var v in _attrs)
            {
                try
                {
                    if (v.type.Equals(s_sString))
                    {
                        String value = "";
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sInt32))
                    {
                        Int32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sUint32))
                    {
                        UInt32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sEnum))
                    {
                        Int32 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sUint8))
                    {
                        UInt8 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sUint16))
                    {
                        UInt16 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }

                    else if (v.type.Equals(s_sUint64))
                    {
                        UInt64 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sInt8))
                    {
                        Int8 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sInt16))
                    {
                        Int16 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }

                    else if (v.type.Equals(s_sInt64))
                    {
                        Int64 value = 0;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sDouble))
                    {
                        Double value = 0.0f;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sFloat))
                    {
                        Float value = 0.0f;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else if (v.type.Equals(s_sBool))
                    {
                        Bool value = false;
                        doDeserialize(stream, ref value);
                        dictionary.Add(v.name, value);
                    }
                    else
                    {
                        var table = _luaEnv.Global.Get <XLua.LuaTable>(v.name);
                        var ml    = table.Get <String, MessageLua>(s_sSelf);
                        ml.Decode(table, stream);
                    }
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
            }

            luaTable.Set(dictionary);
        }