Skip to content

Commit 115f1a9

Browse files
committed
docs: update docs
1 parent 759b6ef commit 115f1a9

File tree

3 files changed

+193
-91
lines changed

3 files changed

+193
-91
lines changed

README.md

+29-31
Original file line numberDiff line numberDiff line change
@@ -42,44 +42,42 @@ Milease supports animation operations for most types such as `Vector3`, `Vector2
4242
For example, use Milease to fade out music:
4343

4444
```c#
45-
AudioSource.MileaseTo(nameof(AudioSource.volume), 0f, 1f, 0f, EaseFunction.Quad, EaseType.Out).Play();
45+
AudioSource.QuadOut(x => x.volume, 1f / 0f.ToThis()).Play();
4646
```
4747

4848
# Create Animations by Organized Code
4949

5050
By using the methods `Milease`, `While`, `Then`, `Delayed`, easily generate complex animations with readable code through nesting:
5151

5252
```c#
53-
var animation =
54-
transform.Milease(UMN.Position,
55-
new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f),
56-
1f)
57-
.While(
58-
GetComponent<SpriteRenderer>().Milease(UMN.Color,
59-
new Color(1f, 1f, 1f, 1f), new Color(1f, 0f, 0f, 1f),
60-
1f, 0.5f)
61-
)
62-
.Then(
63-
transform.Milease(UMN.LScale,
64-
new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f),
65-
1f, 0f, EaseFunction.Bounce)
66-
).Delayed(1f)
67-
.Then(
68-
Text.Milease(nameof(Text.text), "Start!", "Finish!", 1f)
69-
)
70-
.Then(
71-
Text.Milease((e) =>
72-
{
73-
var text = e.GetTarget<TMP_Text>();
74-
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
75-
}, null, 2f, 0f, EaseFunction.Linear)
76-
)
77-
.Then(
78-
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
79-
)
80-
.Then(
81-
transform.MileaseTo(UMN.Position, new Vector3(0f, 0f, 0f), 1f)
82-
);
53+
var spriteRenderer = GetComponent<SpriteRenderer>();
54+
55+
Animation =
56+
MilInstantAnimator.Start(
57+
1f / transform.Milease(x => x.position,new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f))
58+
)
59+
.While(
60+
0.5f + 1f / spriteRenderer.Milease(x => x.color, Color.white, Color.red)
61+
)
62+
.Then(
63+
1f / transform.MBounce(x => transform.localScale, new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f))
64+
).Delayed(1f)
65+
.Then(
66+
1f / Text.MLinear(x => x.text, "Start!", "Finish!")
67+
)
68+
.Then(
69+
Text.Milease((e) =>
70+
{
71+
var text = e.GetTarget<TMP_Text>();
72+
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
73+
}, null,2f, 0f, EaseFunction.Linear)
74+
)
75+
.Then(
76+
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
77+
)
78+
.Then(
79+
1f / transform.Milease(x => x.position, Vector3.zero.ToThis())
80+
);
8381
```
8482

8583
# Lightweight Design

~Document/1. Instant Animator.md

+82-30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,60 @@ Milease provides a series of extension functions for the `object` type, includin
44

55
## Creating an Instant Animator
66

7+
### Method 1: Using DSL for Generation (Recommended)
8+
9+
Compared to traditional generation methods, we’ve observed that developers often need to specify an easing function. However, the easing function is located further down in the optional parameters list, making it less convenient for developers to clearly observe the start value, end value, animation duration, and start time—especially in editors without `Inlay Hints` support.
10+
11+
We use `T4 templates` to generate a series of animation extension functions for `object`, which follow the pattern:
12+
13+
```c#
14+
MilInstantAnimator object.M[EasingFunctionName][EasingBranchName]<T, E>(Expression<Func<T, E>> mbExpr, AniExpression<E> aniExpr);
15+
```
16+
17+
or
18+
19+
```c#
20+
MilInstantAnimator object.M[EasingFunctionName][EasingBranchName]<T, E>(Expression<Func<T, E>> mbExpr, E from, E to);
21+
```
22+
23+
For example, when you need to use `Quad` `Out` easing, the corresponding function is:
24+
25+
```c#
26+
MilInstantAnimator object.MQuadOut<T, E>(Expression<Func<T, E>> mbExpr, E from, E to);
27+
```
28+
29+
Additionally, we provide a series of operator overloads, allowing you to generate an animator/animator segment in this manner.
30+
31+
When you need to use it as a complete animator, we recommend the following syntax:
32+
33+
```c#
34+
// Both approaches are valid
35+
AudioSource.MQuadOut(x => x.volume, [StartTime] + [Duration] / [StartValue].To([EndValue])).Play();
36+
([StartTime] + [Duration] / AudioSource.MQuadOut(x => x.volume, [StartValue], [EndValue])).Play();
37+
```
38+
39+
When transitioning the volume from the current volume to a target volume (instead of starting from a specified volume), you can use the following syntax:
40+
41+
```c#
42+
// Both approaches are valid
43+
AudioSource.MQuadOut(x => x.volume, [StartTime] + [Duration] / [TargetValue].ToThis()).Play();
44+
([StartTime] + [Duration] / AudioSource.MQuadOut(x => x.volume, [TargetValue].ToThis())).Play();
45+
```
46+
47+
When you need to use it as part of an animator segment composition, we recommend the following syntax:
48+
49+
```c#
50+
[StartTime] + [Duration] / AudioSource.MQuadOut(x => x.volume, [StartValue], [EndValue])
51+
```
52+
53+
Or the following:
54+
55+
```c#
56+
[StartTime] + [Duration] / AudioSource.MQuadOut(x => x.volume, [TargetValue])
57+
```
58+
59+
### Method 2: Using the Traditional Generation Method
60+
761
```c#
862
MilInstantAnimator object.Milease(string memberName, object startValue, object toValue, float duration);
963
```
@@ -134,36 +188,34 @@ MilInstantAnimator Action.AsMileaseKeyEvent(float delay = 0);
134188
Define nested animations using functions like `animator.While` and `animator.Then`, for example:
135189

136190
```c#
137-
var animation =
138-
transform.Milease(UMN.Position,
139-
new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f),
140-
1f)
141-
.While(
142-
GetComponent<SpriteRenderer>().Milease(UMN.Color,
143-
new Color(1f, 1f, 1f, 1f), new Color(1f, 0f, 0f, 1f),
144-
1f, 0.5f)
145-
)
146-
.Then(
147-
transform.Milease(UMN.LScale,
148-
new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f),
149-
1f, 0f, EaseFunction.Bounce)
150-
).Delayed(1f)
151-
.Then(
152-
Text.Milease(nameof(Text.text), "Start!", "Finish!", 1f)
153-
)
154-
.Then(
155-
Text.Milease((e) =>
156-
{
157-
var text = e.GetTarget<TMP_Text>();
158-
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
159-
}, null, 2f, 0f, EaseFunction.Linear)
160-
)
161-
.Then(
162-
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
163-
)
164-
.Then(
165-
transform.MileaseTo(UMN.Position, new Vector3(0f, 0f, 0f), 1f)
166-
);
191+
var spriteRenderer = GetComponent<SpriteRenderer>();
192+
193+
Animation =
194+
MilInstantAnimator.Start(
195+
1f / transform.Milease(x => x.position,new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f))
196+
)
197+
.While(
198+
0.5f + 1f / spriteRenderer.Milease(x => x.color, Color.white, Color.red)
199+
)
200+
.Then(
201+
1f / transform.MBounce(x => transform.localScale, new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f))
202+
).Delayed(1f)
203+
.Then(
204+
1f / Text.MLinear(x => x.text, "Start!", "Finish!")
205+
)
206+
.Then(
207+
Text.Milease((e) =>
208+
{
209+
var text = e.GetTarget<TMP_Text>();
210+
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
211+
}, null,2f, 0f, EaseFunction.Linear)
212+
)
213+
.Then(
214+
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
215+
)
216+
.Then(
217+
1f / transform.Milease(x => x.position, Vector3.zero.ToThis())
218+
);
167219
```
168220

169221
To play a specified animation concurrently with the previous one:

~Document/1. 即时动画机.md

+82-30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,60 @@ Milease 为`object`类型提供了一系列的拓展函数,包括`Milease`、`
44

