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
|
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using XLua;
public delegate void CustomCall();
[CSharpCallLua] public delegate int CustomCall2(int a);
[CSharpCallLua] public delegate int CustomCall3(int a, out float b, out bool d, out string e, out int f);
[CSharpCallLua] public delegate void CustomCall4(string a, params int[] args); public class Lesson5_CallFunction : MonoBehaviour { private void Start() { LuaManager.Instance.Init(); LuaManager.Instance.DoLuaFile("Main"); CustomCall call = LuaManager.Instance.Global.Get<CustomCall>("testFun"); call(); UnityAction ua = LuaManager.Instance.Global.Get<UnityAction>("testFun"); ua(); Action action = LuaManager.Instance.Global.Get<Action>("testFun"); action(); LuaFunction lf = LuaManager.Instance.Global.Get<LuaFunction>("testFun"); lf.Call(); CustomCall2 call2 = LuaManager.Instance.Global.Get<CustomCall2>("testFun2"); Debug.Log(call2(10)); Func<int, int> sFunc = LuaManager.Instance.Global.Get<Func<int, int>>("testFun2"); Debug.Log(sFunc(100)); LuaFunction lf2 = LuaManager.Instance.Global.Get<LuaFunction>("testFun2"); Debug.Log(lf2.Call(1000)[0]); CustomCall3 call3 = LuaManager.Instance.Global.Get<CustomCall3>("testFun3"); float b; bool c; string d; int e; Debug.Log(call3(10, out b, out c, out d, out e) + "-" + b + "-" + c + "-" + d + "-" + e); LuaFunction lf3 = LuaManager.Instance.Global.Get<LuaFunction>("testFun3"); object[] objs = lf3.Call(1000); foreach(var item in objs) { Debug.Log(item); } CustomCall4 call4 = LuaManager.Instance.Global.Get<CustomCall4>("testFun4"); call4("array: ", 1, 2, 3, 4, 5); LuaFunction lf4 = LuaManager.Instance.Global.Get<LuaFunction>("testFun4"); lf4.Call("array2: ", 6, 7, 8, 9, 10); } }
|