using UnityEngine; using System.Collections; using System.Collections.Generic; using XLua; using System; using System.IO; [LuaCallCSharp] public class LuaBehaviour : MonoBehaviour { [CSharpCallLua] public delegate void generalDelegate(); public string fileName; private Action luaOnEnable; private Action luaStart; private Action luaUpdate; private Action luaOnDisable; private Action luaOnDestroy; private LuaTable table; void Awake() { table = LuaUtility.GetNewTable(); var meta = LuaUtility.GetNewTable(); meta.Set("__index", LuaUtility.Global); table.SetMetaTable(meta); meta.Dispose(); table.Set("this", this); LuaUtility.DoString(fileName, "LuaBehaviour", table); var luaAwake = table.Get("Awake"); table.Get("OnEnable", out luaOnEnable); table.Get("Start", out luaStart); table.Get("Update", out luaUpdate); table.Get("OnDisable", out luaOnDisable); table.Get("OnDestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } } private void OnEnable() { if (luaOnEnable != null) { luaOnEnable(); } } void Start() { if (luaStart != null) { luaStart(); } } void Update() { if (luaUpdate != null) { luaUpdate(); } } private void OnDisable() { if (luaOnDisable != null) { luaOnDisable(); } } void OnDestroy() { if (luaOnDestroy != null) { luaOnDestroy(); } luaOnDisable = null; luaOnEnable = null; luaOnDestroy = null; luaUpdate = null; luaStart = null; table.Dispose(); } }