void OnGUI() { if (GUI.Button(new Rect(10, 10, 120, 50), "Test")) { float time = Time.realtimeSinceStartup; Vector3 v = Vector3.one; for (int i = 0; i < 800000; i++) { v = transform.position; v += Vector3.one; transform.position = Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); transform.position = Vector3.zero; luaMgr.CallLuaFunction("Test", transform); } if (GUI.Button(new Rect(10, 70, 120, 50), "Test2")) { float time = Time.realtimeSinceStartup; Vector3 v = Vector3.one; for (int i = 0; i < 800000; i++) { v += Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test2", transform); } }
//----------------------------------------------- /// <summary> /// 执行Lua方法-无参数 /// </summary> protected object[] CallMethod(string func) { if (luaMgr == null) { return(null); } string funcName = name + "." + func; funcName = funcName.Replace("(Clone)", ""); return(mgr.CallLuaFunction(funcName)); }
void OnGUI() { if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, 120, 50), "Test")) { float time = Time.realtimeSinceStartup; for (int i = 0; i < 200000; i++) { transform.position = Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test", transform); ret = "Test OK!"; } else if (GUI.Button(new Rect(10, 80, 120, 50), "Coroutine")) { // LuaFunction func = luaMgr.GetLuaFunction("TestCo"); // thread = new LuaThread(luaMgr.lua, func); // thread.Start( } GUI.Label(new Rect(Screen.width / 2, Screen.height / 2, 120, 50), ret); }
/// <summary> /// 这个方法通过LuaScriptMgr来调用Lua方法 /// </summary> /// <param name="funcName"></param> /// <param name="args"></param> /// <returns></returns> protected object[] CallMethod(string funcName, params object[] args) { if (toLua == null) { return(null); } return(toLua.CallLuaFunction(funcName, args)); }
static int CallLuaFunction(IntPtr L) { int count = LuaDLL.lua_gettop(L); LuaScriptMgr obj = LuaScriptMgr.GetNetObject <LuaScriptMgr>(L, 1); string arg0 = LuaScriptMgr.GetLuaString(L, 2); object[] objs1 = LuaScriptMgr.GetParamsObject(L, 3, count - 2); object[] o = obj.CallLuaFunction(arg0, objs1); LuaScriptMgr.PushArray(L, o); return(1); }
// private LuaScriptMgr LoadLua(ref LuaScriptMgr lua, string luaPath) // { // try // { // if(!System.IO.File.Exists(luaPath)) // { // GUI.color = Color.red; // print("Not found:"+luaPath); // return lua; // } // FileStream aFile = new FileStream(luaPath,FileMode.Open); // StreamReader sr = new StreamReader(aFile); // string luaString = sr.ReadToEnd(); // if(!string.IsNullOrEmpty(luaString)) // lua.DoString(luaString); // else // print("lua:"+luaPath+" load fail!"); // sr.Close(); // } // catch (IOException ex) // { // Debug.LogError(ex.ToString()); // } // return lua; // } protected object[] Call(string functionName, params object[] args) { //Debug.LogError(functionName); if (lua == null) { return(null); } // if( lua.GetLuaFunction(functionName) == null) // return null; return(lua.CallLuaFunction(functionName, args)); }
public static object[] CallMethod(string module, string func, params object[] args) { LuaScriptMgr manager = AppFacade.Instance.GetManager <LuaScriptMgr>("LuaScriptMgr"); if (manager == null) { return(null); } string text = module + "." + func; text = text.Replace("(Clone)", string.Empty); return(manager.CallLuaFunction(text, args)); }
/// <summary> /// 执行Lua方法 /// </summary> public static object[] CallMethod(string module, string func, params object[] args) { LuaScriptMgr luaMgr = AppFacade.Instance.GetManager <LuaScriptMgr>(ManagerName.Lua); if (luaMgr == null) { return(null); } string funcName = module + "." + func; funcName = funcName.Replace("(Clone)", ""); return(luaMgr.CallLuaFunction(funcName, args)); }
/// <summary> /// 执行Lua方法 /// </summary> public static object[] CallMethod(string module, string func, params object[] args) { LuaScriptMgr luaMgr = Coo.luaManager; if (luaMgr == null) { return(null); } string funcName = module + "." + func; funcName = funcName.Replace("(Clone)", ""); return(luaMgr.CallLuaFunction(funcName, args)); }
void Start() { if (LuaScriptMgr.Instance == null) { new LuaScriptMgr(); } mgr = LuaScriptMgr.Instance; Debug.Log(startLuaTexts.name); Debug.Log(mgr); mgr.DoStringFile(startLuaTexts.name, startLuaTexts.text); mgr.CallLuaFunction("test"); mgr.Start(); }
public static void NotifyCloseAllPanel() { try { LuaScriptMgr luaScriptMgr = Pandora.Instance.GetLuaScriptMgr(); if (luaScriptMgr != null) { luaScriptMgr.CallLuaFunction("Common.NotifyCloseAllPanel", new object[0]); } } catch (Exception ex) { Logger.ERROR(ex.get_StackTrace()); } }
/// <summary> /// 释放资源 /// </summary> public void CheckExtractResource() { string path = Application.persistentDataPath + "/Game/"; bool isExists = Directory.Exists(path) && Directory.Exists(path + "lua/") && File.Exists(path + "files.txt"); if (isExists) { luaMgr = new LuaScriptMgr(); luaMgr.DoFile("Game/Login"); luaMgr.Start(); luaMgr.CallLuaFunction("GetUI", this.gameObject); print("-----------文件已经解压过了-----------"); return; //文件已经解压过了,自己可添加检查文件列表逻辑 } StartCoroutine(OnExtractResource()); //启动释放协成 }
public static object[] CallMethod(string module, string func, params object[] args) { try { LuaScriptMgr manager = AppFacade.Instance.GetManager <LuaScriptMgr>("LuaScriptMgr"); if (manager == null) { return(null); } string name = (module + "." + func).Replace("(Clone)", string.Empty); return(manager.CallLuaFunction(name, args)); } catch (Exception exception) { com.tencent.pandora.Logger.LogNetError(1, "CallMethond Error:" + module + "," + func + "," + exception.Message + "," + exception.StackTrace); return(null); } }
public static void NotifyAndroidPayFinish(string jsonData) { try { Logger.DEBUG("jsonData=" + jsonData); LuaScriptMgr luaScriptMgr = Pandora.Instance.GetLuaScriptMgr(); if (luaScriptMgr != null) { luaScriptMgr.CallLuaFunction("Common.NotifyAndroidPayFinish", new object[] { jsonData }); } } catch (Exception ex) { Logger.ERROR(ex.get_StackTrace()); } }
protected override void Init() { Screen.sleepTimeout = SleepTimeout.NeverSleep; LuaScriptMgr umgr = new LuaScriptMgr(); umgr.Start(); umgr.DoFile("game"); //object[] tem = uluaMgr.CallLuaFunction("Map.New"); //LuaTable table = tem[0] as LuaTable; //table[1] = 22; //table[2] = 33; umgr.CallLuaFunction("GameManager.OnInit"); //LuaMessageTransmitter lt = (LuaMessageTransmitter)GTLib.NetManager.GetTransmitter("test"); //lt.Call("Connect"); }
public static void ExecCallback(uint callId, string result) { try { Logger.DEBUG("callId=" + callId.ToString() + " result=" + result); LuaScriptMgr luaScriptMgr = Pandora.Instance.GetLuaScriptMgr(); if (luaScriptMgr != null) { luaScriptMgr.CallLuaFunction("Common.ExecCallback", new object[] { callId, result }); } } catch (Exception ex) { Logger.ERROR(ex.get_StackTrace()); } }
void OnGUI() { if (GUI.Button(new Rect(10, 10, 120, 50), "Test")) { lua.DoFile("Test.Lua"); float time = Time.realtimeSinceStartup; for (int i = 0; i < 10000; i++) { transform.position = Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); time = Time.realtimeSinceStartup; lua.CallLuaFunction("Test", transform); Debug.Log("lua cost time: " + (Time.realtimeSinceStartup - time)); } }
public static void NotifyPushData(string jsonData) { try { Logger.DEBUG("jsonData=" + jsonData); LuaScriptMgr luaScriptMgr = Pandora.Instance.GetLuaScriptMgr(); PandoraImpl pandoraImpl = Pandora.Instance.GetPandoraImpl(); if (luaScriptMgr != null && pandoraImpl.GetIsLuaMgrInited()) { luaScriptMgr.CallLuaFunction("Common.NotifyPushData", new object[] { jsonData }); } } catch (Exception ex) { Logger.ERROR(ex.get_StackTrace()); } }
public static void NotifyPushData(string actionName, string jsonData) { try { Logger.DEBUG("actionName=" + actionName + " jsonData=" + jsonData); LuaScriptMgr luaScriptMgr = Pandora.Instance.GetLuaScriptMgr(); if (luaScriptMgr != null) { luaScriptMgr.CallLuaFunction("Common.NotifyPushData", new object[] { actionName, jsonData }); } } catch (Exception ex) { Logger.ERROR(ex.get_StackTrace()); } }
/// <summary> /// 执行Lua方法 /// </summary> public static object[] CallMethod(string module, string func, params object[] args) { LuaScriptMgr luaMgr = Ctx.m_instance.m_luaScriptMgr; if (luaMgr == null) { return(null); } string funcName = ""; if (String.IsNullOrEmpty(module)) // 如果在 _G 表中 { funcName = func; } else // 在一个 _G 的一个表中 { funcName = module + "." + func; } // funcName = funcName.Replace("(Clone)", ""); return(luaMgr.CallLuaFunction(funcName, args)); }
void OnGUI() { if (GUI.Button(new Rect(10, 10, 120, 50), "Test")) { float time = Time.realtimeSinceStartup; for (int i = 0; i < 100000; i++) { transform.position = Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); time = Time.realtimeSinceStartup; luaMgr.CallLuaFunction("Test", transform); } else if (GUI.Button(new Rect(10, 80, 120, 50), "Coroutine")) { LuaFunction func = luaMgr.GetLuaFunction("myFunc"); thread = new LuaThread(luaMgr.lua, func); thread.Start(); } }
// void Awake () // { // // luaMgr = new LuaScriptMgr(); // luaMgr.Start(); // // LuaWapBinder.Bind(luaMgr.lua.L); // } // Use this for initialization void Start() { //timer = gameObject.AddComponent<Timer>(); luaMgr = GamePublic.Instance.LuaManager; //luaMgr.DoFile("Lua/Base/Test.Lua"); /* * luaMgr.DoFile("Lua/UI/StartMenu/StartMenuControl.lua"); * luaMgr.DoFile("Lua/UI/StartMenu/StartMenuView.lua"); * * luaMgr.CallLuaFunction("StartMenuControl.Initialize", GameObject.Find("UI Root/StartMenu(Clone)")); * * Type t = typeof(XMLLoader<XMLDataArms>); * Debug.Log(t.IsGenericType); * Debug.Log(t.Name); */ List <int> list = new List <int>(); list.Add(1); list.Add(2); luaMgr.CallLuaFunction("TestLua.TestList", list); /* * Debug.Log(typeof(List<int>).Name); * Debug.Log(typeof(List<object>).Name); * Debug.Log(typeof(List<int>) == typeof(List<object>)); * List<object> listObj = new List<object>(); * List<int> listInt = new List<int>(); * listInt.Add(1); * listInt.Add(2); * listObj = (List<object>)listInt; */ }
private IEnumerable DoStartGame() { LuaStatic.Load = CustomLoader; LuaStatic.LoadFromAssetsPath = LoadFromAssetsPath; LuaScriptMgr sm = LuaScriptMgr.Instance; yield return(null); foreach (var item in sm.Bind()) { yield return(item); } sm.Start(); yield return(null); try { sm.DoString("require [[init]]"); sm.DoString("require [[preload]]"); } catch (LuaScriptException e) { HobaDebuger.LogErrorFormat("LuaScriptException: {0}", e.Message); yield break; } yield return(null); var luaState = sm.GetLuaState(); if (luaState.L != IntPtr.Zero) { int oldTop = LuaDLL.lua_gettop(luaState.L); do { LuaDLL.lua_getglobal(luaState.L, "preload"); if (LuaDLL.lua_pcall(luaState.L, 0, 1, 0) != 0) { HobaDebuger.LogErrorFormat("LuaScriptException: {0}", LuaDLL.lua_tostring(luaState.L, -1)); yield break; } bool ret = LuaDLL.lua_toboolean(luaState.L, -1); LuaDLL.lua_pop(luaState.L, 1); if (ret) { break; } yield return(null); } while (true); LuaDLL.lua_settop(luaState.L, oldTop); yield return(null); } //设置scale sm.GetDesignWidthAndHeight(ref _DesignWidth, ref _DesignHeight); if (_DesignWidth > 0 && _DesignHeight > 0) { OSUtility.SetDesignContentScale(_DesignWidth, _DesignHeight); } yield return(null); try { if (!_BeForArtTest) { sm.CallLuaFunction("StartGame"); } else { sm.CallLuaFunction("SceneTest"); } _IsInited = true; } catch (LuaScriptException e) { HobaDebuger.LogErrorFormat("LuaScriptException: {0}", e.Message); _IsInited = false; } yield return(null); ReadResPath(); //读取C#端需要的lua路径 StartCoroutine(TickCoroutine().GetEnumerator()); yield return(null); }
// object[] CallMethod(string funcName, params Object[] objs) //{ // //调用 //} object[] CallMethod(string funcName, params object[] objs) { //Debug.Log(tolua.CallLuaFunction(funcName, objs)); return(tolua.CallLuaFunction(funcName, objs)); }
void OnGUI() { #pragma warning disable 219 if (GUI.Button(new Rect(10, 10, 120, 50), "Test")) { float time = Time.realtimeSinceStartup; Vector3 v = Vector3.one; for (int i = 0; i < 200000; i++) { v = transform.position; transform.position = Vector3.one; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); transform.position = Vector3.zero; luaMgr.CallLuaFunction("Test"); } if (GUI.Button(new Rect(10, 70, 120, 50), "Test2")) { float time = Time.realtimeSinceStartup; for (int i = 0; i < 200000; i++) { transform.Rotate(Vector3.up, 1); } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test2", transform); } if (GUI.Button(new Rect(10, 130, 120, 50), "Test3")) { float time = Time.realtimeSinceStartup; Vector3 v = Vector3.one; for (int i = 0; i < 200000; i++) { v = new Vector3(i, i, i); } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test3", transform); } if (GUI.Button(new Rect(10, 190, 120, 50), "Test4")) { float time = Time.realtimeSinceStartup; for (int i = 0; i < 200000; i++) { GameObject go = new GameObject(); } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test4", transform); } if (GUI.Button(new Rect(10, 250, 120, 50), "Test5")) { float time = Time.realtimeSinceStartup; for (int i = 0; i < 20000; i++) { GameObject go = new GameObject(); go.AddComponent <SkinnedMeshRenderer>(); SkinnedMeshRenderer sm = go.GetComponent <SkinnedMeshRenderer>(); sm.castShadows = false; sm.receiveShadows = false; } Debug.Log("c# cost time: " + (Time.realtimeSinceStartup - time)); luaMgr.CallLuaFunction("Test5", transform); } #pragma warning restore 219 }
private void OnGUI() { GUILayout.BeginHorizontal(); GUI.enabled = WorkEnable; if (GUILayout.Button("StartTrace", GUILayout.Height(30))) { isInTrace = true; LuaScriptMgr.CallLuaFunction("LT_StartLuaTrace", IsWhiteList, IsBlackList, WhiteList, BlackList); } GUI.enabled = WorkEnable && isInTrace; if (GUILayout.Button("StopTrace", GUILayout.Height(30))) { isInTrace = false; LuaRes.Clear(); Page = 0; var data = LuaScriptMgr.CallLuaFunction("LT_StopLuaTrace"); ReadData(); } GUI.enabled = true; GUILayout.EndHorizontal(); TreeViewWidth = position.width / 2 - 20; GUILayout.BeginVertical(); if (m_TreeView != null) { m_TreeView.OnGUI(new Rect(10, 35, TreeViewWidth, TreeViewHeight)); } GUILayout.EndVertical(); GUILayout.BeginArea(new Rect(TreeViewWidth + 30, 50, position.width - TreeViewWidth - 40, TreeViewHeight)); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.Label("选择编辑Lua文件的软件,目前支持sublime、vscode"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(CodeSoftPath, GUILayout.Width(TreeViewWidth - 80), GUILayout.Height(30)); if (GUILayout.Button("选择", GUILayout.Width(60))) { var exePath = EditorUtility.OpenFilePanel("选择Lua脚本编辑软件", "", "exe"); if (!string.IsNullOrEmpty(exePath)) { CodeSoftPath = exePath; PlayerPrefs.SetString(CodeSoftPathSaveKey, CodeSoftPath); } } GUILayout.EndHorizontal(); GUILayout.Space(50); //*******************************************黑名单白名单*******************************************// var isWhiteList = IsWhiteList; isWhiteList = GUILayout.Toggle(isWhiteList, "使用白名单(编辑后保存在本地,';'分隔)"); if (isWhiteList != IsWhiteList) { IsWhiteList = isWhiteList; IsBlackList = !isWhiteList; } var whiteList = WhiteList; whiteList = GUILayout.TextArea(whiteList, GUILayout.Height(80)); if (whiteList != WhiteList) { WhiteList = whiteList; PlayerPrefs.SetString(WhiteListSaveKey, WhiteList); } EditorGUILayout.Space(); var isBlackList = IsBlackList; isBlackList = GUILayout.Toggle(isBlackList, "使用黑名单(编辑后保存在本地,';'分隔))"); if (isBlackList != IsBlackList) { IsBlackList = isBlackList; IsWhiteList = !isBlackList; } var blackList = BlackList; blackList = GUILayout.TextArea(blackList, GUILayout.Height(80)); if (blackList != BlackList) { BlackList = blackList; PlayerPrefs.SetString(BlackListSaveKey, BlackList); } GUILayout.Space(50); //*******************************************翻页*******************************************// GUILayout.BeginHorizontal(); GUI.enabled = Page > 0; var showBtn = string.Format("上一页({0})", Page); if (GUILayout.Button(showBtn, GUILayout.Height(30))) { if (Page > 0) { Page--; MakeTree(); } } var totalPage = LuaRes.Count / PageShowCount - 1; GUI.enabled = Page <= totalPage; showBtn = string.Format("下一页({0})", totalPage - Page + 1); if (GUILayout.Button(showBtn, GUILayout.Height(30))) { Page++; MakeTree(); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(50); //*******************************************调试*******************************************// AutoGoToCodeSoft = GUILayout.Toggle(AutoGoToCodeSoft, "自动跳转到Lua代码(需要设置上面编辑软件路径)"); if (AutoGoToCodeSoft) { GUILayout.BeginHorizontal(); if (GUILayout.Button("上一步", GUILayout.Height(30))) { var sel = m_TreeView.GetSelection(); if (sel.Count > 0 && sel[0] > 0) { m_TreeView.SetSelection(new int[] { sel[0] - 1 }, TreeViewSelectionOptions.FireSelectionChanged); } } if (GUILayout.Button("下一步", GUILayout.Height(30))) { var sel = m_TreeView.GetSelection(); if (sel.Count > 0 && sel[0] < m_TreeView.GetRows().Count) { m_TreeView.SetSelection(new int[] { sel[0] + 1 }, TreeViewSelectionOptions.FireSelectionChanged); } } GUILayout.EndHorizontal(); } GUILayout.EndArea(); }
public object[] CallLuaFunction(string funcName, params object[] args) { return(luaMgr.CallLuaFunction(funcName, args)); }