npx skillsauth add 958877748/skills fsmInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Cocos Creator 有限状态机 (FSM) 框架,用于简化游戏对象的状态管理。
状态类需要实现 State 接口:
class 你的状态类 implements State<你的上下文类> {
context: 你的上下文类
onEnter(): void {
// 进入状态时的逻辑
}
onUpdate(dt: number): void {
// 每帧更新的逻辑
}
onExit(): void {
// 退出状态时的逻辑
}
}
export interface Context {
state: State<Context>
// 其他属性...
}
// 切换到新状态
changeState(context, 新状态类)
// 切换并设置属性
changeState(context, 新状态类, (state) => {
state.属性 = 值
})
update(dt: number) {
if (this.context.state) {
this.context.state.onUpdate(dt)
}
}
状态接口:
export interface State<T> {
context: T
onEnter(): void
onUpdate(dt: number): void
onExit(): void
}
改变状态函数:
export function changeState<T extends State<Context>>(
context: Context,
cls: { new(): T },
call?: (state: T) => void
)
context: 状态上下文cls: 新的状态类call: 可选,设置新状态的属性状态上下文接口:
export interface Context {
state: State<Context>
}
// 定义上下文
class Player {
state: PlayerState
hp: number = 100
}
// 定义状态基类
class PlayerState implements State<Player> {
context: Player
onEnter(): void {}
onUpdate(dt: number): void {}
onExit(): void {}
}
// 待机状态
class IdleState extends PlayerState {
onEnter(): void {
console.log("进入待机")
}
}
// 移动状态
class MoveState extends PlayerState {
onEnter(): void {
console.log("开始移动")
}
}
// 使用
let player = new Player()
changeState(player, IdleState)
function update(dt: number) {
if (player.state) {
player.state.onUpdate(dt)
}
}
tools
Cocos Creator 2.4.x 场景/预制体命令行工具,支持读写 .fire/.prefab、JSON 生成 UI、截图预览
development
查询公网IP地址的地理位置信息,包括国家、省份、城市、ISP、时区等
tools
Cocos Creator 2.4.x 粒子系统修饰器开发框架。用于创建、使用和调试自定义粒子修饰器,支持修改粒子位置、颜色、大小、旋转、速度等属性。当需要在 Cocos Creator 中实现复杂的粒子效果控制时使用此技能。
development
使用魔搭平台(ModelScope)API进行图片生成和编辑