protected object CallMethod(LuaMonoMethod method, object arg0, object arg1) { if (m_mapMonoMethod == null) { return(null); } func = null; int i = (int)method; func = m_mapMonoMethod[i]; if (func == null) { return(null); } try { if (m_table != null) { return(func.call(m_table, arg0, arg1)); } } catch (System.Exception e) { Debug.LogWarning(FormatException(e), gameObject); } return(null); }
protected object CallMethod(LuaMonoMethod method, params object[] args) { if (m_mapMonoMethod == null) { return(null); } func = null; int i = (int)method; func = m_mapMonoMethod[i]; if (func == null) { return(null); } try { if (args != null) { return(func.call(args)); } return(func.call()); } catch (System.Exception e) { Debug.LogWarning(FormatException(e), gameObject); } return(null); }
private void SetBehaviour(LuaTable myTable) { m_table = myTable; m_table["this"] = this; m_table["transform"] = transform; m_table["gameObject"] = this.gameObject; //m_mapMonoMethod = new Dictionary<LuaMonoMethod, LuaFunction>(); int len = System.Enum.GetValues(typeof(LuaMonoBehaviour.LuaMonoMethod)).Length; m_mapMonoMethod = new LuaFunction[len]; if (mLuaMonoMethd == null) { mLuaMonoMethd = new string[len]; for (int i = 0; i < len; i++) { LuaMonoMethod method = (LuaMonoMethod)i; mLuaMonoMethd[i] = method.ToString(); } } for (int i = 0; i < len; i++) { string methodName = mLuaMonoMethd[i]; m_mapMonoMethod[i] = m_table[methodName] as LuaFunction; } CallMethod(LuaMonoMethod.Start); CallMethod(LuaMonoMethod.OnEnable); if (this.gameObject.activeSelf == false) { //OnDestroy被调用的前提是,这个gameObject被激活过 this.gameObject.SetActive(true); this.gameObject.SetActive(false); } }