增加技能按钮说明

This commit is contained in:
2026-07-06 11:57:27 +08:00
parent 50d42f8f9e
commit a2f750c234
2 changed files with 43 additions and 7 deletions
+40 -4
View File
@@ -1,6 +1,7 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using TMPro;
using GameFramework;
/// <summary>
@@ -209,17 +210,17 @@ public static class UIBuilder
skillLayout.childAlignment = TextAnchor.LowerRight;
// 冲刺技能
var sprintObj = CreateSkillIcon(skillArea.transform, "SkillSprint", sprintIconSprite, new Color(0.3f, 0.8f, 1f));
var sprintObj = CreateSkillIcon(skillArea.transform, "SkillSprint", sprintIconSprite, new Color(0.3f, 0.8f, 1f), "空格");
so.FindProperty("skillSprintIcon").objectReferenceValue = sprintObj.transform.Find("Icon").GetComponent<Image>();
so.FindProperty("skillSprintCD").objectReferenceValue = sprintObj.transform.Find("CDOverlay").GetComponent<Image>();
// 摇铃技能
var bellObj = CreateSkillIcon(skillArea.transform, "SkillBell", bellIconSprite, new Color(1f, 0.85f, 0.2f));
var bellObj = CreateSkillIcon(skillArea.transform, "SkillBell", bellIconSprite, new Color(1f, 0.85f, 0.2f), "E");
so.FindProperty("skillBellIcon").objectReferenceValue = bellObj.transform.Find("Icon").GetComponent<Image>();
so.FindProperty("skillBellCD").objectReferenceValue = bellObj.transform.Find("CDOverlay").GetComponent<Image>();
// 灵灯技能
var lanternObj = CreateSkillIcon(skillArea.transform, "SkillLantern", lanternIconSprite, new Color(1f, 0.6f, 0.2f));
var lanternObj = CreateSkillIcon(skillArea.transform, "SkillLantern", lanternIconSprite, new Color(1f, 0.6f, 0.2f), "鼠标左键");
so.FindProperty("skillLanternIcon").objectReferenceValue = lanternObj.transform.Find("Icon").GetComponent<Image>();
so.FindProperty("skillLanternCD").objectReferenceValue = lanternObj.transform.Find("CDOverlay").GetComponent<Image>();
@@ -372,7 +373,7 @@ public static class UIBuilder
return obj;
}
private static GameObject CreateSkillIcon(Transform parent, string name, Sprite sprite, Color cdColor)
private static GameObject CreateSkillIcon(Transform parent, string name, Sprite sprite, Color cdColor, string keyText)
{
var container = new GameObject(name);
container.transform.SetParent(parent, false);
@@ -421,6 +422,41 @@ public static class UIBuilder
cdImg.fillAmount = 0f;
cdObj.SetActive(false); // 初始无 CD
// 按键提示标签(黑底白字,位于图标上方)
if (!string.IsNullOrEmpty(keyText))
{
var hintObj = new GameObject("KeyHint");
hintObj.transform.SetParent(container.transform, false);
var hintRect = hintObj.AddComponent<RectTransform>();
hintRect.anchorMin = new Vector2(0.5f, 1f);
hintRect.anchorMax = new Vector2(0.5f, 1f);
hintRect.pivot = new Vector2(0.5f, 0f);
hintRect.anchoredPosition = new Vector2(0, 6f);
hintRect.sizeDelta = new Vector2(60, 22);
var hintBg = hintObj.AddComponent<Image>();
hintBg.color = new Color(0, 0, 0, 0.85f);
var textObj = new GameObject("Text");
textObj.transform.SetParent(hintObj.transform, false);
var textRect = textObj.AddComponent<RectTransform>();
textRect.anchorMin = Vector2.zero;
textRect.anchorMax = Vector2.one;
textRect.sizeDelta = Vector2.zero;
var tmp = textObj.AddComponent<TextMeshProUGUI>();
tmp.text = keyText;
tmp.fontSize = 14;
tmp.fontStyle = FontStyles.Normal;
tmp.color = Color.white;
tmp.alignment = TextAlignmentOptions.Center;
// 加载中文字体
var font = AssetDatabase.LoadAssetAtPath<TMPro.TMP_FontAsset>(
"Assets/UI/Art/No.392-ShangShouNiShangTi-2 SDF.asset");
if (font != null) tmp.font = font;
}
return container;
}
+3 -3
View File
@@ -22,7 +22,7 @@ namespace IndianOceanAssets.Engine2_5D
[Header("冷却")]
[Tooltip("放置灵灯的冷却时间(秒)")]
[SerializeField] private float cooldown = 5f;
[SerializeField] private float cooldown = 3.5f;
[Header("灵灯预制体")]
[SerializeField] private GameObject lanternPrefab;
@@ -49,8 +49,8 @@ namespace IndianOceanAssets.Engine2_5D
private void Update()
{
// 按 U 且 CD 就绪 且 还有灵灯 → 放置
if (Input.GetKeyDown(lanternKey)
// 按 U 或鼠标左键 且 CD 就绪 且 还有灵灯 → 放置
if ((Input.GetKeyDown(lanternKey) || Input.GetMouseButtonDown(0))
&& _remainingLanterns > 0
&& Time.time > _lastPlaceTime + cooldown
&& lanternPrefab != null)