66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
|
|
|||
|
using Animancer;
|
|||
|
using NodeCanvas.Framework;
|
|||
|
using NodeCanvas.StateMachines;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Ether
|
|||
|
{
|
|||
|
[RequireComponent(typeof(Rigidbody2D))]
|
|||
|
public class PlayerController : MonoBehaviour
|
|||
|
{
|
|||
|
Rigidbody2D playerRigid;
|
|||
|
FSMOwner fsmOwer;
|
|||
|
Blackboard blackboard;
|
|||
|
|
|||
|
bool isInputEnabled = true;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
playerRigid = GetComponent<Rigidbody2D>();
|
|||
|
fsmOwer = GetComponent<FSMOwner>();
|
|||
|
blackboard = GetComponent<Blackboard>();
|
|||
|
|
|||
|
DontDestroyOnLoad(gameObject);
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
EventCenter.AddListener<ReInputEvent, Vector2>(ReInputEvent.Move, OnMove);
|
|||
|
}
|
|||
|
|
|||
|
private void OnMove(Vector2 move)
|
|||
|
{
|
|||
|
if (!isInputEnabled)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (move == Vector2.zero)
|
|||
|
{
|
|||
|
blackboard.SetVariableValue("moveDirection", move);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
blackboard.SetVariableValue("moveDirection", move);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SetInputOperation(bool isEnable)
|
|||
|
{
|
|||
|
Vector2 moveDirection = blackboard.GetVariableValue<Vector2>("moveDirection");
|
|||
|
if (moveDirection != Vector2.zero)
|
|||
|
{
|
|||
|
blackboard.SetVariableValue("direction", moveDirection);
|
|||
|
blackboard.SetVariableValue("moveDirection", Vector2.zero);
|
|||
|
}
|
|||
|
isInputEnabled = isEnable;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
EventCenter.RemoveListener<ReInputEvent, Vector2>(ReInputEvent.Move, OnMove);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|