56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
using UnityEngine.InputSystem.Interactions;
|
||
|
|
||
|
namespace BITFALL.Scene
|
||
|
{
|
||
|
public class ActionBasedCancel : ActionBasedComponent
|
||
|
{
|
||
|
[SerializeField] private InputActionReference cancelAction;
|
||
|
|
||
|
protected override void OnEnable()
|
||
|
{
|
||
|
base.OnEnable();
|
||
|
InputActionGroup.EnsureCreated(cancelAction);
|
||
|
actionBasedObject.OnTick += OnTick;
|
||
|
actionBasedObject.OnStarted += OnStarted;
|
||
|
actionBasedObject.OnCompleted += OnStop;
|
||
|
actionBasedObject.OnCanceled += OnStop;
|
||
|
}
|
||
|
protected override void OnDisable()
|
||
|
{
|
||
|
base.OnDisable();
|
||
|
actionBasedObject.OnTick -= OnTick;
|
||
|
actionBasedObject.OnStarted -= OnStarted;
|
||
|
actionBasedObject.OnCompleted -= OnStop;
|
||
|
actionBasedObject.OnCanceled -= OnStop;
|
||
|
}
|
||
|
private void OnStarted()
|
||
|
{
|
||
|
InputActionGroup.RegisterCallback(cancelAction, Cancel);
|
||
|
}
|
||
|
private void OnStop()
|
||
|
{
|
||
|
InputActionGroup.UnRegisterCallback(cancelAction, Cancel);
|
||
|
}
|
||
|
private void OnTick(float obj)
|
||
|
{
|
||
|
switch (actionBasedObject.ActionMode)
|
||
|
{
|
||
|
case HoldAction when
|
||
|
actionBasedObject.ElapsedTime>0.1f
|
||
|
&& InputActionGroup.GetAction(cancelAction).IsPressed() is false:
|
||
|
throw new InGameException("取消互动");
|
||
|
}
|
||
|
}
|
||
|
private void Cancel(InputAction.CallbackContext context)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|