slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

InputTriggerPolling.cs (1198B)


      1 using System;
      2 using UnityEngine;
      3 using UnityEngine.InputSystem;
      4 
      5 namespace Slimecing.Triggers.TriggerLogic
      6 {
      7     [CreateAssetMenu(fileName = "AxisInputTrigger(Polling)", menuName = "Triggers/InputTriggers/AxisInputTrigger(Polling)")]
      8     public class InputTriggerPolling : Trigger
      9     {
     10         [SerializeField] private InputActionReference inputActionReference;
     11 
     12         public InputActionReference currentActionReference
     13         {
     14             get => inputActionReference;
     15             set => inputActionReference = value;
     16         }
     17         
     18         public InputAction action { get; set; }
     19         public PlayerInput currentPlayerInput { get; set; }
     20         public override void EnableTrigger(GameObject target)
     21         {
     22             currentPlayerInput = target.GetComponent<PlayerInput>();
     23             if (currentPlayerInput == null) return;
     24 
     25             foreach (var a in currentPlayerInput.actions)
     26             {
     27                 if (!currentActionReference.action.name.Equals(a.name)) continue;
     28                 a.Enable();
     29                 action = a;
     30             }
     31             
     32         }
     33 
     34         public override T ReadCurrentValue<T>() => (T) Convert.ChangeType(action, typeof(T));
     35 
     36     }
     37 }