CangJie/Assets/Scripts//StateMachineBase.cs
Roman 876778ccb0 任务:编写底层逻辑,增加一些有用的工具类
1.新增单例模式单例类模板,可以广泛用在同时间只有一个存在在场景中的各种管理器
2.新增事件框架
3.新增状态模式的状态类和状态管理员类的类模板
4.新增进入式触发器
5.新增互动式触发器(涉及玩家类的更改,暂缓)
*.以上均为底层代码,目前无法测试,如果发现问题请联系开发者,如无必要,请勿修改

我是每天上班提醒小助手,今天你上班了吗?😺
2022-03-12 21:14:07 +08:00

42 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 状态模式的状态管理员基类,每一组状态的管理员都必须继承这个类
/// </summary>
public class StateMachineBase : MonoBehaviour
{
protected StateBase currentState;
protected bool isBegin = false;
/// <summary>
/// 改变状态的时候调用
/// </summary>
/// <param name="newState"></param>
public void ChangeState(StateBase newState)
{
isBegin = false;
if (currentState != null)
{
currentState.End();
}
currentState = newState;
}
/// <summary>
/// 状态的每一帧调用需要手动安排到主程序的Update中切记
/// </summary>
public void StateUpdate()
{
if (currentState != null)
{
if (!isBegin)
{
currentState.Enter();
isBegin = true;
}
currentState.StateUpdate();
}
}
}