You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Various events are invoked throughout the tween lifecycle. A [TweenCallback](/api/Zigurous.Tweening/TweenCallback) function delegate can be used to respond to the following events:
8
+
9
+
-[onUpdate](/api/Zigurous.Tweening/Tween/onUpdate): Invoked every time the tween is updated
10
+
-[onStart](/api/Zigurous.Tweening/Tween/onStart): Invoked when the tween is started
11
+
-[onStop](/api/Zigurous.Tweening/Tween/onStop): Invoked when the tween is stopped
12
+
-[onLoop](/api/Zigurous.Tweening/Tween/onLoop): Invoked when the tween is looped
13
+
-[onComplete](/api/Zigurous.Tweening/Tween/onComplete): Invoked when the tween is completed
14
+
-[onKill](/api/Zigurous.Tweening/Tween/onKill): Invoked when the tween is killed
15
+
16
+
<hr/>
17
+
18
+
## 🗣️ Assigning callbacks
19
+
20
+
Tween callbacks can be assigned with delegates or lambdas. They have no parameters or return types. You can also use [property chaining](/manual/property-chaining) to make it easier to set multiple callbacks.
21
+
22
+
```csharp
23
+
// assigning callbacks with functions
24
+
tween.onUpdate+=OnTweenUpdated
25
+
tween.onStart+=OnTweenStarted;
26
+
tween.onStop+=OnTweenStopped;
27
+
tween.onLoop+=OnTweenLooped;
28
+
tween.onComplete+=OnTweenCompleted;
29
+
tween.onKill+=OnTweenKilled;
30
+
```
31
+
32
+
```csharp
33
+
// assigning callbacks with lambdas
34
+
tween.onUpdate+= () =>Debug.Log("Updated");
35
+
tween.onStart+= () =>Debug.Log("Started");
36
+
tween.onStop+= () =>Debug.Log("Stopped");
37
+
tween.onLoop+= () =>Debug.Log("Looped");
38
+
tween.onComplete+= () =>Debug.Log("Completed");
39
+
tween.onKill+= () =>Debug.Log("Killed");
40
+
```
41
+
42
+
```csharp
43
+
// assigning callbacks with property chaining
44
+
transform.TweenPosition(Vector3.zero, 1f)
45
+
.OnUpdate(OnTweenUpdated)
46
+
.OnStart(OnTweenStarted)
47
+
.OnStop(OnTweenStopped)
48
+
.OnLoop(OnTweenLooped)
49
+
.OnComplete(OnTweenCompleted)
50
+
.OnKill(OnTweenKilled);
51
+
```
52
+
53
+
## 🎫 Event Handler
54
+
55
+
One drawback of using delegates is that it produces GC allocations. If you are highly concerned about performance, you can use the [ITweenEventHandler](/api/Zigurous.Tweening/ITweenEventHandler) interface to avoid allocations.
Copy file name to clipboardExpand all lines: Documentation~/articles/managing-tweens.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,15 @@ Tweening.KillAll();
17
17
You can also get the current amount of tweens:
18
18
19
19
```csharp
20
-
intcount=Tweening.Count; // the number of tweens alive (not necessarily active)
21
-
intalive=Tweening.ActiveCount; // the number of tween active
20
+
intcount=Tweening.Count; // the number of alive tweens (not necessarily active)
21
+
intactiveCount=Tweening.ActiveCount; // the number of active tweens
22
22
```
23
23
24
24
<hr/>
25
25
26
26
## 🏷️ Tween Ids
27
27
28
-
You can also target specific tweens by id. Every tween has an `id` property which allows you to distinguish it from others. However, this is not required, nor is the id unique. The id is set automatically unless you create tweens manually using the generic approach.
28
+
You can also target specific tweens by id. Every tween has an `id` property which allows you to distinguish it from others. However, this is not required, nor is the id unique. The id is set automatically unless you create tweens manually using the generic approach. All ids are implement as `int` values.
29
29
30
30
```csharp
31
31
Tweening.Play(id);
@@ -35,6 +35,12 @@ Tweening.Complete(id);
35
35
Tweening.Kill(id);
36
36
```
37
37
38
+
To manually set the id of a tween:
39
+
40
+
```csharp
41
+
tween.id=id;
42
+
```
43
+
38
44
<hr/>
39
45
40
46
## 🎯 Target References
@@ -49,18 +55,18 @@ Tweening.Complete(transform);
49
55
Tweening.Kill(transform);
50
56
```
51
57
52
-
If you create tweens manually using the generic approach, you should indicate to the tween what its target game object or component is, which will set the id of the tween based on that object's hash code.
58
+
If you create tweens manually using the generic approach, you should indicate to the tween what game object or component it is referencing. This sets both the id (see above) and scene index (see below) of the tween.
53
59
54
60
```csharp
55
-
tween.SetTarget(gameObject);
56
-
tween.SetTarget(component);
61
+
tween.SetReference(gameObject);
62
+
tween.SetReference(component);
57
63
```
58
64
59
65
<hr/>
60
66
61
67
## 🎬 Scene Unloading
62
68
63
-
Tweens will be killed automatically when the scene they are apart of is unloaded which prevents errors. However, this only works automatically if the tween knows which target object it is animating (see above). You should only need to worry about this if you are creating tweens manually using the generic approach.
69
+
Tweens will be killed automatically when the scene they are apart of is unloaded which prevents errors accessing objects that have been destroyed. However, this only works automatically if the tween knows which target object it is animating (see above). You should only need to worry about this if you are creating tweens manually using the generic approach.
64
70
65
71
Make sure to kill your tweens before transitioning scenes, or set the target reference as outlined above. You can also manually set the scene index if desired.
Copy file name to clipboardExpand all lines: Documentation~/articles/tweens.md
+16-20Lines changed: 16 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,29 +18,25 @@ A tween is an animation of a value from a start position to an end position usin
18
18
Most of the time you will be creating tweens by using the shortcut extension methods available on most Unity objects. See the [Supported Types](/manual/supported-types) manual for the full list of classes that provide shortcut functions. Here are just a few examples:
19
19
20
20
```csharp
21
-
transform.TweenPosition(endValue, duration);
22
-
material.TweenColor(endValue, duration);
23
-
camera.TweenFieldOfView(endValue, duration);
24
-
light.TweenIntensity(endValue, duration);
21
+
transform.TweenPosition(Vector3.zero, duration);
22
+
material.TweenColor(Color.white, duration);
23
+
camera.TweenFieldOfView(90f, duration);
24
+
light.TweenIntensity(1f, duration);
25
25
```
26
26
<br/>
27
27
28
28
### Generic Approach
29
29
30
-
Although most of the time you will not be creating tweens with this approach, it is the basis of the entire tweening system so it is valuable to understand how it works. Essentially any value represented by a number can be tweened. The [Supported Types](/manual/supported-types) manual lists all of the specific types that can be tweened.
30
+
Although most of the time you will not be creating tweens with this approach, it is the basis of the entire tweening system so it is valuable to understand how it works. Essentially any value represented by a number can be tweened. The [Supported Types](/manual/supported-types) manual provides a list of all types that can be tweened.
@@ -69,10 +65,10 @@ All of these properties can be set with [property chaining](/manual/property-cha
69
65
70
66
## 🌪️ Controlling tweens
71
67
72
-
Often times you might want to manually control the state of the tween, even if it is just pausing and resuming a tween. There are several methods available to transition a tween to a different state. *Note*: not all states can be transitioned to depending on the current state. See [Managing Tweens](/manual/managing-tweens) for ways to control tweens globally.
68
+
Often times you might want to manually control the state of the tween, even if it is just pausing and resuming a tween. There are several methods available to transition a tween to a different state. *Note:* not all states can be transitioned to depending on the current state. See [Managing Tweens](/manual/managing-tweens) for ways to control tweens globally.
73
69
74
70
```csharp
75
-
tween.Play(); // starts or resumes the the tween
71
+
tween.Play(); // starts or resumes the tween
76
72
tween.Stop(); // pauses the tween if it is already playing
77
73
tween.Restart(); // restarts the tween from the beginning if not killed
78
74
tween.Complete(); // completes the tween, jumping to the end value
@@ -92,17 +88,17 @@ There are a number of properties available to read the current state of a tween.
92
88
-`Killed`: The tween is killed, making it no longer usable.
93
89
94
90
```csharp
95
-
TweenStatestate=tween.state; // the current animation state of the tween
91
+
TweenStatestate=tween.State; // the current animation state of the tween
96
92
97
93
boolplaying=tween.IsPlaying; // true if playing
98
94
boolstopped=tween.IsStopped; // true if stopped
99
95
boolcomplete=tween.IsComplete; // true if complete
100
96
boolkilled=tween.IsKilled; // true if killed
101
97
booldelayed=tween.IsDelayed; // true if delayed
102
98
103
-
floatelapsed=tween.elapsed; // the amount of seconds playing
99
+
floatelapsed=tween.Elapsed; // the amount of seconds playing
104
100
floatpercent=tween.PercentComplete; // the percentage of completion
105
-
floatdelayElapsed=tween.delayElapsed; // the amount of seconds delayed
101
+
floatdelayElapsed=tween.DelayElapsed; // the amount of seconds delayed
106
102
107
-
intiterations=tween.iterations; // the number of times completed
103
+
intiterations=tween.Iterations; // the number of times completed
0 commit comments