Repository navigation
Expand file tree
/
Copy pathTag_BounceBehavior.tsx
More file actions
48 lines (43 loc) · 1.58 KB
/
Copy pathTag_BounceBehavior.tsx
File metadata and controls
48 lines (43 loc) · 1.58 KB
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
47
48
/*
This example behavior demonstrates tweening an IsHTML element. It is not required for IsHTML to function.
*/
namespace game {
export class Tag_BounceBehaviorFilter extends ut.EntityFilter {
tag: game.Tag_Bounce;
entity: ut.Entity;
rect: ut.UILayout.RectTransform;
is_html: game.IsHTML;
}
export class Tag_BounceBehavior extends ut.ComponentBehaviour {
data: Tag_BounceBehaviorFilter;
// ComponentBehaviour lifecycle events
// uncomment any method you need
// this method is called for each entity matching the Tag_BounceBehaviorFilter signature, once when enabled
OnEntityEnable(): void {
ut.Tweens.TweenService.addTween(
this.world,
this.data.entity,
ut.UILayout.RectTransform.anchoredPosition.y,
this.data.rect.anchoredPosition.y,
this.data.rect.anchoredPosition.y + 200,
4,
0,
ut.Core2D.LoopMode.PingPong,
ut.Tweens.TweenFunc.InOutBounce,
false
);
}
// this method is called for each entity matching the Tag_BounceBehaviorFilter signature, every frame it's enabled
OnEntityUpdate(): void {
const pos = Math.floor(this.data.rect.anchoredPosition.y);
const color = pos > 100 ? "blue" : "red";
const text = pos > 100 ? "white" : "black";
IsHTMLService.SetHTML(
this.data.is_html,
<div style={`background-color: ${color}; color: ${text}`}>Y: {pos}</div>
);
}
// this method is called for each entity matching the Tag_BounceBehaviorFilter signature, once when disabled
//OnEntityDisable():void { }
}
}