优化整体流程和修复HUD数值更新BUG

This commit is contained in:
2026-07-05 16:18:04 +08:00
parent 31cbb580b6
commit 1caf10d602
15 changed files with 1448 additions and 44 deletions
@@ -78,16 +78,20 @@ namespace IndianOceanAssets.Engine2_5D
// Handles death logic and effects
public void Die()
{
Debug.Log($"[HealthSystem] Die() called on {gameObject.name}, dissolveMaterial={(dissolveMaterial != null ? dissolveMaterial.name : "NULL")}");
if (deathEffect != null)
Instantiate(deathEffect, transform.position + new Vector3(0f, .5f, 0f), Quaternion.identity);
// 如果有溶解材质,播放消隐动画后再销毁
if (dissolveMaterial != null)
{
Debug.Log($"[HealthSystem] Starting DissolveAndDestroy coroutine on {gameObject.name}");
StartCoroutine(DissolveAndDestroy());
}
else
{
Debug.Log($"[HealthSystem] No dissolve material, destroying {gameObject.name} immediately");
Destroy(gameObject);
}
}
@@ -97,6 +101,8 @@ namespace IndianOceanAssets.Engine2_5D
/// </summary>
private IEnumerator DissolveAndDestroy()
{
Debug.Log($"[HealthSystem] DissolveAndDestroy START on {gameObject.name}");
// 禁用碰撞体和刚体,防止死亡过程中仍能触发碰撞或受重力下坠
foreach (var col in GetComponents<Collider>())
col.enabled = false;
@@ -114,15 +120,30 @@ namespace IndianOceanAssets.Engine2_5D
mb.enabled = false;
}
// 切换所有 SpriteRenderer 到溶解材质
// 等一帧,确保禁用生效
yield return null;
// 切换所有 SpriteRenderer 到溶解材质(保留原始纹理和颜色)
var renderers = GetComponentsInChildren<SpriteRenderer>();
var originalMats = new Material[renderers.Length][];
Debug.Log($"[HealthSystem] DissolveAndDestroy: {renderers.Length} SpriteRenderers on {gameObject.name}");
for (int i = 0; i < renderers.Length; i++)
{
originalMats[i] = renderers[i].materials;
renderers[i].materials = new Material[] { new Material(dissolveMaterial) };
// 创建溶解材质实例,并复制原始纹理 + 颜色
var dissolveMat = new Material(dissolveMaterial);
if (renderers[i].sprite != null)
dissolveMat.mainTexture = renderers[i].sprite.texture;
dissolveMat.SetColor("_Color", renderers[i].color);
dissolveMat.SetFloat("_DissolveAmount", 0f);
renderers[i].material = dissolveMat;
}
// 再等一帧,确保材质切换生效
yield return null;
Debug.Log($"[HealthSystem] Starting dissolve animation, fadeDuration={fadeDuration}");
// 动画溶解
float elapsed = 0f;
while (elapsed < fadeDuration)
@@ -139,6 +160,7 @@ namespace IndianOceanAssets.Engine2_5D
yield return null;
}
Debug.Log($"[HealthSystem] Dissolve complete, destroying {gameObject.name}");
Destroy(gameObject);
}
}
@@ -35,5 +35,5 @@ Material:
- _DissolveNoiseScale: 10
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _DissolveEdgeColor: {r: 1, g: 0.8, b: 0.3, a: 1}
- _DissolveEdgeColor: {r: 0.3, g: 0.6, b: 1, a: 1}
m_BuildTextureStacks: []
@@ -10,7 +10,7 @@ Shader "Custom/SpriteDissolve"
[Header(Dissolve)]
_DissolveAmount ("溶解进度", Range(0, 1)) = 0
_DissolveEdgeWidth ("边缘宽度", Range(0, 0.3)) = 0.05
_DissolveEdgeColor ("边缘颜色", Color) = (1, 0.8, 0.3, 1)
_DissolveEdgeColor ("边缘颜色", Color) = (0.3, 0.6, 1, 1)
_DissolveNoiseScale ("噪声缩放", Float) = 10
// 阴影设置(保持与项目一致)
File diff suppressed because it is too large Load Diff
+73 -22
View File
@@ -833,7 +833,7 @@ MonoBehaviour:
m_GameObject: {fileID: 956194999}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
@@ -844,20 +844,75 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 36
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 0
m_text: 0
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 7b2d3c4c2e857f14aaa0e7fb9ebab7e5, type: 2}
m_sharedMaterial: {fileID: -1264883736430894452, guid: 7b2d3c4c2e857f14aaa0e7fb9ebab7e5, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4287124462
m_fontColor: {r: 0.93333334, g: 0.3254902, b: 0.53333336, 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: 69.9
m_fontSizeBase: 69.9
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
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: 0
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 &963194225
GameObject:
m_ObjectHideFlags: 0
@@ -1136,12 +1191,8 @@ MonoBehaviour:
lineSprite: {fileID: 21300000, guid: c9f1fae21aac59242836f5e4529afa17, type: 3}
bgPointImage: {fileID: 165255196}
bgPointSprite: {fileID: 21300000, guid: 661924bcc4d953349baa740051ca9895, type: 3}
submitSFX:
audioClip: {fileID: 0}
volume: 1
cancelSFX:
audioClip: {fileID: 0}
volume: 1
submitSFX: {fileID: 0}
cancelSFX: {fileID: 0}
--- !u!114 &1828901353
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1200,7 +1251,7 @@ Canvas:
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 0
m_AdditionalShaderChannelsFlag: 25
m_UpdateRectTransformForStandalone: 0
m_SortingLayerID: 0
m_SortingOrder: 0
File diff suppressed because one or more lines are too long
+9
View File
@@ -91,6 +91,15 @@ namespace GameFramework
void Update()
{
// 延迟订阅 ScoreManager(跨场景后 ScoreManager 可能才创建)
if (!_subscribedScoreEvent && ScoreManager.Instance != null)
{
ScoreManager.onScoreChanged += UpdateSoulCount;
_subscribedScoreEvent = true;
UpdateSoulCount(ScoreManager.Instance.CurrentScore);
Debug.Log("[GameHUD] 延迟订阅 ScoreManager.onScoreChanged 成功");
}
UpdateLifeIcons();
UpdateSkillCooldowns();
}
+6 -2
View File
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace GameFramework
{
@@ -22,7 +23,7 @@ namespace GameFramework
[SerializeField] private GameObject winPanel;
[SerializeField] private Image winTitleImage; // "你做到了" 图片
[SerializeField] private Sprite winTitleSprite; // nizuodaol.png
[SerializeField] private Text soulCountText; // 魂灵数量
[SerializeField] private TextMeshProUGUI soulCountText; // 魂灵数量
[SerializeField] private Image soulCountBgImage; // 魂灵数量底图
[SerializeField] private Sprite soulCountBgSprite; // bgpoint.png
[SerializeField] private Image newRecordImage; // "新记录" 图片
@@ -38,7 +39,7 @@ namespace GameFramework
[Header("排行榜")]
[SerializeField] private GameObject leaderboardPanel;
[SerializeField] private Transform leaderboardContainer;
[SerializeField] private Text finalScoreText;
[SerializeField] private TextMeshProUGUI finalScoreText;
[Header("新纪录输入")]
[SerializeField] private GameObject newHighScorePanel;
@@ -284,8 +285,11 @@ namespace GameFramework
void OnMainMenuClick()
{
Time.timeScale = 1f;
if (SceneLoader.Instance != null)
SceneLoader.Instance.LoadMainMenuScene();
else
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
}
#endregion
}
@@ -564,6 +564,8 @@ MonoBehaviour:
maxHealth: 3
deathEffect: {fileID: 0}
isPlayer: 0
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
fadeDuration: 2
--- !u!114 &1099825457660127417
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -476,6 +476,8 @@ MonoBehaviour:
maxHealth: 3
deathEffect: {fileID: 0}
isPlayer: 0
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
fadeDuration: 2
--- !u!114 &6371374142521685546
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -564,6 +564,8 @@ MonoBehaviour:
maxHealth: 3
deathEffect: {fileID: 0}
isPlayer: 0
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
fadeDuration: 2
--- !u!114 &467771591586586371
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -476,6 +476,8 @@ MonoBehaviour:
maxHealth: 3
deathEffect: {fileID: 0}
isPlayer: 0
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
fadeDuration: 2
--- !u!114 &7993147426357698
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -353,6 +353,8 @@ MonoBehaviour:
maxHealth: 3
deathEffect: {fileID: 0}
isPlayer: 0
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
fadeDuration: 2
--- !u!114 &1011900935948289768
MonoBehaviour:
m_ObjectHideFlags: 0