迁移剩下的 UI 到 Serialization 方式
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Definition;
|
||||
using SepCore.InputModule;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class JoystickController : UIControllerBase<JoystickContext, JoystickForm>
|
||||
{
|
||||
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;
|
||||
|
||||
Context.Direction = cmd.Vector2Value;
|
||||
Context.Magnitude = cmd.Vector2Value.magnitude;
|
||||
Form.RefreshUI(Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user