Mod
Mod 类负责与本地 Mod 对象交互。
继承关系
方法
SetSharedVariable(string VariableName, any Value)
- 设置一个可供任何 Mod 访问的变量。
- 第二个参数
Value仅支持以下类型:nil、string、number、bool、UObject(及其派生类型)、lightuserdata。
警告: 热重载时不会重置这些变量。
示例
-- When sharing a UObject, make absolutely sure that it's a UObject that doesn't cease to exist before it's used again.
-- It's a very bad idea to share transient objects like actors as they might die and stop existing.
local StaticObject = StaticFindObject("/Script/Engine.Default__GameplayStatics")
-- The 'ModRef' variable is a global variable that's automatically created and is the instance of the current mod.
ModRef:SetSharedVariable("MyVariable", StaticObject)
GetSharedVariable(string VariableName)
- 返回类型:
any - 返回值: 可能由另一个 Mod 设置的变量。
- 返回值仅支持以下类型:
nil、string、number、bool、UObject(及其派生类型)、lightuserdata。
示例
-- Assuming that the example script for 'SetSharedVariable' has been executed.
local SharedObject = ModRef:GetSharedVariable("MyVariable")
-- 'GetSharedVariable' may return anything that its able to store.
-- Any mod is able to override the value for any shared variable.
if SharedObject and type(SharedObject) == "userdata" and SharedObject:type() == "UObject" and SharedObject:IsValid() then
print(string.format("SharedObject '%s' is valid.\n", SharedObject:GetFullName()))
else
print("SharedObject was nil, not userdata, not a UObject, or an invalid UObject")
end
OnUnload(function Callback)
- 在此 Mod 卸载前立即调用回调。
- 调用回调前始终会等待异步操作完成。
- 此函数默认不存在,必须由 Mod 提供,参见示例。
示例
ModRef.OnUnload = function()
print("Mod is unloading.\n")
end
type()
- 返回类型:
string - 返回值:
"ModRef"
原文:docs/lua-api/classes/mod.md · 固定提交 560411f18512 · 来源与 MIT 许可