This commit is contained in:
CortexCore
2023-10-02 23:24:56 +08:00
parent 8ef5c7ec0a
commit 947e52e748
183 changed files with 107857 additions and 9378 deletions

View File

@@ -1,3 +1,4 @@
using BITKit.Sensors;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
@@ -6,24 +7,16 @@ namespace BITKit.Entities.Player
public class EntityInteractive : EntityPlayerComponent
{
[Header(Constant.Header.Settings)]
public float distance;
public LayerMask layerMask;
[Header(Constant.Header.Input)]
public InputActionReference interactiveAction;
private readonly InputActionGroup inputActionGroup = new();
[Header(Constant.Header.Gameobjects)]
[SerializeField] private Transform cameraTransform;
[SerializeReference, SubclassSelector] private ISensor sensor;
[Header(Constant.Header.InternalVariables)]
private ISelectable selected;
private IntervalUpdate cd = new(0.08f);
public override void OnUpdate(float deltaTime)
{
if (Physics.Raycast(cameraTransform.position,cameraTransform.forward, out var raycastHit, distance, layerMask,QueryTriggerInteraction.Collide))
if (sensor.Get().TryGetAny(x=>x.TryGetComponentAny<ISelectable>(out _),out var detected))
{
if (raycastHit.transform.TryGetComponentAny<ISelectable>(out var _detected))
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
{
if (_detected == selected)
{
@@ -68,7 +61,7 @@ namespace BITKit.Entities.Player
}
public void Interactive(InputAction.CallbackContext context)
{
if (context.interaction is not PressInteraction || !context.performed) return;
if (context.interaction is not PressInteraction || !context.performed || cd.AllowUpdate is false) return;
var _selected = selected;
if (_selected is not MonoBehaviour monoBehaviour) return;
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))