55
## 生成即时动画机
66

7+
### 方式一:使用 DSL 生成(推荐)
8+
9+
相比传统的生成方式,我们注意到,开发者更多时候需要指定缓动函数,而缓动函数位于可选参数表有些靠后的位置,也不便于开发者观察开始值、终止值、动画长度和开始时间,特别是在没有 `Inlay Hints` 支持的编辑器上。
10+
11+
我们使用 `T4模板` 来生成针对 `object` 的一系列动画拓展函数,它遵循以下规律:
12+
13+
```c#
14+
MilInstantAnimator object.M[缓动函数名][缓动分支名]<T,E>(Expression<Func<T, E>> mbExpr, AniExpression<E> aniExpr);
15+
```
16+
17+
18+
19+
```c#
20+
MilInstantAnimator object.M[缓动函数名][缓动分支名]<T,E>(Expression<Func<T, E>> mbExpr, E from, E to);
21+
```
22+
23+
举个例子,当你需要使用 `Quad` `Out` 缓动时,相应的函数为:
24+
25+
```c#
26+
MilInstantAnimator object.MQuadOut<T,E>(Expression<Func<T, E>> mbExpr, E from, E to);
27+
```
28+
29+
同时,我们对其做了一系列运算符重载,你可以通过这个方式生成一个动画机/动画机片段。
30+
31+
当你需要将其作为一整个动画机直接使用时,我们推荐以下写法:
32+
33+
```c#
34+
// 两种方式均可
35+
AudioSource.MQuadOut(x => x.volume, [开始时间] + [动画时长] / [开始值].To([终止值])).Play();
36+
([开始时间] + [动画时长] / AudioSource.MQuadOut(x => x.volume, [开始值], [终止值])).Play();
37+
```
38+
39+
当你需要将音量从当前音量过渡到目标音量,而不是从一个指定的音量开始时,你可以使用以下写法:
40+
41+
```c#
42+
// 两种方式均可
43+
AudioSource.MQuadOut(x => x.volume, [开始时间] + [动画时长] / [目标音量].ToThis()).Play();
44+
([开始时间] + [动画时长] / AudioSource.MQuadOut(x => x.volume, [目标音量].ToThis())).Play();
45+
```
46+
47+
当你需要将其作为动画机片段组合时,我们推荐以下写法:
48+
49+
```c#
50+
[开始时间] + [动画时长] / AudioSource.MQuadOut(x => x.volume, [开始值], [终止值])
51+
```
52+
53+
或以下写法:
54+
55+
```c#
56+
[开始时间] + [动画时长] / AudioSource.MQuadOut(x => x.volume, [目标音量])
57+
```
58+
59+
### 方式二:使用传统方式生成
60+
761
```c#
862
MilInstantAnimator object.Milease(string memberName, object startValue, object toValue, float duration);
963
```
@@ -134,36 +188,34 @@ MilInstantAnimator Action.AsMileaseKeyEvent(float delay = 0);
134188
利用 `animator.While``animator.Then ` 等函数嵌套定义动画,例如:
135189

