迁移剩下的 UI 到 Serialization 方式
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Definition;
|
||||
using SepCore.InputModule;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class HudController : UIControllerBase<HudContext, HudForm>
|
||||
{
|
||||
protected override UIFormType UIFormType => UIFormType.HudForm;
|
||||
|
||||
protected override void RefreshUI(HudForm form, HudContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.InputModule.DeviceKindChanged += OnDeviceKindChanged;
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.InputModule.DeviceKindChanged -= OnDeviceKindChanged;
|
||||
}
|
||||
|
||||
private static HudContext BuildHudContext()
|
||||
{
|
||||
return new HudContext
|
||||
{
|
||||
MovePrompt = BuildPromptContext(InputActionId.Move)
|
||||
};
|
||||
}
|
||||
|
||||
private static string BuildPromptContext(InputActionId actionId)
|
||||
{
|
||||
if (!GameEntry.InputModule.TryGetPrompt(actionId, out InputPrompt prompt))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return InputPromptTextUtility.BuildTmpText(prompt);
|
||||
}
|
||||
|
||||
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
|
||||
{
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Error("HudController.OpenUIAsync() userData type is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
await OpenFormAsync(BuildHudContext(), timeout);
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
Log.Info("HudFormController doesn't need UseCase");
|
||||
}
|
||||
|
||||
private void OnDeviceKindChanged(InputDeviceKind deviceKind)
|
||||
{
|
||||
Context.MovePrompt = BuildPromptContext(InputActionId.Move);
|
||||
Form.RefreshMovePrompt(Context.MovePrompt);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user