-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathScaleInLocatedObject.ts
More file actions
55 lines (45 loc) · 1.4 KB
/
ScaleInLocatedObject.ts
File metadata and controls
55 lines (45 loc) · 1.4 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
49
50
51
52
53
54
55
import {LocatedObject} from "./LocatedObject"
/**
* Animates appearing and disappearing through scaling.
*/
@component
export class ScaleInLocatedObject extends BaseScriptComponent implements LocatedObject {
@input
@allowUndefined
@hint("Will be enabled the first time it is activated")
contentSceneObject: SceneObject
@input
private animationSpeed: number = 0.0
private targetScaleIn: number = 0.0
onAwake() {
const t = this.contentSceneObject.getTransform()
this.targetScaleIn = t.getLocalScale().x
t.setLocalScale(new vec3(0, 0, 0))
this.createEvent("UpdateEvent").bind(() => {
if (this.animationSpeed !== 0.0) {
const t = this.contentSceneObject.getTransform()
let currScale = t.getLocalScale().x + this.animationSpeed
if (currScale < 0) {
currScale = 0
this.animationSpeed = 0
} else if (currScale > this.targetScaleIn) {
currScale = this.targetScaleIn
this.animationSpeed = 0
}
t.setLocalScale(new vec3(currScale, currScale, currScale))
}
})
}
public activate(): void {
if (this.contentSceneObject) {
if (!this.contentSceneObject.enabled) {
this.contentSceneObject.enabled = true
}
}
this.animationSpeed = this.targetScaleIn * 0.05
}
public deactivate(): void {
this.animationSpeed = this.targetScaleIn * -0.05
}
public localize() {}
}