136190
```c#
137-
var animation =
138-
transform.Milease(UMN.Position,
139-
new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f),
140-
1f)
141-
.While(
142-
GetComponent<SpriteRenderer>().Milease(UMN.Color,
143-
new Color(1f, 1f, 1f, 1f), new Color(1f, 0f, 0f, 1f),
144-
1f, 0.5f)
145-
)
146-
.Then(
147-
transform.Milease(UMN.LScale,
148-
new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f),
149-
1f, 0f, EaseFunction.Bounce)
150-
).Delayed(1f)
151-
.Then(
152-
Text.Milease(nameof(Text.text), "Start!", "Finish!", 1f)
153-
)
154-
.Then(
155-
Text.Milease((e) =>
156-
{
157-
var text = e.GetTarget<TMP_Text>();
158-
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
159-
}, null, 2f, 0f, EaseFunction.Linear)
160-
)
161-
.Then(
162-
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
163-
)
164-
.Then(
165-
transform.MileaseTo(UMN.Position, new Vector3(0f, 0f, 0f), 1f)
166-
);
191+
var spriteRenderer = GetComponent<SpriteRenderer>();
192+
193+
Animation =
194+
MilInstantAnimator.Start(
195+
1f / transform.Milease(x => x.position,new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f))
196+
)
197+
.While(
198+
0.5f + 1f / spriteRenderer.Milease(x => x.color, Color.white, Color.red)
199+
)
200+
.Then(
201+
1f / transform.MBounce(x => transform.localScale, new Vector3(1f, 1f, 1f), new Vector3(2f, 2f, 2f))
202+
).Delayed(1f)
203+
.Then(
204+
1f / Text.MLinear(x => x.text, "Start!", "Finish!")
205+
)
206+
.Then(
207+
Text.Milease((e) =>
208+
{
209+
var text = e.GetTarget<TMP_Text>();
210+
text.text = $"Hide after {((1f - e.Progress) * 2f):F1}s...";
211+
}, null,2f, 0f, EaseFunction.Linear)
212+
)
213+
.Then(
214+
Text.gameObject.Milease(HandleFunction.Hide, HandleFunction.AutoActiveReset(Text.gameObject), 0f)
215+
)
216+
.Then(
217+
1f / transform.Milease(x => x.position, Vector3.zero.ToThis())
218+
);
167219
```
168220

169221
与上一个动画同时播放指定动画:

0 commit comments

Comments
 (0)