FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UnLua/Content/Script/Tutorials/04_DynamicBinding.lua at master · dsz0/UnLua · GitHub
This repository was archived by the owner on Aug 8, 2026. It is now read-only.
dsz0
/
UnLua
Public archive
forked from
Tencent/UnLua
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
UnLua
/
Content
/
Script
/
Tutorials
/
04_DynamicBinding.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (34 loc) · 1.45 KB
Breadcrumbs
UnLua
/
Content
/
Script
/
Tutorials
/
04_DynamicBinding.lua
Copy path
File metadata and controls
46 lines (34 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
--[[
说明:除了实现 UnLuaInterface 的静态绑定方式外,还可以在运行时动态绑定对象到Lua
对于 Actor 类,可以使用 SpawnActor 接口,例如:
World:SpawnActor(SpawnClass, Transform, AlwaysSpawn, self, self, "Tutorials.GravitySphereActor")
对于非 Actor 类,可以使用 NewObject 接口,例如:
NewObject(WidgetClass, self, nil, "Tutorials.IconWidget")
注意:无论哪种绑定方式,都需要指定脚本文件路径。它是一个相对于 {工程目录}/Content/Script 下的相对路径。
]]
--
require
"
UnLua
"
local
Screen
=
require
"
Tutorials.Screen
"
local
M
=
Class
()
function
M
:
ReceiveBeginPlay
()
local
msg
=
[[
鼠标左键:创建动态绑定的 Actor
鼠标右键:创建动态绑定的 Object
—— 本示例来自 "Content/Script/Tutorials.04_DynamicBinding.lua"
]]
Screen
.
Print
(
msg
)
end
function
M
:
LeftMouseButton_Pressed
()
local
World
=
self
:
GetWorld
()
local
SpawnClass
=
self
.
SpawnClass
local
Transform
=
self
.
SpawnPointActor
:
GetTransform
()
local
AlwaysSpawn
=
UE
.
ESpawnActorCollisionHandlingMethod
.
AlwaysSpawn
World
:
SpawnActor
(
SpawnClass
,
Transform
,
AlwaysSpawn
,
self
,
self
,
"
Tutorials.GravitySphereActor
"
)
end
function
M
:
RightMouseButton_Pressed
()
local
WidgetClass
=
self
.
WidgetClass
local
img
=
NewObject
(
WidgetClass
,
self
,
nil
,
"
Tutorials.IconWidget
"
)
img
:
AddToViewport
()
img
:
RandomPosition
()
end
return
M
Back
|
FazBrowse Home
|
New Git URL