跳转到内容

模组的使用

模组的使用

  • 创建模组:想要多次复用的元件组合可以保存为模组,首先把元件组合为编组,然后点击编辑,在右侧栏可以看到保存到我的资源

image1image2

跟着引导保存完模组后,就可以在 资源-我的 中看见刚才保存的模组了。

目前编程元件暂时不支持直接创建模组【资源】。
如果需要创建模组,请先将模组拖到场景中成为实例,然后即可操作这些实例。

local group_element=277 --模组的实例ID
--也可以通过实例ID,复制模组
local pos, rot, scale = Engine.Vector(0,0,200), Engine.Rotator(0,0,0), Engine.Vector(1,1,1)
--创建完成后触发的回调函数
local callBack = function(elementId)
--新的元件ID复制给group_element_copy
group_element_copy = elementId
end
--通过场景中的实例ID复制元件,SpawnSource选择Scene
Element:SpawnElement(Element.SPAWN_SOURCE.Scene, group_element, callBack, pos, rot, scale)
local function GroupTransform()
TimerManager:AddLoopTimer(
0.03,
--持续变化
function()
--也可以使用group_element_copy
local _pos=Element:GetPosition(group_element) --获取模组的变换
local _rot=Element:GetRotation(group_element)
local _scale=Element:GetScale(group_element)
_pos=_pos+Engine.Vector(10,0,1) --变换递增
_rot=_rot+Engine.Rotator(0,10,0)
_scale=_scale+Engine.Vector(0.01,0.01,0.01)
Element:SetPosition(group_element,_pos,Element.COORDINATE.World) --应用变换
Element:SetRotation(group_element,_rot,Element.COORDINATE.World)
Element:SetScale(group_element,_scale)
end)
end
  • 创建元件预设:依次点击 魔方-元件预设 ,可以进入元件预设编辑界面,编辑完元件后,点击存为自定义 ,即可保存元件预设。

image3image4image5image6

自定义中可以看到保存的元件预设,在实例信息中,可以看到元件预设ID。

元件预设ID使用时需要转换为string类型,多场景与非多场景的的元件预设ID格式上会不同,不影响使用。

--从实例信息中获取
local prefabID=5126663763122828917580142197
prefabID=tostring(prefabID) --转换为string类型
local pos, rot, scale = Engine.Vector(0,0,200), Engine.Rotator(0,0,0), Engine.Vector(1,1,1)
--创建完成后触发的回调函数
local callBack = function(elementId)
print(elementId)
end
--创建元件预设,SpawnSource选择Prefab
Element:SpawnElement(Element.SPAWN_SOURCE.Prefab, prefabID, callBack, pos, rot, scale)