Files
plugin-library/Assets/03.FiniteStateMachine/RunTime/PlayerFSMExample.cs

53 lines
1.2 KiB
C#
Raw Normal View History

2025-03-21 18:34:26 +08:00
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("<22><><EFBFBD><EFBFBD>״̬");
},
UpdateAction = () =>
{
timer += Time.deltaTime;
Debug.Log("<22><>ǰʱ<C7B0>䣺" + timer);
},
OnExitAction = () =>
{
Debug.Log("<22>뿪״̬");
}
};
idleStateId = fSMManager.CreateState(controllerId, stateDateAction);
}
void Update()
{
// <20><><EFBFBD>¿ո<C2BF><D5B8><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD>Running״̬
if (Input.GetKeyDown(KeyCode.A))
{
fSMManager.EnterState(idleStateId);
}
if (Input.GetKeyDown(KeyCode.D))
{
fSMManager.ExitState(idleStateId);
}
}
void OnDestroy()
{
}
}