mirror of
https://github.com/ConjureETS/GameOff2024.git
synced 2026-03-24 05:00:59 +00:00
62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System;
|
|
using GameOff.Player;
|
|
using UnityEngine;
|
|
|
|
namespace GameOff.Core
|
|
{
|
|
public class PlayerMain : MonoBehaviour
|
|
{
|
|
public static PlayerMain Instance { get; private set; }
|
|
|
|
public event EventHandler<bool> OnStateUpdate;
|
|
|
|
private PlayerInputHandler _inputHandler;
|
|
|
|
private IState _currentState;
|
|
private PlayerClassState _classState;
|
|
private PlayerQuizState _quizState;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance)
|
|
{
|
|
Debug.LogError($"PlayerMain already exist! {transform}");
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
_inputHandler = GetComponent<PlayerInputHandler>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_inputHandler.OnChangeState += InputHandler_OnChangeState;
|
|
|
|
_classState = new PlayerClassState();
|
|
_quizState = new PlayerQuizState();
|
|
_currentState = _classState;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_currentState.UpdateState();
|
|
}
|
|
|
|
private void InputHandler_OnChangeState(object sender, EventArgs e)
|
|
{
|
|
bool isClass = _currentState is PlayerQuizState;
|
|
Debug.Log(isClass);
|
|
ChangeState(isClass ? _quizState : _classState);
|
|
OnStateUpdate?.Invoke(this, isClass);
|
|
}
|
|
|
|
private void ChangeState(IState next)
|
|
{
|
|
_currentState.ExitState();
|
|
_currentState = next;
|
|
_currentState.EnterState();
|
|
}
|
|
}
|
|
}
|