Skip to content

Commit 6637a7c

Browse files
committed
new tutorial
1 parent 2c9cf50 commit 6637a7c

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

Examples/Content/Scripts/helloJS.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
(function (global) {
2+
"use strict"
3+
4+
const UMG = require('UMG')
5+
const _ = require('lodash')
6+
const uclass = require('uclass')().bind(this,global)
7+
8+
function tutorial_StaticMeshActor() {
9+
console.log('creating a static mesh actor')
10+
class MySMA extends StaticMeshActor {
11+
ctor() {
12+
let smc = this.StaticMeshComponent
13+
let mtrl = GWorld.CreateDynamicMaterialInstance(Material.Load('/Game/Color.Color'))
14+
mtrl.SetVectorParameterValue('Color',{G:1,A:1})
15+
smc.SetStaticMesh(StaticMesh.Load('/Engine/BasicShapes/Cube.Cube'))
16+
smc.SetMaterial(0,mtrl)
17+
}
18+
}
19+
let actor = new (uclass(MySMA))(GWorld,{Z:100})
20+
return _ => {
21+
actor.DestroyActor()
22+
}
23+
}
24+
25+
let tutorials = {
26+
'Static mesh actor' : tutorial_StaticMeshActor
27+
}
28+
29+
function Logger() {
30+
let log
31+
class MyOutput extends JavascriptOutputDevice {
32+
OnMessage(msg,verbosity,category) {
33+
log && log([category,msg].join(':'))
34+
}
35+
}
36+
let outputDevice = new (uclass(MyOutput))
37+
38+
function LogWindow() {
39+
return UMG.div({$link:elem => {
40+
function add(msg) {
41+
let child = elem.add_child(UMG.text({Font:{Size:18}},msg))
42+
setTimeout(_ => elem.remove_child(child),5000)
43+
}
44+
45+
log = add
46+
}})
47+
}
48+
49+
return {
50+
destroy : _ => outputDevice.Kill(),
51+
window : LogWindow
52+
}
53+
}
54+
55+
function app() {
56+
let logger = Logger()
57+
58+
let cur
59+
return UMG.div({$link:elem => {
60+
elem.bye = _ => {
61+
console.log('done')
62+
cur && cur()
63+
logger.destroy()
64+
}
65+
}},
66+
_.map(tutorials,(v,k) =>
67+
UMG(Button,{OnClicked:_ => {
68+
cur && cur()
69+
cur = v()
70+
}},UMG.text({},k)
71+
)),
72+
UMG(Border,{
73+
'Slot.Size.Rule':'Fill',
74+
'Slot.VerticalAlignment':'VAlign_Bottom',
75+
'BrushColor':{A:0.5}
76+
},
77+
logger.window()
78+
)
79+
)
80+
}
81+
82+
function main() {
83+
let PC = GWorld.GetPlayerController()
84+
85+
class AppWidget extends JavascriptWidget {
86+
ctor() {
87+
this.bSupportsKeyboardFocus = true
88+
}
89+
}
90+
91+
// create a widget
92+
let widget = GWorld.CreateWidget(uclass(AppWidget), PC)
93+
let page = (require('instantiator'))(app())
94+
95+
widget.SetRootWidget(page)
96+
widget.AddToViewport()
97+
98+
return function () {
99+
page.bye()
100+
widget.RemoveFromViewport()
101+
}
102+
}
103+
104+
try {
105+
module.exports = () => {
106+
let cleanup = null
107+
process.nextTick(() => cleanup = main());
108+
return () => cleanup()
109+
}
110+
}
111+
catch (e) {
112+
require('bootstrap')('helloJS')
113+
}
114+
})(this)

Examples/Content/helloJS.umap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:09a9a3126b3c5a0fa8138977148bb95ffe596e4a8b371d8e23a8355674a4a626
3+
size 628591

0 commit comments

Comments
 (0)