接入 Hud 输入提示并完善 InputModule 提示映射

This commit is contained in:
SepComet
2026-06-12 14:59:16 +08:00
parent a2cd3ab7e7
commit 024ec7be99
13 changed files with 397 additions and 33 deletions
@@ -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
+139
View File
@@ -166,6 +166,142 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &1181223948078793352
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 844544797351374585}
- component: {fileID: 8628784289326000741}
- component: {fileID: 4622934279017998176}
m_Layer: 5
m_Name: InputPrompt
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &844544797351374585
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1181223948078793352}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5845023051097607336}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -50, y: 100}
m_SizeDelta: {x: 600, y: 150}
m_Pivot: {x: 1, y: 0.5}
--- !u!222 &8628784289326000741
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1181223948078793352}
m_CullTransparentMesh: 1
--- !u!114 &4622934279017998176
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1181223948078793352}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "<sprite name=\"keyboard_w\"><sprite name=\"keyboard_a\"><sprite name=\"keyboard_s\"><sprite
name=\"keyboard_d\">\u79FB\u52A8"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 99d811b0183246646a2ce8df996f4bca, type: 2}
m_sharedMaterial: {fileID: -1106088975554028259, guid: 99d811b0183246646a2ce8df996f4bca,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 80
m_fontSizeBase: 80
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 100
m_fontStyle: 0
m_HorizontalAlignment: 4
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &1588863174275057922
GameObject:
m_ObjectHideFlags: 0
@@ -798,6 +934,7 @@ RectTransform:
- {fileID: 2701155363628883645}
- {fileID: 5367559285010484074}
- {fileID: 716378031281921353}
- {fileID: 844544797351374585}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@@ -825,6 +962,8 @@ MonoBehaviour:
_coinText: {fileID: 2927128461236740550}
_levelTimeLeftText: {fileID: 4547091306916251724}
_enemyCountText: {fileID: 1716982582738894949}
_movePromptRoot: {fileID: 1181223948078793352}
_movePromptText: {fileID: 4622934279017998176}
--- !u!1 &5990189277179061188
GameObject:
m_ObjectHideFlags: 0