-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExample109.cs
More file actions
70 lines (62 loc) · 1.7 KB
/
Example109.cs
File metadata and controls
70 lines (62 loc) · 1.7 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
using System;
using Puerts;
using UnityEngine;
using XLua;
/// <summary>
/// 调用脚本function
/// 逻辑: 调用Transform.Rotate
/// 参数: 1引用类型, 1个值类型(Vector3)
/// 返回值: UnityEngine.Quaternion
/// </summary>
[Test(100)]
public class Example109 : IExecute
{
[CSharpCallLua]
public delegate void TargetFunc(Transform transform, Vector3 param1);
[CSharpCallLua]
public delegate TargetFunc CreateFunc();
public bool Static => true;
public string Method => "payload(Transform,Vector3): void;";
public CallTarget Target => CallTarget.CSharpCallScript;
public object RunCS(int count)
{
throw new System.NotImplementedException();
}
public object RunJS(JsEnv env, int count)
{
var func = env.Eval<TargetFunc>(@"
function payload(transform, param1){
transform.Rotate(param1);
}
payload;
");
var obj = new GameObject().transform;
var eulers = new Vector3(1f, 2f, 3f);
for (int i = 0; i < count; i++)
{
func(obj, eulers);
}
var result = obj.rotation;
UnityEngine.Object.DestroyImmediate(obj.gameObject);
return result;
}
public object RunLua(LuaEnv env, int count)
{
var create = env.LoadString<CreateFunc>(@"
local function payload(transform, param1)
transform:Rotate(param1);
end
return payload;
");
var func = create();
var obj = new GameObject().transform;
var eulers = new Vector3(1f, 2f, 3f);
for (int i = 0; i < count; i++)
{
func(obj, eulers);
}
var result = obj.rotation;
UnityEngine.Object.DestroyImmediate(obj.gameObject);
return result;
}
}