Skip to content

Commit 2c1633d

Browse files
committed
Update documentation
1 parent b7f4469 commit 2c1633d

File tree

8 files changed

+142
-68
lines changed

8 files changed

+142
-68
lines changed

Documentation~/articles/callbacks.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

Documentation~/articles/events.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
slug: "/manual/events"
3+
---
4+
5+
# Events
6+
7+
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.
56+
57+
```csharp
58+
public class Example : MonoBehaviour, ITweenEventHandler
59+
{
60+
private void Start()
61+
{
62+
transform.TweenPosition(Vector3.zero, 1f)
63+
.SetEventHandler(this);
64+
}
65+
66+
public void OnTweenUpdate(Tween tween)
67+
{
68+
Debug.Log("Updated");
69+
}
70+
71+
public void OnTweenStart(Tween tween)
72+
{
73+
Debug.Log("Started");
74+
}
75+
76+
public void OnTweenStop(Tween tween)
77+
{
78+
Debug.Log("Stopped");
79+
}
80+
81+
public void OnTweenLoop(Tween tween)
82+
{
83+
Debug.Log("Looped");
84+
}
85+
86+
public void OnTweenComplete(Tween tween)
87+
{
88+
Debug.Log("Completed");
89+
}
90+
91+
public void OnTweenKill(Tween tween)
92+
{
93+
Debug.Log("Killed");
94+
}
95+
}

Documentation~/articles/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The system is lightweight, optimized, type-safe, and memory efficient. Hundreds
3030

3131
#### 〽️ [Easing](/manual/easing)
3232

33-
#### 🗣️ [Callbacks](/manual/callbacks)
33+
#### 🎫 [Events](/manual/events)
3434

3535
#### ⛓️ [Property Chaining](/manual/property-chaining)
3636

Documentation~/articles/managing-tweens.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Tweening.KillAll();
1717
You can also get the current amount of tweens:
1818

1919
```csharp
20-
int count = Tweening.Count; // the number of tweens alive (not necessarily active)
21-
int alive = Tweening.ActiveCount; // the number of tween active
20+
int count = Tweening.Count; // the number of alive tweens (not necessarily active)
21+
int activeCount = Tweening.ActiveCount; // the number of active tweens
2222
```
2323

2424
<hr/>
2525

2626
## 🏷️ Tween Ids
2727

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.
2929

3030
```csharp
3131
Tweening.Play(id);
@@ -35,6 +35,12 @@ Tweening.Complete(id);
3535
Tweening.Kill(id);
3636
```
3737

38+
To manually set the id of a tween:
39+
40+
```csharp
41+
tween.id = id;
42+
```
43+
3844
<hr/>
3945

4046
## 🎯 Target References
@@ -49,18 +55,18 @@ Tweening.Complete(transform);
4955
Tweening.Kill(transform);
5056
```
5157

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.
5359

5460
```csharp
55-
tween.SetTarget(gameObject);
56-
tween.SetTarget(component);
61+
tween.SetReference(gameObject);
62+
tween.SetReference(component);
5763
```
5864

5965
<hr/>
6066

6167
## 🎬 Scene Unloading
6268

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.
6470

6571
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.
6672

Documentation~/articles/property-chaining.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ Property/method chaining is a technique that allows multiple properties to be as
88

99
<hr/>
1010

11-
## ⛓️ Example
11+
## ⛓️ Examples
1212

1313
```csharp
14+
// using a tween shortcut
1415
transform.TweenPosition(Vector3.zero, 1f)
1516
.SetDelay(3f)
16-
.SetReversed(true)
17+
.SetReversed()
1718
.SetEase(Ease.CubicInOut)
1819
.SetLoops(-1, LoopType.PingPong)
1920
.OnLoop(() => Debug.Log("looped!"));
2021
```
22+
23+
```csharp
24+
// building from scratch
25+
Tween tween = new Tweener<Transform, Vector3>(transform)
26+
.SetGetter((target) => target.position)
27+
.SetSetter((target, value) => target.position = value)
28+
.SetEndValue(Vector3.zero)
29+
.SetDuration(1f)
30+
.SetEase(Ease.QuadOut)
31+
.OnComplete(() => Debug.Log("complete!"));
32+
```

Documentation~/articles/supported-types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ All of the following types offer shortcut functions for creating tweens:
7676
- `LineRenderer`
7777
- `LookAtConstraint`
7878
- `Material`
79+
- `MaterialPropertyBlock`
7980
- `NavMeshAgent`
8081
- `NavMeshObstacle`
8182
- `OcclusionArea`

Documentation~/articles/tweens.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,25 @@ A tween is an animation of a value from a start position to an end position usin
1818
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:
1919

2020
```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);
2525
```
2626
<br/>
2727

2828
### Generic Approach
2929

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.
3131

3232
```csharp
33-
float currentValue, endValue, duration;
34-
3533
// Setup delegates to get and set a value
36-
TweenGetter<float> getter = () => { return currentValue; };
37-
TweenSetter<float> setter = newValue => { currentValue = newValue; };
38-
39-
// Create a tween that animates to the end value from the current value
40-
Tweening.To<float>(getter, setter, endValue, duration);
34+
TweenGetter<Transform, Vector3> getter = (target) => target.position;
35+
TweenSetter<Transform, Vector3> setter = (target, value) => target.position = value;
4136

42-
// Create a tween that animates from the end value to the current value
43-
Tweening.From<float>(getter, setter, endValue, duration);
37+
// Create a tween that animates to the end value over a duration
38+
Tweening.To(transform, getter, setter, Vector3.one, 1f);
39+
Tweening.From(transform, getter, setter, Vector3.one, 1f);
4440
```
4541

4642
<hr/>
@@ -69,10 +65,10 @@ All of these properties can be set with [property chaining](/manual/property-cha
6965

7066
## 🌪️ Controlling tweens
7167

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.
7369

7470
```csharp
75-
tween.Play(); // starts or resumes the the tween
71+
tween.Play(); // starts or resumes the tween
7672
tween.Stop(); // pauses the tween if it is already playing
7773
tween.Restart(); // restarts the tween from the beginning if not killed
7874
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.
9288
- `Killed`: The tween is killed, making it no longer usable.
9389

9490
```csharp
95-
TweenState state = tween.state; // the current animation state of the tween
91+
TweenState state = tween.State; // the current animation state of the tween
9692
9793
bool playing = tween.IsPlaying; // true if playing
9894
bool stopped = tween.IsStopped; // true if stopped
9995
bool complete = tween.IsComplete; // true if complete
10096
bool killed = tween.IsKilled; // true if killed
10197
bool delayed = tween.IsDelayed; // true if delayed
10298
103-
float elapsed = tween.elapsed; // the amount of seconds playing
99+
float elapsed = tween.Elapsed; // the amount of seconds playing
104100
float percent = tween.PercentComplete; // the percentage of completion
105-
float delayElapsed = tween.delayElapsed; // the amount of seconds delayed
101+
float delayElapsed = tween.DelayElapsed; // the amount of seconds delayed
106102
107-
int iterations = tween.iterations; // the number of times completed
103+
int iterations = tween.Iterations; // the number of times completed
108104
```

Documentation~/data/sidenav.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"path": "/manual/easing"
3737
},
3838
{
39-
"name": "Callbacks",
40-
"path": "/manual/callbacks"
39+
"name": "Events",
40+
"path": "/manual/events"
4141
},
4242
{
4343
"name": "Property Chaining",

0 commit comments

Comments
 (0)