void Start() { lua = new LuaSvr(); self = (LuaTable)lua.start("LuaFiles/building_txt"); //self = (LuaTable)lua.luaState.getObject("data"); //object o = lua.luaState.getFunction("GetData").call(); Debug.Log("table " + ((LuaTable)self[1])["name"]); LuaFunction dataFunction = ((LuaFunction)self["GetData"]); LuaTable dataTable = (LuaTable)dataFunction.call(); LuaFunction callFunction = (LuaFunction)self["CallBack"]; callFunction.call(222); //lua.luaState.getFunction("CallBack").call(); lua.luaState.getFunction("Call").call(2); Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + " is Null " + (callFunction == null)); LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call(); Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]); LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1"); test2 = (LuaFunction)self["test"]; object o = test2.call(self,9,1); Debug.Log("add function :"+o); SetTransform = (LuaFunction)self["SetTransform"]; SetTransform.call(self, tr); //tr.localPosition = new Vector3(2, 2, 2); }
public static void ShowMsg(string msg) { SLua.LuaFunction luaFunc = MyLuaSrv.Instance.GetFunction("BridgingClass.ShowMsg"); if (null != luaFunc) { luaFunc.call(msg); } }
// 处理消息 public void DealWithSocketData(ReceiveMsg msgData) { // lua 处理协议 SLua.LuaFunction func = LuaGameManager.Instance().GetState().getFunction("OnProtobufCallBack"); if (func != null) { func.call(msgData.data.handleId, new SLua.ByteArray(msgData.data.data)); } }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="eachFn"></param> public static void ForeachChild(GameObject parent, LuaFunction eachFn) { Transform pr=parent.transform; int count = pr.childCount; Transform child = null; for (int i = 0; i < count; i++) { child = pr.GetChild(i); eachFn.call(i, child.gameObject); } }
// CS 向Lua发送事件 public static void PostLuaEvent(string eventName, params object[] args) { if (!LuaGameManager.Instance().CheckAvailable()) { return; } SLua.LuaFunction func = LuaGameManager.Instance().GetState().getFunction("OnHandleEventFromCS"); if (func != null) { func.call(eventName, args); } }
void CallMethod(KeyCode key, bool bDown) { if (!SLua.LuaSvr.inited || null == SLua.LuaSvr.mainState) { return; } SLua.LuaState l = SLua.LuaSvr.mainState; SLua.LuaFunction func = l.getFunction("OnHotKeyInput"); if (null != func) { func.call(key, bDown); func.Dispose(); } }
private static void AddClick(Transform transform, SLua.LuaFunction function) { if (transform == null) { return; } var button = transform.GetComponent <UIButton>(); if (button) { button.onClick.Add(new EventDelegate(delegate() { if (function != null) { function.call(); } })); } }
static bool ReportLog(LogType type, string str) { if (!SLua.LuaSvr.inited || null == SLua.LuaSvr.mainState) { return(false); } SLua.LuaState l = SLua.LuaSvr.mainState; if (null == l) { return(false); } SLua.LuaFunction func = l.getFunction("OnUnityLog"); if (null != func) { func.call(new object[] { type, str }); func.Dispose(); return(true); } return(false); }
void InitKeyCodeMap() { if (bInited) { return; } if (null == LuaSvr.main || !LuaSvr.main.inited || null == LuaSvr.main.luaState) { return; } SLua.LuaState l = SLua.LuaSvr.main.luaState; if (null == l) { return; } bInited = true; SLua.LuaFunction func = l.getFunction("OnHotKeyCodeMap"); if (null != func) { LuaTable ret = func.call() as LuaTable; foreach (var obj in ret) { object value = obj.value; int ival = Convert.ToInt32(value); KeyCode key = (KeyCode)Enum.ToObject(typeof(KeyCode), ival); if (!sKeyCodeMap.ContainsKey(key)) { sKeyCodeMap.Add(key, true); } else { sKeyCodeMap[key] = true; } } func.Dispose(); } }
public void Update() { if (mWriteTxt != null && mWriteTxt.Count > 0) { if (_luaTable != null) { SLua.LuaFunction callback = _luaTable["OnLogCallback"] as SLua.LuaFunction; if (callback != null) { callback.call(mWriteTxt[0]); } } using (StreamWriter writer = new StreamWriter(logPath, true, Encoding.UTF8)) { FLog log = mWriteTxt[0] as FLog; string s = string.Format("{0}\n{1}", log.content, log.track); writer.WriteLine(s); writer.Close(); } mWriteTxt.RemoveAt(0); } }
private IEnumerator _ExecuteWhen(object instruction,LuaFunction func,object param) { yield return instruction; func.call(param); }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="eachFn"></param> public static void ForeachChild(ReferGameObjects parent, LuaFunction eachFn) { List<GameObject> lists = parent.refers; int count = lists.Count; GameObject child = null; for (int i = 0; i < count; i++) { child = lists[i]; eachFn.call(i, child); } }
/// <summary> /// lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain,LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath("font.u3d"); WWW luaLoader = new WWW(luaP); yield return luaLoader; if (luaLoader.error == null) { byte[] byts=CryptographHelper.Decrypt(luaLoader.bytes,DESHelper.instance.Key,DESHelper.instance.IV); AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); TextAsset[] all = item.LoadAllAssets<TextAsset>(); foreach (var ass in all) { keyName = ass.name; luacache[keyName] = ass; } item.Unload(false); luaLoader.Dispose(); } DoUnity3dLua(); if (domain) DoMain(); if (onLoadedFn != null) onLoadedFn.call(); }
private static IEnumerator DelayDo(LuaFunction luafun,float time,params object[] args) { yield return new WaitForSeconds(time); luafun.call(args); }
/// <summary> /// /// </summary> /// <param name="ab"></param> /// <param name="luaFn"></param> public static void UnpackConfigAssetBundleFn(AssetBundle ab, LuaFunction luaFn) { callBackFn = luaFn; #if UNITY_5 UnityEngine.Object[] all = ab.LoadAllAssets(); #else UnityEngine.Object[] all = ab.LoadAll(); #endif foreach (UnityEngine.Object i in all) { if (i is TextAsset) { TextAsset a = (TextAsset)i; if (callBackFn != null) callBackFn.call(a.name, a.text); } } }
private IEnumerator doCoroutine(YieldInstruction ins, LuaFunction fn) { yield return ins; fn.call(); }
public static IEnumerator yieldReturn(object y, LuaFunction f) { if (y is IEnumerator) yield return mb.StartCoroutine((IEnumerator)y); else yield return y; f.call(); }
/// <summary> /// 加载lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain,LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath("font.u3d"); //Debug.Log("load lua bundle" + luaP); WWW luaLoader = new WWW(luaP); yield return luaLoader; if (luaLoader.error == null) { byte[] byts=CryptographHelper.Decrypt(luaLoader.bytes,DESHelper.instance.Key,DESHelper.instance.IV); AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); // item = luaLoader.assetBundle; #if UNITY_5 TextAsset[] all = item.LoadAllAssets<TextAsset>(); foreach (var ass in all) { keyName = Regex.Replace(ass.name,@"\.",""); //Debug.Log("cache : " + keyName); luacache[keyName] = ass; } #else UnityEngine.Object[] all = item.LoadAll(typeof(TextAsset)); foreach (var ass in all) { keyName = Regex.Replace(ass.name,@"\.",""); Debug.Log(keyName + " complete"); luacache[keyName] = ass as TextAsset; } #endif //Debug.Log("loaded lua bundle complete" + luaP); // luaLoader.assetBundle.Unload(false); item.Unload(false); luaLoader.Dispose(); } DoUnity3dLua(); if (domain) DoMain(); if (onLoadedFn != null) onLoadedFn.call(); }
static public IEnumerator buildEnumerator(LuaFunction f) { f.call(); yield break; }
private static IEnumerator DelayDo(LuaFunction luafun, object arg, float time) { yield return new WaitForSeconds(time); luafun.call(arg); }
/// <summary> /// lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath(Common.LUA_ASSETBUNDLE_FILENAME); WWW luaLoader = new WWW(luaP); yield return luaLoader; if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV); #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); #else AssetBundle item = AssetBundle.LoadFromMemory(byts); #endif TextAsset[] all = item.LoadAllAssets<TextAsset>(); foreach (var ass in all) { keyName = ass.name; SetRequire(keyName, ass); } item.Unload(true); luaLoader.Dispose(); } if (domain) DoMain(); if (onLoadedFn != null) onLoadedFn.call(); }