Skip to content

Commit

Permalink
Bug fix, provide ability to work with animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daylily-Zeleen committed Jan 23, 2023
1 parent 8b4fed8 commit 7726535
Show file tree
Hide file tree
Showing 28 changed files with 1,516 additions and 387 deletions.
Binary file added DOCUMENT.assets/animation_player_node_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DOCUMENT.assets/hfsm_inspector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DOCUMENT.assets/is_nested.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DOCUMENT.assets/state.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DOCUMENT.assets/state_animation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 122 additions & 12 deletions Document_cn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 分层有限状态机 - V 1.1
# 分层有限状态机 - V 1.2

​ 总所周知,状态机是一种很常见的设计模式,这里提供了一个强大易用、可视化编辑的分层有限状态机Godot插件。

Expand Down Expand Up @@ -235,6 +235,24 @@
1. 将该嵌套`FSM``Entry State``Exit State`设置为在编辑器中设置的`Entry State``Exit State`.
2. 复位该嵌套`FSM`中的所有`State`

6. 动画属性(v1.2 新增):

​ 当所属的HFSM设定了`动画播放器(animation_player)`属性时,每当进入该State时,将根据这些属性尝试播放相应动画。

![](DOCUMENT.assets/state_animation.png)
- 动画名称(Animation Name):
进入该State时要播放的动画名称。如果留空,将以状态名称`state_name`作为动画名称尝试进行播放。
(如果所属的HFSM没有指定动画播放器或该动画播放器不存在指定动画,将不进行动画播放操作)

- 动画混合时间(Animation Blend Time) (完整版特有):
播放动画时的混入时间。

- 动画速度(Animation Speed) (完整版特有):
动画的播放速度。

- 动画反向播放(Animation Play Backwards) (完整版特有):
是否方向播放动画。

### · 状态行为及其代码控制(State Behavior & Code Control)

