FSM_Over
This commit is contained in:
53
Assets/03.FiniteStateMachine/RunTime/PlayerFSMExample.cs
Normal file
53
Assets/03.FiniteStateMachine/RunTime/PlayerFSMExample.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PlayerFSMExample : MonoBehaviour
|
||||
{
|
||||
private int controllerId;
|
||||
private int idleStateId;
|
||||
private float timer = 0.0f;
|
||||
private FSMManager fSMManager;
|
||||
|
||||
void Start()
|
||||
{
|
||||
fSMManager = FSMInitialize.Init(gameObject.scene);
|
||||
controllerId = fSMManager.CreateFSMController();
|
||||
StateDateAction stateDateAction = new StateDateAction()
|
||||
{
|
||||
OnEnterAction = () =>
|
||||
{
|
||||
Debug.Log("进入状态");
|
||||
},
|
||||
UpdateAction = () =>
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
Debug.Log("当前时间:" + timer);
|
||||
},
|
||||
OnExitAction = () =>
|
||||
{
|
||||
Debug.Log("离开状态");
|
||||
}
|
||||
};
|
||||
idleStateId = fSMManager.CreateState(controllerId, stateDateAction);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 按下空格键切换到Running状态
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
fSMManager.EnterState(idleStateId);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
fSMManager.ExitState(idleStateId);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user