void Awake() { XLuaManager.Instance().InitLuaEnv(); luaEnv = XLuaManager.Instance().luaEnv; scriptEnv = luaEnv.NewTable(); // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in variables) { scriptEnv.Set(injection.name, injection.value); } luaEnv.DoString(luaScript.text, "XLuaBehaviour", scriptEnv); scriptEnv.Get("Awake", out luaAwake); scriptEnv.Get("Start", out luaStart); scriptEnv.Get("Update", out luaUpdate); scriptEnv.Get("OnDestroy", out luaOnDestroy); if (null != luaAwake) { luaAwake(); } }
static int _m_StartHotfix(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 2 && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2)) { bool _restart = LuaAPI.lua_toboolean(L, 2); gen_to_be_invoked.StartHotfix(_restart); return(0); } if (gen_param_count == 1) { gen_to_be_invoked.StartHotfix( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to XLuaManager.StartHotfix!")); }
protected void Awake() { if (Instance != null) { Destroy(gameObject); return; } Instance = this; }
public static XLuaManager GetInstance() { if (Instance == null) { Instance = new XLuaManager(); } return(Instance); }
private void Awake() { this.luaTable = XLuaManager.GetInstance().InitMonoBehaviour(this, scriptName); luaAwake = CallLuaFunction("Awake"); luaStart = CallLuaFunction("Start"); luaUpdate = CallLuaFunction("Update"); luaOnEnable = CallLuaFunction("OnEnable"); luaOnDestroy = CallLuaFunction("OnDestroy"); luaAwake?.Invoke(); }
// Start is called before the first frame update void Start() { LuaEnv lua = XLuaManager.GetInstance().GetLuaEnv(); onCollisionEnter = lua.Global.Get <Action <Collision> >("OnCollisionEnter"); onCollisionStay = lua.Global.Get <Action <Collision> >("OnCollisionStay"); onCollisionExit = lua.Global.Get <Action <Collision> >("OnCollisionExit"); //transform.GetChild() }
void Awake() { Instance = this; this.LoadedLuas.Clear(); for (int i = 0; i < this.PreloadLuas.Length; i++) { this.LoadFile(this.PreloadLuas[i]); } }
void Awake() { DontDestroyOnLoad(this); Instance = this; Application.targetFrameRate = 60; XLuaManager.GetInstance().StartUp(); // XLuaManager.GetInstance().OnEntry(); }
static int _g_get_AssetbundleName(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, gen_to_be_invoked.AssetbundleName); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(1); }
static int _g_get_luaEnv(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); translator.Push(L, gen_to_be_invoked.luaEnv); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(1); }
private void EnableLua() { if (AppConfig.Instance.EnableXLua == false) { return; } ReloadBundleManifest(); XLuaManager.InitXLua(); XLuaManager.LoadMainSctipt(); Debug.Log("<color='#00ff99'>EnableLua Success!!!</color>"); }
static int __CreateInstance(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (LuaAPI.lua_gettop(L) == 1) { var gen_ret = new XLuaManager(); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to XLuaManager constructor!")); }
static int _m_CustomLoader_xlua_st_(RealStatePtr L) { try { { string _filepath = LuaAPI.lua_tostring(L, 1); var gen_ret = XLuaManager.CustomLoader(ref _filepath); LuaAPI.lua_pushstring(L, gen_ret); LuaAPI.lua_pushstring(L, _filepath); return(2); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_StartGame(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.StartGame( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_SafeDoString(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING)) { string _scriptContent = LuaAPI.lua_tostring(L, 2); string _chunkName = LuaAPI.lua_tostring(L, 3); gen_to_be_invoked.SafeDoString(_scriptContent, _chunkName); return(0); } if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING)) { string _scriptContent = LuaAPI.lua_tostring(L, 2); gen_to_be_invoked.SafeDoString(_scriptContent); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to XLuaManager.SafeDoString!")); }
static int _m_StartLogin(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); { System.Action _login_ok = translator.GetDelegate <System.Action>(L, 2); gen_to_be_invoked.StartLogin(_login_ok); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_SafeDoString(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); { string _scriptContent = LuaAPI.lua_tostring(L, 2); gen_to_be_invoked.SafeDoString(_scriptContent); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_LoadOutsideFile(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLuaManager gen_to_be_invoked = (XLuaManager)translator.FastGetCSObj(L, 1); { string _file_path = LuaAPI.lua_tostring(L, 2); gen_to_be_invoked.LoadOutsideFile(_file_path); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
protected override void Awake() { m_scriptEnv = XLuaManager.GetInstance().CreateTable(); // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 LuaTable _meta = XLuaManager.GetInstance().CreateTable(); _meta.Set("__index", XLuaManager.GetInstance().GlobalTable); m_scriptEnv.SetMetaTable(_meta); _meta.Dispose(); m_scriptEnv.Set("self", this); foreach (var _injection in m_injections) { m_scriptEnv.Set(_injection.name, _injection.value); } var _chunk = ScriptFileName; // 读取 var _objects = XLuaManager.GetInstance().DoStringForPath(_chunk, m_scriptEnv, _chunk); if (_objects != null && _objects.Length > 0) { m_luaTable = _objects[0] as LuaTable;; } else { //Debug.LogError("没找到对应lua"); } Action _luaAwake = null; if (m_luaTable != null) { Debug.LogWarning("成功读取函数" + ScriptFileName); _luaAwake = m_luaTable.Get <Action>("Awake"); m_luaTable.Get("Start", out m_luaStart); m_luaTable.Get("Update", out m_luaUpdate); m_luaTable.Get("OnDestroy", out m_luaOnDestroy); m_luaTable.Get("OnEnable", out m_luaEnable); m_luaTable.Get("OnDisable", out m_luaDisable); } if (!XLuaManager.GetInstance().m_scriptEnvDic.Contains(this)) { XLuaManager.GetInstance().m_scriptEnvDic.Add(this); //Debug.LogError("添加"); } //Action _luaAwake = scriptEnv.Get<Action>("Awake"); //scriptEnv.Get("Start", out luaStart); //scriptEnv.Get("Update", out luaUpdate); //scriptEnv.Get("OnDestroy", out luaOnDestroy); //scriptEnv.Get("OnEnable", out luaEnable); //scriptEnv.Get("OnDisable", out luaDisable); if (_luaAwake != null) { _luaAwake(); _luaAwake = null;; } }
public static Action CallFunction(string _targetName, string _function) { return(XLuaManager.GetInstance().CallFunction(_targetName, _function)); }
private Action CallLuaFunction(string _fun) { return(XLuaManager.GetInstance().CallFunction(gameObject.name, _fun)); }
// Use this for initialization void Start() { ResManager.Create().Init(delegate { XLuaManager.Create().Init(); }); }
protected void Awake() { Instance = this; }
private void Awake() { ms_Instance = this; luaEnv = new LuaEnv(); }