public void OpenPanel(string filePath, LuaRef fn, LuaRef inst) { OpenPanel(filePath, (go) => { fn.Call(inst, go); }); }
public void Run(string file) { luna.DoFile(file); update = luna.GetGlobal("update"); fixedUpdate = luna.GetGlobal("fixedUpdate"); lateUpdate = luna.GetGlobal("lateUpdate"); }
public static void ScrollRectListener(ScrollRect sr, LuaFunction func, LuaRef self) { CacheLuaFunction(sr, func); sr.onValueChanged.AddListener((vc2) => { func.Call(self, vc2); }); }
private void treeView2_BeforeExpand(object sender, TreeViewCancelEventArgs e) { LuaRef v = (LuaRef)e.Node.Tag; if (v.IsTable) { Refresh(v, e.Node.Nodes, 2); } }
public static void ScrollbarListener(Scrollbar scrollbar, LuaFunction func, LuaRef self) { CacheLuaFunction(scrollbar, func); scrollbar.onValueChanged.RemoveAllListeners(); scrollbar.onValueChanged.AddListener((val) => { func.Call(self, val); }); }
public static void ToggleListener(Toggle toggle, LuaFunction func, LuaRef self) { CacheLuaFunction(toggle, func); toggle.onValueChanged.RemoveAllListeners(); toggle.onValueChanged.AddListener((val) => { func.Call(self, val); }); }
private void treeView2_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { LuaRef v = (LuaRef)e.Node.Tag; if (v.IsTable) { Refresh(v, e.Node.Nodes, 2); } }
public static void DropdownListener(Dropdown dropdown, LuaFunction func, LuaRef self) { CacheLuaFunction(dropdown, func); dropdown.onValueChanged.RemoveAllListeners(); dropdown.onValueChanged.AddListener((val) => { func.Call(self, val); }); }
void EnumerateTable(LunaTreeViewItem parent, LuaRef parentLuaRef, int depth) { if (depth <= 0) { return; } string parentPath = parent.fullPath; var it = parentLuaRef.GetEnumerator(); while (it.MoveNext()) { var key = it.Current.Key(); var k = key.ToString(); if (k == "_G") { continue; } var v = it.Current.Value(); string fullPath = string.Join(".", parentPath, k); int hash = fullPath.GetHashCode(); if (!treeViewItems.TryGetValue(hash, out var tvi)) { id2v[hash] = v; id2fullPath[hash] = fullPath; string strDisplay = k; if (v.Type <= LuaType.String) { strDisplay += (" : " + v.ToString()); } tvi = new LunaTreeViewItem { id = hash, depth = parent.depth + 1, displayName = strDisplay }; tvi.fullPath = fullPath; tvi.luaType = v.Type; treeViewItems[hash] = tvi; parent.AddChild(tvi); } if (v.IsTable) { tvi.icon = EditorGUIUtility.FindTexture("Folder Icon"); EnumerateTable(tvi, v, depth - 1); } } it.Dispose(); parent.children?.Sort(); }
protected virtual void Awake() { if (!string.IsNullOrEmpty(luaPath)) { var luna = LunaClient.Luna; var L = luna.State; int index = luaPath.LastIndexOf("."); if (index != -1) { className = luaPath.Remove(index); } else { className = luaPath; } index = className.LastIndexOf("/"); if (index != -1) { className = className.Substring(index + 1); } scriptClass = luna.GetGlobal(className) as LuaRef; if (!scriptClass) { luna.DoFile(luaPath); scriptClass = luna.GetGlobal(className) as LuaRef; if (!scriptClass) { return; } } var metaTable = scriptClass.GetMetaTable(); if (metaTable) { var ctor = metaTable.RawGet("__call") as LuaRef; scriptInstance = ctor.Call <LuaRef>(metaTable); metaTable.Dispose(); } else { Debug.Log("GetMetaTable failed : " + className); } scriptInstance["gameObject"] = gameObject; scriptInstance["transform"] = gameObject.transform; scriptInstance["behaviour"] = this; onEnableFn = scriptClass.Get("onEnable") as LuaRef; onDisableFn = scriptClass.Get("onDisable") as LuaRef; updateFn = scriptClass.Get("update") as LuaRef; CallFunc("awake"); } }
void Refresh(LuaRef table, TreeNodeCollection node, int depth) { if (depth <= 0) { return; } var meta = table.GetMetaTable(); if (meta) { var k = "metatable"; var v = meta; TreeNode n; if (!node.ContainsKey(k)) { n = node.Add(k, k); n.Tag = v; } else { n = node[k]; } Refresh(v, n.Nodes, depth - 1); } foreach (var t in table) { var key = t.Key(); var k = key.ToString(); if (k == "_G") { continue; } var v = t.Value(); TreeNode n; if (!node.ContainsKey(k)) { n = node.Add(k, k); n.Tag = v; } else { n = node[k]; } if (v.IsTable) { Refresh(v, n.Nodes, depth - 1); } } }
void TickUnref() { if (Time.frameCount % 30 != 0) { return; } while (!_refGCList.IsEmpty()) { LuaRef lf = _refGCList.Dequeue(); LuaDLL.lua_unref(lf.L, lf.reference); } }
protected override TreeViewItem BuildRoot() { var root = new TreeViewItem { id = 0, depth = -1, displayName = "_G" }; SetExpanded(0, true); if (luna != null) { string fullPath = "_G"; int hash = fullPath.GetHashCode(); var item = new LunaTreeViewItem { id = hash, depth = 1, displayName = "_G" }; LuaRef luaRef = luna.Global; item.luaType = luaRef.Type; item.fullPath = fullPath; id2v[hash] = luaRef; id2fullPath[hash] = fullPath; treeViewItems[hash] = item; lastExpendedIDs.Clear(); lastExpendedIDs.Add(hash); SetExpanded(hash, true); item.icon = EditorGUIUtility.FindTexture("Folder Icon"); root.AddChild(item); EnumerateTable(item, luaRef, 2); } else { var item = new TreeViewItem { id = 0, depth = 1, displayName = "_G" }; root.AddChild(item); } // Return root of the tree return(root); }
public static void AddEventTrigger(GameObject go, EventTriggerType eventTriggerType, LuaFunction luaFunc, LuaRef self) { if (go == null || luaFunc == null) { return; } CacheLuaFunction(go, luaFunc); UnityAction <BaseEventData> click = (data) => { luaFunc.Call(self, go, data); }; EventTrigger.Entry eventTrigger = new EventTrigger.Entry(); eventTrigger.eventID = eventTriggerType; eventTrigger.callback.AddListener(click); EventTrigger trigger = go.GetComponent <EventTrigger>(); if (trigger == null) { trigger = go.AddComponent <EventTrigger>(); } for (int i = 0; i < trigger.triggers.Count; ++i) { if (trigger.triggers[i].eventID == eventTriggerType) { return; } } trigger.triggers.Add(eventTrigger); }
public static void InputFieldEndEdit(InputField inputfield, LuaFunction func, LuaRef self) { CacheLuaFunction(inputfield, func); inputfield.onEndEdit.RemoveAllListeners(); inputfield.onEndEdit.AddListener((val) => { func.Call(self, val); }); }
public static void ButtonListener(Button btn, LuaFunction luaFunc, LuaRef self) { CacheLuaFunction(btn, luaFunc); btn.onClick.AddListener(() => luaFunc.Call(self)); }
public static void AddClick(GameObject go, LuaFunction luaFunc, LuaRef self) { CacheLuaFunction(go, luaFunc); go.GetComponent <Button>().onClick.AddListener(() => luaFunc.Call(self, go)); }
public static void AddListener(LuaRef action) { tableTree.recharge(() => action.Call()); }