public void AddLuaTable(string name, LuaTable table) { if (string.IsNullOrEmpty(name) || table == null) { return; } if (mLuaTables.ContainsKey(name) == false) { mLuaTables.Add(name, table); table.Call("_init", table, this); table.Call("Awake", table); table.Call("OnEnable", table); if (mStart) { table.Call("Start", table); } } #if UNITY_EDITOR LuaTables = new string[mLuaTables.Count]; mLuaTables.Keys.CopyTo(LuaTables, 0); for (int i = 0; i < LuaTables.Length; ++i) { string key = LuaTables[i]; LuaTables[i] = mLuaTables[key].Invoke <string>("GetType") + ".lua"; } #endif }
public void AddLuaTable(string name, LuaTable table) { if (string.IsNullOrEmpty(name) || table == null) { return; } if (mLuaTables.ContainsKey(name) == false) { mLuaTables.Add(name, table); table.Call("_init", table, this); table.Call("Awake", table); table.Call("OnEnable", table); if (mStart) { table.Call("Start", table); } } #if UNITY_EDITOR if (LuaTables == null) { LuaTables = new List <string>(); } LuaTables.Clear(); var it = mLuaTables.GetEnumerator(); while (it.MoveNext()) { LuaTables.Add(it.Current.Value.Invoke <string>("GetType") + ".lua"); } #endif }
private static void OnDownload(long downloadedSize, long downloadSize) { if (hotUpdateClass == null || hotUpdateObject == null) { return; } hotUpdateClass.Call("Download", hotUpdateObject, downloadedSize, downloadSize); }
protected void Start() { if (isFinishLuaInit) { _luaTable.Call("Start", _luaTable); } InitUpdateEvent(); isStart = true; }
private void CallFunctionToName(string name) { if (mLuaTable != null) { mLuaTable.Call(name); } }
public void DetachProfiler() { if (profiler != null) { profiler.Call("stop", profiler); profiler.Dispose(); } }
public void AttachProfiler() { if (profiler == null) { profiler = luaState.Require <LuaTable>("UnityEngine.Profiler"); profiler.Call("start", profiler); } }
private void CallVoidFunc(string name) { if (self == null) { return; } self.Call <LuaTable>(name, self); }
void TestToLua2() { string filename = "TestToLuaC2"; m_state.DoFile(filename); //这里获取不到 GameLogger.Log("Get Lua Local Value : " + m_state["local_num"]); //可以读取到全局的变量 GameLogger.Log("Get Lua Value : " + m_state["global_num"]); m_state["global_num"] = 10; GameLogger.Log("Set Lua Value : " + m_state["global_num"]); //调用lua方法 LuaFunction luaFunc = m_state.GetFunction("Count"); luaFunc.Call(); GameLogger.Log("Get Lua Value : " + m_state["global_num"]); //也可以直接 m_state.Call("Count", false); GameLogger.Log("Get Lua Value : " + m_state["global_num"]); //方法传入参数 LuaFunction valueFunc = m_state.GetFunction("InputValue"); valueFunc.BeginPCall(); valueFunc.Push("-- 这是CSharp中的参数----"); valueFunc.PCall(); valueFunc.EndPCall(); valueFunc.Call("--这是CSharp中直接调用传入参数-----"); // Get Table LuaTable table = m_state.GetTable("mytable"); table.Call("tableFunc"); LuaFunction tableFunc = table.GetLuaFunction("tableFunc"); GameLogger.Log("Lua Table Function"); tableFunc.Call(); //这里访问的时table的变量,不是local或者全局变量 GameLogger.Log("Get Table Value local_num : " + table["local_num"]); GameLogger.Log("Get Table Value global_num : " + table["global_num"]); GameLogger.Log("Get Table Value table_num : " + table["table_num"]); for (int i = 0; i < table.Length; ++i) { GameLogger.Log("table " + i.ToString() + " : " + table[i + 1]); } LuaDictTable dicTable = table.ToDictTable(); foreach (var item in dicTable) { GameLogger.LogFormat("dicTable {0} -- {1}", item.Key, item.Value); } }
protected virtual void CallLuaFunction(string luaFunctionName) { if (m_currentLuaTable == null) { return; } m_currentLuaTable.Call(luaFunctionName, m_currentLuaTable); }
void OnTriggerEnter(Collider other) { var it = mLuaTables.GetEnumerator(); while (it.MoveNext()) { LuaTable table = it.Current.Value; table.Call("OnTriggerEnter", table, other); } }
void CallFunction(string name) { var it = mLuaTables.GetEnumerator(); while (it.MoveNext()) { LuaTable table = it.Current.Value; if (table != null) { table.Call(name, table); } } }
public LuaTable NewLuaPlayer(PlayerDisplay display) { if (m_LuaClass == null || display == null) { return(null); } LuaTable ret = m_LuaClass.Invoke <LuaTable, LuaTable>("new", m_LuaClass); if (ret != null) { ret.Call <LuaTable, PlayerDisplay>("OnInit", ret, display); } return(ret); }
void Start() { #if UNITY_5 || UNITY_2017 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); lua = new LuaState(); lua.Start(); DelegateFactory.Init(); lua.DoString(script); //Get the function object luaFunc = lua.GetFunction("test.luaFunc"); if (luaFunc != null) { int num = luaFunc.Invoke <int, int>(123456); Debugger.Log("generic call return: {0}", num); num = CallFunc(); Debugger.Log("expansion call return: {0}", num); Func <int, int> Func = luaFunc.ToDelegate <Func <int, int> >(); num = Func(123456); Debugger.Log("Delegate call return: {0}", num); num = lua.Invoke <int, int>("test.luaFunc", 123456, true); Debugger.Log("luastate call return: {0}", num); } LuaTable luaTable = lua.GetTable("test"); luaTable.Call <int>("luaFunc", 1000); LuaDictTable dict = luaTable.ToDictTable(); var iter2 = dict.GetEnumerator(); while (iter2.MoveNext()) { Debugger.Log("map item, k,v is {0}:{1}", iter2.Current.Key, iter2.Current.Value); } iter2.Dispose(); dict.Dispose(); luaTable.Dispose(); lua.CheckTop(); }
private void DestroyLuaPlayer() { try { if (m_LuaPlayer != null) { m_LuaPlayer.Call <LuaTable>("OnDestroy", m_LuaPlayer); m_LuaPlayer.Dispose(); m_LuaPlayer = null; } } catch (System.Exception e) { #if DEBUG Debug.LogError(e.ToString()); #endif } }
private static IEnumerator OnRequestDownload(long downloadSize) { hotUpdateClass = LuaFacade.GetTable("HotUpdate"); hotUpdateObject = hotUpdateClass.Invoke <LuaTable>("new"); hotUpdateClass.Call("Initialize", hotUpdateObject, downloadSize); yield return(null); while (!hotUpdateClass.Invoke <LuaTable, bool>("Response", hotUpdateObject)) { yield return(null); } if (hotUpdateClass.Invoke <LuaTable, bool>("Result", hotUpdateObject)) { AddressablesUpdater.Result = RequestDownloadResult.Agree; } else { AddressablesUpdater.Result = RequestDownloadResult.Disagree; } }
public void register(LuaRegister v) { engine.Call("register", v); }
public override void Execute(INotification notification) { commandClass.Call("Execute", commandObject, notification); }
public void CallAwake() { if (luaTable != null) { luaTable.Call("Awake", luaTable); } }
/// <summary> /// 加载场景 /// </summary> /// <param name="loadingWindowClass"></param> /// <returns></returns> private IEnumerator LoadingScene(LuaTable loadingWindowClass) { int showProgress = 80; while (showProgress < 100) { if (showProgress < 30) { showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else if (showProgress < 90) { yield return(new WaitUntil(delegate() { return _preloadIsEnd; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else { yield return(new WaitUntil(delegate() { return _prog.progress >= 0.9f; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } } //-----------------------------预加载资源加载完成,进入场景------------------------------ _prog.allowSceneActivation = true; //如果加载完成,可以进入场景 Scene scene = SceneManager.GetSceneByName(_id); yield return(new WaitUntil(delegate() { return scene.isLoaded; })); DebugManager.Log("enter scene:" + scene.name); GameObject[] objs = scene.GetRootGameObjects(); foreach (GameObject go in objs) { DebugManager.Log("go.name:" + go.name); if (go.name.Equals("Canvas")) { _loadBaseScene = new BaseScene(_id, _preloadList, _completeCallback, _progressCallback, _isCache, go.transform); LuaComponent luaComponent = go.AddComponent <LuaComponent>(); luaComponent.New(_luaSceneClass, _loadBaseScene); _completeCallback(_loadBaseScene); this.CurrScene = _loadBaseScene; _loadBaseScene = null; _id = null; break; } } }
public override void OnRegister() { proxyClass.Call("OnRegister", proxyObject); }
/// <summary> /// 开始拖拽 /// </summary> /// <param name="eventData"></param> public override void OnBeginDrag(PointerEventData eventData) { base.OnBeginDrag(eventData); if (onBeginDrag != null) { if (targetTable != null) { targetTable.Call("OnBeginDrag", targetTable, this.gameObject, eventData); } else { onBeginDrag(gameObject, eventData); } } }
public override void HandleNotification(INotification notification) { mediatorClass.Call("HandleNotification", mediatorObject, notification); }