using Cysharp.Threading.Tasks; using SepCore.Definition; using SepCore.InputModule; using UnityGameFramework.Runtime; namespace SepCore.UI { public class JoystickController : UIControllerBase { protected override UIFormType UIFormType => UIFormType.JoystickForm; protected override void RefreshUI(JoystickForm form, JoystickContext context) { form.RefreshUI(context); } protected override void SubscribeCustomEvents() { GameEntry.InputModule.CommandTriggered += OnCommandTriggered; } protected override void UnsubscribeCustomEvents() { GameEntry.InputModule.CommandTriggered -= OnCommandTriggered; } public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f) { JoystickContext context = new JoystickContext(); await OpenFormAsync(context, timeout); } public override void BindUseCase(IUIUseCase useCase) { Log.Info("JoystickController doesn't need UseCase"); } private void OnCommandTriggered(InputCommand cmd) { if (cmd.ActionId != InputActionId.Move) return; if (Context == null || Form == null) return; Context.Direction = cmd.Vector2Value; Context.Magnitude = cmd.Vector2Value.magnitude; Form.RefreshUI(Context); } } }