​ 这是本插件所提供的`GDScript`状态脚本模板。
Expand Down Expand Up @@ -898,6 +916,10 @@ public class TemplateTransion :Reference
​ c. 强制保持(Force Persist) : 该模式下,所有`FSM`在进入时均不执行[FSM的复位](#-%E7%8A%B6%E6%80%81%E7%9B%91%E8%A7%86%E5%99%A8%E5%B1%9E%E6%80%A7state-inspector-properties)。
7. 动画播放器节点路径(animation_player_node_path)(V1.2 新特性):
![](DOCUMENT.assets/animation_player_node_path.png)
用于进入State时播放对应动画的动画播放器节点路径。
Expand Down Expand Up @@ -1040,8 +1062,16 @@ public class TemplateTransion :Reference
> "agent3":[Node:3],
> }
5. NodePath animation_player_node_path :
> v1.2 新特性
> 用于在编辑器指定动画播放器节点路径。
> 对该属性进行赋值或在`_ready()`被执行时,如果 `animation_player_node_path` 指向一个合法的 `AnimationPlayer` 节点,将获取对应的节点并赋值给 `animation_player`
6. AnimationPlayer animation_player:
> v1.2 新特性
> 运行时属性。每当 State 被进入时尝试播放动画所用的动画播放器节点。
### · 方法(Methods)
Expand Down Expand Up @@ -1274,35 +1304,46 @@ public class TemplateTransion :Reference
## 二 、 State(`GDScript`版本)
​ 不能在`HFSM`外部直接获取继承自这个类的对象,附加在`HFSM`中状态的脚本均继承自这个类。
> **`C#`用户注意:**
>
>`HFSM.State`的用法可以直接参考 `GDScript` 版本的`State`.
### · 属性(Properties)
`State`的所有属性均为只读属性,不可写入
1. String state_name[default : ""]
1. String state_name[default : ""] **只读**
> get_state_name() #getter
> State的名称,只能在设计`HFSM`时为`State`命名,不可通过代码写入
2. bool is_exited[default : false]
2. bool is_exited[default : false] **只读**
> is_exited() #getter
> 如果为真,该`State`未在运行,未进入,或已退出;如果为假,该`State`正在运行。不可写入
3. HFSM hfsm[default : null]
3. HFSM hfsm[default : null] **只读**
> get_hfsm() #getter
>`State`所处的`HFSM`对象,您可以通过他调用`HFSM`的成员,不可写入
4. String animation_name[default: ""]
> (v1.2 新特性)
> 进入该State时要播放的动画名称。如果留空,将以状态名称state_name作为动画名称尝试进行播放。 (如果所属的HFSM没有指定动画播放器或该动画播放器不存在指定动画,将不进行动画播放操作)
5. float animation_blend_time[default: 0.0]
> (v1.2 新特性 完整版特有)
> 播放动画时的混入时间。
6. float animation_speed[default: 1.0]
> (v1.2 新特性 完整版特有)
> 动画的播放速度。
7. bool animation_play_backwards[default: false]
> (v1.2 新特性 完整版特有)
> 是否反向播放动画。
### · 方法(Methods)
​ 对于可重载方法,其行为详见[状态行为及其代码控制](#-%E7%8A%B6%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%85%B6%E4%BB%A3%E7%A0%81%E6%8E%A7%E5%88%B6state-behavior--code-control)
​ 对于可重载方法,其行为详见[状态行为及其代码控制](#·状态行为及其代码控制(StateBehavior&CodeControl)).
1. void manual_exit()
Expand All @@ -1329,6 +1370,75 @@ public class TemplateTransion :Reference
> 可重载函数,退出该`State`时执行
## 三 、 State(`CSharpScript`版本)
​ 不能在`HFSM`外部直接获取继承自这个类的对象,附加在`HFSM`中状态的脚本均继承自这个类。
### · 属性(Properties)
`State`的所有属性均为只读属性,不可写入
1. string StateName[default : ""] **只读**
> State的名称,只能在设计`HFSM`时为`State`命名,不可通过代码写入
2. bool IsExited[default : false] **只读**
> 如果为真,该`State`未在运行,未进入,或已退出;如果为假,该`State`正在运行。不可写入
3. Node Hfsm[default : null] **只读**
>`State`所处的`HFSM`对象,您可以通过他调用`HFSM`的成员,不可写入
> **访问到的 HFSM 节点为GDScript对象,无法进行代码补全,请通过 `Set()`, `Get()`, `Call()` 等方式访问其成员。**
4. string AnimationName[default: ""]
> (v1.2 新特性)
> 进入该State时要播放的动画名称。如果留空,将以状态名称StateName作为动画名称尝试进行播放。 (如果所属的HFSM没有指定动画播放器或该动画播放器不存在指定动画,将不进行动画播放操作)
5. float AnimationBlendTime[default: 0.0f]
> (v1.2 新特性 完整版特有)
> 播放动画时的混入时间。
6. float AnimationSpeed[default: 1.0f]
> (v1.2 新特性 完整版特有)
> 动画的播放速度。
7. bool AnimationPlayBackwards[default: false]
> (v1.2 新特性 完整版特有)
> 是否反向播放动画。
### · 方法(Methods)
​ 对于可重载方法,其行为详见[状态行为及其代码控制](#·状态行为及其代码控制(StateBehavior&CodeControl)).
1. void ManualExit()
> 手动退出退出该`State`,并执行退出行为。
2. void Init() virtual
> 可重载函数,当`HFSM`生成时执行,在此方法执行后所有自定义属性的值将作为其初始值。
3. void Entry() virtual
> 可重载函数,当进入该`State`时执行.
4. void Update(float delta) virtual
> 可重载函数,该`State`更新时执行.
5. void PhysicsUpdate(float delta) virtual
> 可重载函数,该`State`物理更新时执行.
6. void Exit() virtual
> 可重载函数,退出该`State`时执行.
Expand Down
133 changes: 122 additions & 11 deletions Document_en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Hierarchical Finite State Machine - V 1.1
# Hierarchical Finite State Machine - V 1.2

​ As we all know, state machine is a very common design pattern. Here provide a powerful and easy-to-use Godot plugin for Hierarchical Finite State Machine with visual editing.

Expand Down Expand Up @@ -233,6 +233,23 @@
1. Set the Entry State and Exit States of the nested FSM to which perset in the editor.
2. Reset all States in the nested FSM when enter they.

6. Animation properties(v1.2 New Feature):

​ If the HFSM which contain this State, has been setting `animation_player`, it will try to play the animation as these properties descripted every time this State is entered.
![](DOCUMENT.assets/state_animation.png)
- Animation Name:
The animation whcih will be tried to play when this State be entered.
If remained it as a empty String, the `state_name` will be used as the `animation_name`.
If the `animaion_player` of HFSM is invalid or has not target animation, it will not be played.

- Animation Blend Time( full version only):
The time of target animation fade in.

- Animation Speed ( full version only):
The speed of play animation.

- Animation Play Backwards ( full version only):
To play animation backwards or not.
### State Behavior & Code Control

​ This is the **State script template( `GDScript` version)** provided by this plugin.
Expand Down Expand Up @@ -904,6 +921,11 @@ The difference between process types as follow :

​ c. Force Persist : In this mode, all FSM will not execute [reset behavior of FSM](#strate-inspector-properties) when is entered.

7. Animation Player Node Path (v1.2 New Feature):

![](DOCUMENT.assets/animation_player_node_path.png)
The AnimationPlayer NodePath, which point to the AnimationPlayer that used to play animation when State entery.

### The running of HFSM

1. When the game starts , after HFSM is added to the scene tree, all FSMs, States and Transitions will be instantiated and all States will be initialized.
Expand Down Expand Up @@ -1041,8 +1063,17 @@ The difference between process types as follow :
> "agent3":[Node:3],
> }

5. NodePath animation_player_node_path :

> v1.2 New feature.
> The AnimationPlayer NodePath, which point to the AnimationPlayer that used to play animation when State entery.
> In runtime, when set `animation_player_node_path` or `_ready()` executed, if `animation_player_node_path` point to a valid `AnimationPlayer` node, the `AnimationPlayer` node will be gotten and assign to this property.

6. AnimationPlayer animation_player:

> v1.2 New feature.
> Runtime property
> The AnimationPlay node that will be used to tried to play animation when state is entered.

### Methods

Expand Down Expand Up @@ -1271,33 +1302,46 @@ The difference between process types as follow :
## State(`GDScript` version)

​ Scripts attached to the State in HFSM inherit from this class, but you can not obtain the objects which inherited from this class directly outside HFSM.

> **For `C#` users:**
>
> ​ The usage of `HFSM.State` can refer to `GDScript` version's `State`.

### Properties

​ All State's properties are read only.

1. String state_name[default : ""]
1. String state_name[default : ""] **readyonly**

> get_state_name() #getter
> The name of State, you can not edit it in runtime. Read only.

2. bool is_exited[default : false]
2. bool is_exited[default : false] **readyonly**

> is_exited() #getter
>
> If true, this State is not running(not enter or already exited). Read only.

3. HFSM hfsm[default : null]
3. HFSM hfsm[default : null] **readyonly**

> get_hfsm() #getter
>
> The HFSM instance which contains this State. Ready only.

4. String animation_name[default: ""]

> (v1.2 New Feature)
> The animation whcih will be tried to play when this State be entered.
> If remained it as a empty String, the `state_name` will be used as the `animation_name`.
> If the `animaion_player` of HFSM is invalid or has not target animation, it will not be played.

5. float animation_blend_time[default: 0.0]

> (v1.2 New Feature, Full version only)
> The time of target animation fade in.

6. float animation_speed[default: 1.0]

> (v1.2 New Feature, Full version only)
> The speed of target animation playing.

7. bool animation_play_backwards[default: false]

> (v1.2 New Feature, Full version only)
> To play the animation backward or not.

### Methods

Expand Down Expand Up @@ -1329,6 +1373,73 @@ The difference between process types as follow :



## State(`CSharpScript` version)

​ Scripts attached to the State in HFSM inherit from this class, but you can not obtain the objects which inherited from this class directly outside HFSM.
### Properties

1. String StateName[default : ""] **readyonly**

> The name of State, you can not edit it in runtime. Read only.

2. bool IsExited[default : false] **readyonly**

> If true, this State is not running(not enter or already exited). Read only.

3. Node Hfsm[default : null] **readyonly**

> The HFSM instance which contains this State. Ready only.
> **Please use `Set()`, `Get()`, `Call()`, etc, to access menbers of this property.**

4. String AnimationName[default: ""]

> (v1.2 New Feature)
> The animation whcih will be tried to play when this State be entered.
> If remained it as a empty String, the `StateName` will be used as the `AnimationName`.
> If the `animaion_player` of HFSM is invalid or has not target animation, it will not be played.

5. float AnimationBlendTime[default: 0.0f]

> (v1.2 New Feature, Full version only)
> The time of target animation fade in.

6. float AnimationSpeed[default: 1.0f]

> (v1.2 New Feature, Full version only)
> The speed of target animation playing.

7. bool AnimationPlayBackwards[default: false]

> (v1.2 New Feature, Full version only)
> To play the animation backward or not.

### Methods

​ Read [State Behavior](#state-behavior--code-control) for more informations of overridable methods.

1. void ManualExit()

> Exit State Manually , and execute its exit behavior.

2. void Init() virtual

> Overridable, called when HFSM is generated, values of all custom properties will be confirm as initial value.

3. void Entry() virtual

> Overridable, called when State is entering.

4. void Update(float delta) virtual

> Overridable, called when State updating.

5. void PhysicsUpdate(float delta) virtual

> Overridable, called when State physics updating.

6. void Exit() virtual

> Overridable, called when State exiting.



Expand Down
Loading

0 comments on commit 7726535

Please sign in to comment.