using System.Collections; using System.Collections.Generic; using UnityEngine; using BITKit; using BITKit.Entities; using UnityEngine.UIElements; using UnityEngine.InputSystem; using BITKit.Animations; using BITKit.StateMachine; using BITFALL; namespace BITFALL.Guns { [System.Serializable] public class Idle : GunState, ISelectableCallback { public override void OnStateEnter(IState old) { root.animator.CrossFade(BITGun._Movement, 0.16f); root.Entity.RegisterCallback(this); } public override void OnStateExit(IState old, IState newState) { base.OnStateExit(old, newState); root.Entity.UnRegisterCallback(this); } public override void OnStateUpdate() { if (root.animator[0].stateName is BITGun._Movement) { if (root.isFiring.shouldBe && root.fireUpdater) { root.Fire(); } if (root.isAiming.shouldBe && BITAppForUnity.AllowCursor == false) { root.stateMachine.StateMachine.TransitionState(); } } } public override void OnMovementCallback(IMovementCallback callback) { switch (callback) { case OnRunCallback runCallback: if (runCallback.started || runCallback.updated) { root.stateMachine.StateMachine.TransitionState(); } break; } } public void OnHover(ISelectable selectable) { } public void OnActive(ISelectable selectable) { root.animator.Play(BITGun._Interactive); } public void OnInactive(ISelectable selectable) { } } [System.Serializable] public class Run : GunState { public override void OnStateEnter(IState old) { root.animator.CrossFade(BITGun._Run, 0.16f); root.actionGroup.RegisterCallback(root.aimAction, OnAim); } public override void OnStateExit(IState old, IState newState) { root.actionGroup.UnRegisterCallback(root.aimAction, OnAim); } public override void OnStateUpdate() { if (root.animator[0].stateName == BITGun._Movement) { root.animator.CrossFade(BITGun._Run, 0.32f); } } public override void OnMovementCallback(IMovementCallback callback) { switch (callback) { case OnRunCallback runCallback: if (runCallback.canceled || runCallback.updated is false) { root.stateMachine.StateMachine.TransitionState(); } break; } } void OnAim(InputAction.CallbackContext context) { if (context.started && BITAppForUnity.AllowCursor == false) { root.stateMachine.StateMachine.TransitionState(); } } } [System.Serializable] public class Aim : GunState { public override void OnStateEnter(IState old) { root.animator.CrossFade(BITGun._Aim, 0.16f); root.Entity .Invoke( new CancelRunOrSprint() ); } public override void OnStateUpdate() { if (root.isFiring.shouldBe && root.fireUpdater) { root.Fire(); } if (BITAppForUnity.AllowCursor) { root.stateMachine.StateMachine.TransitionState(); } else if (root.isAiming.shouldBe) { } else { root.stateMachine.StateMachine.TransitionState(); } } public override void OnMovementCallback(IMovementCallback callback) { switch (callback) { case OnRunCallback runCallback: if (runCallback.started) { root.stateMachine.StateMachine.TransitionState(); } break; } } } [System.Serializable] public class Equip : GunState { IntervalUpdate updater = new(0.16f); public override void OnStateEnter(IState old) { updater.Reset(); root.animator.Play(BITGun._Equip); } public override void OnStateUpdate() { var state = root.animator[0]; if (updater.canUpdate) { if (state.stateName == BITGun._Equip) { if (state.currentState.normalizedTime >= 1) { root.stateMachine.StateMachine.TransitionState(); } } else { root.animator.Play(BITGun._Equip); } } } } }