uLua记录--UILua

来源:互联网 发布:淘宝店铺运营公司 编辑:程序博客网 时间:2024/06/06 06:44

UILua绑定在UI上,根据UI名字自动执行Lua脚本

public class UILua : MonoBehaviour {    private LuaTable mLuaTable = null;    private LuaFunction OnInitFunciton = null;    private LuaFunction AwakeFunction = null;    private LuaFunction StartFunction = null;    private LuaFunction UpdateFunction = null;    private LuaFunction EnableFunction = null;    private LuaFunction DisableFunction = null;    private LuaFunction LateUpdateFunction = null;    void Awake()    {        LuaMgr.Instance.Start();        mLuaTable = LuaMgr.Instance.OnLoadLuaTable(gameObject.name);        if (mLuaTable != null)        {            OnInitFunciton = mLuaTable.RawGetFunc("OnInit");            AwakeFunction = mLuaTable.RawGetFunc("Awake");            StartFunction = mLuaTable.RawGetFunc("Start");            UpdateFunction = mLuaTable.RawGetFunc("Update");            EnableFunction = mLuaTable.RawGetFunc("OnEnable");            DisableFunction = mLuaTable.RawGetFunc("OnDisable");            LateUpdateFunction = mLuaTable.RawGetFunc("LateUpdate");        }        else        {            Debug.LogError("Can not find " + gameObject.name + ".lua");        }        if (AwakeFunction != null)        {            AwakeFunction.Call(gameObject);        }    }    void OnEnable()    {        if (EnableFunction != null)        {            EnableFunction.Call();        }    }    void OnDisable()    {        if (DisableFunction != null)        {            DisableFunction.Call();        }    }    void Start()    {        if (StartFunction != null)        {            StartFunction.Call();        }    }    // Update is called once per frame    void Update()    {        if (UpdateFunction != null)        {            UpdateFunction.Call();        }    }    void LateUpdate()    {        if (LateUpdateFunction != null)        {            LateUpdateFunction.Call();        }    }    void OnDestroy()    {        OnInitFunciton = null;        AwakeFunction = null;        StartFunction = null;        UpdateFunction = null;        EnableFunction = null;        DisableFunction = null;        LateUpdateFunction = null;        if (mLuaTable != null)        {            mLuaTable.Release();            mLuaTable = null;        }    }}

注:个人学习记录

0 0
原创粉丝点击