59 lines
1.8 KiB
Lua
59 lines
1.8 KiB
Lua
local Ex04_DynamicBinding = UnLua.Class()
|
|||
|
|
function Ex04_DynamicBinding.SpawnDynamicActor(self, tag, power)
|
||
|
|
local world = self:GetWorld()
|
||
|
|
local actorClass = UE.UClass.Load("/Game/Blueprints/BP_DynamicDemo.BP_DynamicDemo_C")
|
||
|
|
if not world or not actorClass then
|
||
|
|
return nil
|
||
|
|
end
|
||
|
|
local transform = UE.FTransform(
|
||
|
|
UE.FRotator(0, 90, 0):ToQuat(),
|
||
|
|
UE.FVector(100, 200, 300),
|
||
|
|
UE.FVector(1, 1, 1)
|
||
|
|
)
|
||
|
|
return world:SpawnActor(
|
||
|
|
actorClass,
|
||
|
|
transform,
|
||
|
|
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||
|
|
self,
|
||
|
|
nil,
|
||
|
|
"Tests.UnLuaExamples.Ex04_DynamicSpawnedActor",
|
||
|
|
{InitTag = tag, InitPower = power}
|
||
|
|
)
|
||
|
|
end
|
||
|
|
function Ex04_DynamicBinding.SpawnDynamicActorEx(self, tag)
|
||
|
|
local world = self:GetWorld()
|
||
|
|
local actorClass = UE.LoadClass("/Game/Blueprints/BP_DynamicDemoEx.BP_DynamicDemoEx_C")
|
||
|
|
if not world or not actorClass then
|
||
|
|
return nil
|
||
|
|
end
|
||
|
|
local params = UE.FActorSpawnParameters()
|
||
|
|
params.Name = "ExSpawnedActor"
|
||
|
|
params.bNoFail = true
|
||
|
|
params.Owner = self
|
||
|
|
params.SpawnCollisionHandlingOverride = UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn
|
||
|
|
return world:SpawnActorEx(
|
||
|
|
actorClass,
|
||
|
|
UE.FTransform(
|
||
|
|
UE.FRotator(0, 0, 0):ToQuat(),
|
||
|
|
UE.FVector(10, 20, 30),
|
||
|
|
UE.FVector(1, 1, 1)
|
||
|
|
),
|
||
|
|
{InitTag = tag, InitPower = 77},
|
||
|
|
"Tests.UnLuaExamples.Ex04_DynamicSpawnedActor",
|
||
|
|
params
|
||
|
|
)
|
||
|
|
end
|
||
|
|
function Ex04_DynamicBinding.CreateDynamicObject(self, seed)
|
||
|
|
local objClass = UE.UClass.Load("/Script/CoreUObject.Object")
|
||
|
|
if not objClass then
|
||
|
|
return nil
|
||
|
|
end
|
||
|
|
return UE.NewObject(
|
||
|
|
objClass,
|
||
|
|
self,
|
||
|
|
"DynamicObjectInstance",
|
||
|
|
"Tests.UnLuaExamples.Ex04_DynamicObject",
|
||
|
|
{Seed = seed}
|
||
|
|
)
|
||
|
|
end
|
||
|
|
return Ex04_DynamicBinding
|