-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXLuaBehaviour.cs
More file actions
88 lines (76 loc) · 1.54 KB
/
XLuaBehaviour.cs
File metadata and controls
88 lines (76 loc) · 1.54 KB
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;
[LuaCallCSharp]
public class XLuaBehaviour : MonoBehaviour
{
public TextAsset luaScript;
public Injection[] injections;
private Action luaStart;
private Action luaUpdate;
private Action luaOnDestroy;
private Action<string> LuaCustomize;
public LuaTable main;
void Awake()
{
main = AppMng.luaEnv.NewTable();
LuaTable meta = AppMng.luaEnv.NewTable();
meta.Set("__index", AppMng.luaEnv.Global);
main.SetMetaTable(meta);
meta.Dispose();
main.Set("this", this);
foreach (var injection in injections)
{
main.Set(injection.name, injection.value);
}
AppMng.luaEnv.DoString(luaScript.text, luaScript.name, main);
Action luaAwake = main.Get<Action>("awake");
main.Get("start", out luaStart);
main.Get("update", out luaUpdate);
main.Get("ondestroy", out luaOnDestroy);
main.Get("customize", out LuaCustomize);
if (luaAwake != null)
{
luaAwake();
}
// Debug.LogWarning (main);
// Debug.LogWarning ("Awake:"+name);
}
// Use this for initialization
void Start ()
{
if (luaStart != null)
{
luaStart();
}
}
// Update is called once per frame
void Update ()
{
if (luaUpdate != null)
{
luaUpdate();
}
}
void OnDestroy()
{
if (luaOnDestroy != null)
{
luaOnDestroy();
}
luaOnDestroy = null;
luaUpdate = null;
luaStart = null;
main.Dispose();
injections = null;
}
public void Customize(string _event)
{
if(LuaCustomize!=null)
{
LuaCustomize (_event);
}
}
}