Skip to content

Commit

Permalink
docs: 增加很多工具
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamster5295 committed Jan 16, 2025
1 parent 946b4cd commit 48e0698
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 2-func/1-archive.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`Archive` 提供一个便捷的、基于字典的存档系统,使用相当简便的代码即可实现读写操作。


## 快速上手
## 快速使用

以下示例演示了如何使用 `Archive` 进行读写操作:

Expand Down
2 changes: 1 addition & 1 deletion 2-func/2-fsm.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`FSM` 提供一套简单快速的状态机系统,可以更方便地实现主角控制、敌人 AI、游戏状态管理等功能,减少重复劳动。


## 快速上手
## 快速使用

以下示例演示了一个双状态的状态机,实现主角的走路和跑步两种状态。

Expand Down
2 changes: 1 addition & 1 deletion 2-func/4-tween.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:::


## 快速上手
## 快速使用

以下示例演示了如何使用 `Tween` 实现淡出效果:

Expand Down
2 changes: 1 addition & 1 deletion 3-struct/1-int-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`IntRange` 表示一个整数范围。它可以方便地在 `Inspector` 中编辑,并用代码进行操作。


## 快速入门
## 快速使用

以下示例演示了 `IntRange` 的使用方法:

Expand Down
2 changes: 1 addition & 1 deletion 3-struct/2-float-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`FloatRange` 表示一个浮点数范围。它可以方便地在 `Inspector` 中编辑,并用代码进行操作。


## 快速入门
## 快速使用

以下示例演示了 `FloatRange` 的使用方法:

Expand Down
2 changes: 1 addition & 1 deletion 3-struct/3-rectangle.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`Rectangle` 提供了在**场景**中选定矩形范围,并用代码进行交互的功能。


## 快速入门
## 快速使用

下方示例演示了 `Rectangle` 的基本使用方法:

Expand Down
2 changes: 1 addition & 1 deletion 3-struct/4-float-curve.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
这有点类似于 `ParticleSystem` 中,可以调整模式的数值。


## 快速上手
## 快速使用

下方示例演示了 `FloatCurve` 的典型使用方法:

Expand Down
2 changes: 1 addition & 1 deletion 4-code/1-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:::


## 快速上手
## 快速使用

以下例子演示了如何使用 `Flow` 进行简单的流程控制。

Expand Down
2 changes: 1 addition & 1 deletion 4-code/2-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

`CSV` 用于处理 `.csv` 格式的表格文件。目前支持将特定格式的表格解析为 C# 对象。

## 快速上手
## 快速使用

以下例子演示了将 `.csv` 文件中的数值解析为自定义的 `Person` 对象的过程。

Expand Down
2 changes: 1 addition & 1 deletion 4-code/3-flex-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
在制作一些**经常被打断的动画**,如 UI 的动效时非常好用。


## 快速上手
## 快速使用

以下示例演示了如何使用 `FlexValue` 来实现一个简单的 UI 缩放功能:

Expand Down
2 changes: 1 addition & 1 deletion 4-code/4-audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`AudioUtils` 提供了一些与音量控制有关的工具方法。


## 快速上手
## 快速使用
```C#
// 百分比转分贝
var db = AudioUtils.ValueToDb(0.5);
Expand Down
2 changes: 1 addition & 1 deletion 4-code/5-color.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`ColorUtils` 提供了一些与颜色有关的工具方法。

## 快速上手
## 快速使用

```C#
// 将 #rrggbbaa, #rrggbb, #rgb, #rgba 格式的字符串转为 Color
Expand Down
34 changes: 34 additions & 0 deletions 4-code/6-vector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# `VectorUtils` - 向量工具

`Bingyan DevKit` 围绕向量提供了一组相当方便的工具。

## 快速使用

```C#
Vector2 vec2 = new Vector2(1, 0);
transform.position += vec2.Vec3(); // 等效于 (Vector3)movement,但写起来更方便
vec2 = transform.position.Vec2(); // 等效于 (Vector2)transform.position
// 获得一个向量仅改变一个分量后的值
vec2 = vec2.SetX(1);
vec2 = vec2.SetY(1);

// Vector3 也有类似的方法,此处不再列举
// 翻转 x 或 y
vec2 = vec2.FlipX();
vec2 = vec2.FlipY();

// 快捷运算
vec2 = vec2.SetLength(1); // 方向不变,长度设为 1
vec2 = vec2.LimitLength(1); // 方向不变,长度限制到 1
vec2 = vec2.Rotate(45); // 顺时针顺时针旋转 45 度
vec2 = vec2.Dot(Vector2.up); // 点积
var vec3 = Vector3.up.Cross(Vector3.left); // 叉积
// 工具方法
vec2 = VectorUtils.MinLength(vec2, Vector2.one); // 获得长度较小的向量
vec2 = VectorUtils.MaxLength(vec2, Vector2.one); // 获得长度较大的向量
```
26 changes: 26 additions & 0 deletions 4-code/7-comp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# `Component` - 组件工具

`Bingyan DevKit` 提供了一套利用层级关系获取组件的工具。


## 快速使用

```C#
// 在 MonoBehaviour 中
// 按照 Hierarchy 中的路径获取组件
// 下方的代码将获取到当前物体的 Path 子物体 -> To 子物体 -> Collider 子物体上的 Collider2D 组件
var comp = this.GetComp<Collider2D>("Path/To/Collider");

// 尝试获得组件,如果不存在则返回 false 并 out null
var hasComp = this.TryGetComp<Collider2D>("Path/To/Collider", out comp);

// GetComponentInChildren 的 Try 版本
hasComp = this.TryGetComponentInChildren<Collider2D>(out comp);

// GetComponentInParent 的 Try 版本
hasComp = this.TryGetComponentInParent<Collider2D>(out comp);

// 直接获取位置,等效于 (Vector2) comp.transform.position
var pos = comp.Pos2D();
```
20 changes: 20 additions & 0 deletions 4-code/8-enumerate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `IEnumerate` - 迭代器工具

`Bingyan DevKit` 提供了一套更方便地遍历迭代器的工具。


## 快速使用

```C#
// 有下标的 List
var list = new List<string>() { "Hello", "World" };

// 无下标的 HashSet
var set = new HashSet<string>() { "Hello", "World" };

// ForEach, 但现在非 List 的迭代器也能用了
set.ForEach(s => Debug.Log(s));

// 对于有下标的迭代器,可以带下标进行遍历了
list.ForEachIndex((index, s) => Debug.Log($"{index}: {s}"));
```
21 changes: 21 additions & 0 deletions 4-code/9-rand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# `RandomUtils` - 随机工具

`RandomUtils` 提供了一些常用的取随机工具。


## 快速使用

```C#
var array = new string[] { "Hello", "World", "!" };

// 随机取一个元素
var item = RandomUtils.Choose(array);

// 对于 List<T>, 可以使用 GetRand() 拓展方法
var list = new List<string>() { "Hello", "World", "!" };
item = list.GetRand();

// 还可以获取随机元素的下标
item = list.GetRand(out var idx);

```

0 comments on commit 48e0698

Please sign in to comment.