接入 Hud 输入提示并完善 InputModule 提示映射
This commit is contained in:
@@ -2,5 +2,6 @@ namespace SepCore.UI
|
||||
{
|
||||
public class HudContext : UIContext
|
||||
{
|
||||
public string MovePrompt { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Definition;
|
||||
using SepCore.InputModule;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
@@ -13,9 +14,32 @@ namespace SepCore.UI
|
||||
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();
|
||||
return new HudContext
|
||||
{
|
||||
MovePrompt = BuildPromptContext(InputActionId.Move)
|
||||
};
|
||||
}
|
||||
|
||||
private static string BuildPromptContext(InputActionId actionId)
|
||||
{
|
||||
if (GameEntry.InputModule == null || !GameEntry.InputModule.TryGetPrompt(actionId, out InputPrompt prompt))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return InputPromptTextUtility.BuildTmpText(prompt);
|
||||
}
|
||||
|
||||
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
|
||||
@@ -33,5 +57,16 @@ namespace SepCore.UI
|
||||
{
|
||||
Log.Info("HudFormController doesn't need UseCase");
|
||||
}
|
||||
|
||||
private void OnDeviceKindChanged(InputDeviceKind deviceKind)
|
||||
{
|
||||
if (Context == null || Form == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Context.MovePrompt = BuildPromptContext(InputActionId.Move);
|
||||
Form.RefreshMovePrompt(Context.MovePrompt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,27 @@ namespace SepCore.UI
|
||||
|
||||
[SerializeField] private TMP_Text _enemyCountText;
|
||||
private EnemyManagerComponent _enemy;
|
||||
|
||||
|
||||
[SerializeField] private GameObject _movePromptRoot;
|
||||
[SerializeField] private TMP_Text _movePromptText;
|
||||
|
||||
public void RefreshUI(HudContext hudContext)
|
||||
{
|
||||
RefreshMovePrompt(hudContext?.MovePrompt);
|
||||
}
|
||||
|
||||
public void RefreshMovePrompt(string prompt)
|
||||
{
|
||||
bool visible = !string.IsNullOrEmpty(prompt);
|
||||
if (_movePromptRoot != null)
|
||||
{
|
||||
_movePromptRoot.SetActive(visible);
|
||||
}
|
||||
|
||||
if (_movePromptText != null)
|
||||
{
|
||||
_movePromptText.text = prompt;
|
||||
}
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
Reference in New Issue
Block a user