【发布时间】:2020-04-02 18:57:06
【问题描述】:
我一直在努力思考如何创建这个函数调用,我在 Lua 中编写没有问题,但我正在将内容转换为 C# 以离开 Lua 并转向新的东西。非常感谢我能得到的任何帮助,我附上了工作 Lua 代码,就我在 C# 中得到的而言,我还在我无法弄清楚的部分代码中添加了注释。
Lua 代码:
Progress({
name = "unique_action_name",
duration = 1000,
label = 'Doing Something',
useWhileDead = true,
canCancel = true,
controlDisables = {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
},
animation = {
animDict = "missheistdockssetup1clipboard@base",
anim = "base",
flags = 49,
},
prop = {
model = "p_amb_clipboard_01",
bone = 18905,
coords = { x = 0.10, y = 0.02, z = 0.08 },
rotation = { x = -80.0, y = 0.0, z = 0.0 },
},
propTwo = {
model = "prop_pencil_01",
bone = 58866,
coords = { x = 0.12, y = 0.0, z = 0.001 },
rotation = { x = -150.0, y = 0.0, z = 0.0 },
},
}, function(cancelled)
if not cancelled then
-- Do Something If Action Wasn't Cancelled
else
-- Do Something If Action Was Cancelled
end
end)
到目前为止,我已经获得了 C# 代码
Progress(new {
name = "unique_action_name",
duration = 1000,
label = "Doing Something",
useWhileDead = true,
canCancel = true,
controlDisables = new {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
},
animation = new {
animDict = "missheistdockssetup1clipboard@base",
anim = "base",
flags = 49,
},
prop = new {
model = "p_amb_clipboard_01",
bone = 18905,
coords = new { x = 0.10, y = 0.02, z = 0.08 },
rotation = new { x = -80.0, y = 0.0, z = 0.0 },
},
propTwo = new {
model = "prop_pencil_01",
bone = 58866,
coords = new { x = 0.12, y = 0.0, z = 0.001 },
rotation = new { x = -150.0, y = 0.0, z = 0.0 },
},
}, function(cancelled) { // < This part here is the question that rises for me, no clue how to call this in C#
if (!cancelled)
//Do Something If Action Wasn't Cancelled
else
// Do Something If Action Was Cancelled
});
【问题讨论】:
-
Progress是什么?你不能只使用/编写自己的类吗? -
Progress 属于第 3 方脚本,它最后执行的函数调用在游戏中的多核函数中非常常见,这是我正在尝试学习如何调用的部分。不完全确定如何从第一次调用中声明回调函数
-
试试
(cancelled) => { /* your code goes there */ }而不是function(canceled { })。这称为lambda expression -
您在编辑中编写它的第二种方式应该可以工作。但是,不要编辑您的问题并添加您的解决方案,您可以对其进行测试,然后,如果它按预期工作,请将其作为答案发布