-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExample8.cs
More file actions
73 lines (64 loc) · 1.93 KB
/
Example8.cs
File metadata and controls
73 lines (64 loc) · 1.93 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
using Puerts;
using UnityEngine;
using XLua;
/// <summary>
/// 静态方法调用
/// 逻辑: 调用Transform.Rotate
/// 参数: 1引用类型, 3个值类型
/// 返回值: UnityEngine.Quaternion
/// </summary>
[Test]
[TestGroup("xyz vs Vector3", 1, Desc = "xyz传参 vs Vector3传参")]
public class Example8 : IExecute
{
public bool Static => true;
public string Method => "Quaternion Payload(Transform, float, float, float);";
public CallTarget Target => CallTarget.ScriptCallCSharp;
public object RunCS(int count)
{
var obj = new GameObject().transform;
for (var i = 0; i < count; i++)
{
Example8.Payload(obj, i % 3f, i % 4f, i % 5f);
}
var result = obj.rotation;
Object.DestroyImmediate(obj.gameObject);
return result;
}
public object RunJS(JsEnv env, int count)
{
var result = env.Eval<Quaternion>(string.Format(
@"(function() {{
var Example = require('csharp').Example8;
var obj = new (require('csharp').UnityEngine.GameObject)().transform;
for(let i = 0; i < {0}; i++){{
Example.Payload(obj, i % 3, i % 4, i % 5);
}}
var result = obj.rotation;
require('csharp').UnityEngine.Object.DestroyImmediate(obj.gameObject);
return result;
}})()", count));
return result;
}
public object RunLua(LuaEnv env, int count)
{
object[] result = env.DoString(string.Format(
@"
return (function()
local Example = CS.Example8;
local obj = CS.UnityEngine.GameObject().transform;
for i = 0,{0} do
Example.Payload(obj, i % 3, i % 4, i % 5);
end
local result = obj.rotation;
CS.UnityEngine.Object.DestroyImmediate(obj.gameObject);
return result;
end)()
", count - 1));
return result != null && result.Length > 0 ? result[0] : null;
}
public static void Payload(Transform transform, float x, float y, float z)
{
transform.Rotate(x, y, z);
}
}