summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs
blob: 8c141a25b443ea0208369437b9e30c09fed82460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using UnityEngine;
using System.Collections;
using LuaInterface;
using System.Text;

public class LuaDlg : MonoBehaviour
{

    private LuaScriptMgr mgr;

    private string m_name
    {
        get { return name.Substring(0, 1).ToUpper() + name.Substring(1); }
    }

    private const string AWAKE = "Awake";
    private const string START = "Start";
    private const string ENABLE = "OnEnable";
    private const string DISABLE = "OnDisable";
    private const string HIDE = "OnHide";
    private const string SHOW = "OnShow";
    private const string DESTROY = "OnDestroy";

    void Awake()
    {
        mgr = HotfixManager.Instance.GetLuaScriptMgr();
        mgr.DoFile("Lua" + m_name + ".lua");
        LuaFunction func = mgr.GetLuaFunction(StrAppend(AWAKE));
        if (func != null) func.Call(gameObject);
    }


    void Start()
    {
        if (mgr != null)
        {
            LuaFunction func = mgr.GetLuaFunction(StrAppend(START));
            if (func != null) func.Call();
        }
    }


    void OnEnable()
    {
        if (mgr != null)
        {
            LuaFunction func = mgr.GetLuaFunction(StrAppend(ENABLE));
            if (func != null) func.Call();
        }
    }



    void OnDisable()
    {
        if (mgr != null)
        {
            LuaFunction func = mgr.GetLuaFunction(StrAppend(DISABLE));
            if (func != null) func.Call();
        }
    }

    public void OnHide()
    {
        if (mgr != null)
        {
            LuaFunction func = mgr.GetLuaFunction(StrAppend(HIDE));
            if (func != null) func.Call();
        }
    }


    public void OnDestroy()
    {
        if (mgr != null)
        {
            try
            {
                LuaFunction func = mgr.GetLuaFunction(StrAppend(DESTROY));
                if (func != null) func.Call();
            }
            catch { };
        }
    }


    public void OnShow()
    {
        if (mgr != null)
        {
            LuaFunction func = mgr.GetLuaFunction(StrAppend(SHOW));
            if (func != null) func.Call();
        }
    }


    private string StrAppend(string func)
    {
        StringBuilder sb = new StringBuilder("Lua");
        sb.Append(m_name);
        sb.Append(".");
        sb.Append(func);
        return sb.ToString();
    }

}