特效新内容。修复gameplay致命bug和分数保存bug

This commit is contained in:
2026-02-16 01:55:18 +08:00
parent 3a7a0b4669
commit 9f7c1c57b7
206 changed files with 112684 additions and 857 deletions
@@ -37,6 +37,13 @@ public class GfxController : MonoBehaviour
public GameObject k_o_fx;
public GameObject koFatherObject;
[Header("Explosion Effect Settings")]
[Tooltip("当单次伤害超过敌人最大生命值的百分比时触发爆炸 (0.2 = 20%)")]
public float explosionDamageThresholdRatio = 0.2f;
[Tooltip("爆炸特效是否使用独立的缩放设置 (否则跟随Hit特效缩放)")]
public bool useExplosionSeparateScale = false;
public float explosionFxScale = 1.5f;
[Header("Hit Effect Settings - Enemy")]
public float enemyOffsetX = 0f;
public float enemyOffsetY = 0f;
@@ -123,11 +130,26 @@ public class GfxController : MonoBehaviour
/// <param name="isEnemy">是否为敌人受击</param>
/// <param name="customWorldPos">可选:自定义世界坐标播放(如匹配弹道终点)</param>
/// <param name="scaleOverride">可选:强制指定特效缩放倍率</param>
public void PlayHitFX(GameObject target, GameObject parent = null, bool isEnemy = false, Vector3? customWorldPos = null, float? scaleOverride = null)
/// <param name="damageInfo">可选:传入伤害信息以判断是否触发爆炸特效 (damage, maxHealth)</param>
public void PlayHitFX(GameObject target, GameObject parent = null, bool isEnemy = false, Vector3? customWorldPos = null, float? scaleOverride = null, (float damage, float maxHealth)? damageInfo = null)
{
if (target == null || hitFX == null)
// Determine which FX prefab to use (Hit or Explosion)
GameObject fxPrefab = hitFX;
bool isExplosion = false;
if (isEnemy && damageInfo.HasValue && explosionFX != null)
{
if (hitFX == null) Debug.LogWarning("[GfxController] hitFX Prefab 未在 Inspector 中分配!");
float ratio = damageInfo.Value.damage / damageInfo.Value.maxHealth;
if (ratio >= explosionDamageThresholdRatio)
{
fxPrefab = explosionFX;
isExplosion = true;
}
}
if (target == null || fxPrefab == null)
{
if (fxPrefab == null) Debug.LogWarning($"[GfxController] {(isExplosion ? "ExplosionFX" : "HitFX")} Prefab 未在 Inspector 中分配!");
return;
}
@@ -176,7 +198,14 @@ public class GfxController : MonoBehaviour
}
else if (isEnemy)
{
fxScale = useEnemyRandomScale ? Random.Range(enemyMinFxScale, enemyMaxFxScale) : enemyFxScale;
if (isExplosion && useExplosionSeparateScale)
{
fxScale = explosionFxScale;
}
else
{
fxScale = useEnemyRandomScale ? Random.Range(enemyMinFxScale, enemyMaxFxScale) : enemyFxScale;
}
}
else
{
@@ -194,7 +223,7 @@ public class GfxController : MonoBehaviour
visualParent.transform.localScale = Vector3.one * fxScale;
// 作为子物体生成
fx = Instantiate(hitFX, visualParent.transform);
fx = Instantiate(fxPrefab, visualParent.transform);
// 确保特效在 UI 层级中显示在最前方
fx.transform.SetAsLastSibling();
@@ -215,7 +244,7 @@ public class GfxController : MonoBehaviour
rt.localRotation = Quaternion.identity;
// 确保 UI 特效的原始大小正确,且 localScale 为 1(继承 parent 的缩放)
rt.sizeDelta = hitFX.GetComponent<RectTransform>().sizeDelta;
rt.sizeDelta = fxPrefab.GetComponent<RectTransform>().sizeDelta;
rt.localScale = Vector3.one;
}
else
@@ -235,7 +264,7 @@ public class GfxController : MonoBehaviour
else
{
Vector3 spawnPos = customWorldPos.HasValue ? customWorldPos.Value : (target.transform.position + offsetVector);
fx = Instantiate(hitFX, spawnPos, Quaternion.identity);
fx = Instantiate(fxPrefab, spawnPos, Quaternion.identity);
fx.transform.localScale = Vector3.one * fxScale;
}