```
chore(plastic): 更新 Plastic SCM 配置文件 更新了 .plastic/plastic.changes 和 .plastic/plastic.wktree 二进制配置文件以同步工作区状态。 ```
This commit is contained in:
1 parent
fac62a5560
commit
83263c1d21
12 files changed
+192
-461
No files matched your search
@@ -21,6 +21,12 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 血条内部填充颜色。
|
||||
public Color fillColor = new Color(0.1f, 0.8f, 0.18f, 1f);
|
||||
|
||||
// 死亡特效持续时间,单位为秒。
|
||||
[Min(0.1f)] public float deathEffectDuration = 1.1f;
|
||||
|
||||
// 死亡时使用的浅蓝色粒子颜色。
|
||||
public Color deathEffectColor = new Color(0.55f, 0.9f, 1f, 1f);
|
||||
|
||||
// 血条 UI 的像素尺寸,实际显示大小由 worldWidth 控制。
|
||||
private const int PixelWidth = 100;
|
||||
private const int PixelHeight = 14;
|
||||
@@ -43,6 +49,9 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 所有血条共用的圆角 Sprite。
|
||||
private static Sprite roundedSprite;
|
||||
|
||||
// 防止死亡逻辑重复执行。
|
||||
private bool isDead;
|
||||
|
||||
// 初始化血量和血条 UI。
|
||||
private void Awake()
|
||||
{
|
||||
@@ -99,8 +108,14 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 直接设置当前生命值,并刷新绿色填充比例。
|
||||
public void SetHealth(float value)
|
||||
{
|
||||
if (isDead) return;
|
||||
|
||||
currentHealth = Mathf.Clamp(value, 0f, maxHealth);
|
||||
UpdateFill();
|
||||
if (currentHealth <= 0f)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
// 让单位受到伤害。
|
||||
@@ -109,6 +124,128 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 让单位恢复生命值。
|
||||
public void Heal(float amount) => SetHealth(currentHealth + amount);
|
||||
|
||||
// 处理单位死亡:隐藏模型和血条,播放蓝色向上爆散特效。
|
||||
private void Die()
|
||||
{
|
||||
isDead = true;
|
||||
currentHealth = 0f;
|
||||
UpdateFill();
|
||||
|
||||
foreach (Renderer renderer in GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
renderer.enabled = false;
|
||||
}
|
||||
|
||||
// 立即从敌我扫描中移除,避免死亡等待期间继续被攻击。
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (barRect != null)
|
||||
{
|
||||
barRect.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
GameObject effect = CreateDeathEffect();
|
||||
Destroy(effect, deathEffectDuration);
|
||||
Destroy(gameObject, deathEffectDuration);
|
||||
}
|
||||
|
||||
// 创建蓝色粒子爆散特效。
|
||||
private GameObject CreateDeathEffect()
|
||||
{
|
||||
GameObject effect = new GameObject("DeathEffect");
|
||||
effect.transform.position = transform.position + Vector3.up * 1.35f;
|
||||
|
||||
ParticleSystem particles = effect.AddComponent<ParticleSystem>();
|
||||
particles.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
|
||||
var main = particles.main;
|
||||
main.playOnAwake = false;
|
||||
main.duration = deathEffectDuration;
|
||||
main.startLifetime = new ParticleSystem.MinMaxCurve(0.9f, deathEffectDuration);
|
||||
main.startSpeed = new ParticleSystem.MinMaxCurve(0.05f, 0.18f);
|
||||
main.startSize = new ParticleSystem.MinMaxCurve(0.09f, 0.2f);
|
||||
main.startRotation3D = true;
|
||||
main.startRotationX = new ParticleSystem.MinMaxCurve(0f, 6.28f);
|
||||
main.startRotationY = new ParticleSystem.MinMaxCurve(0f, 6.28f);
|
||||
main.startRotationZ = new ParticleSystem.MinMaxCurve(0f, 6.28f);
|
||||
main.startColor = deathEffectColor;
|
||||
main.maxParticles = 32;
|
||||
main.gravityModifier = new ParticleSystem.MinMaxCurve(1.6f);
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
main.stopAction = ParticleSystemStopAction.None;
|
||||
|
||||
var emission = particles.emission;
|
||||
emission.rateOverTime = 0f;
|
||||
emission.SetBursts(new[] { new ParticleSystem.Burst(0f, 18) });
|
||||
|
||||
var shape = particles.shape;
|
||||
shape.shapeType = ParticleSystemShapeType.Sphere;
|
||||
shape.radius = 0.12f;
|
||||
|
||||
// 只保留轻微水平散落,主要依靠重力向下坠落。
|
||||
var velocity = particles.velocityOverLifetime;
|
||||
velocity.enabled = true;
|
||||
velocity.space = ParticleSystemSimulationSpace.World;
|
||||
velocity.x = new ParticleSystem.MinMaxCurve(-0.08f, 0.08f);
|
||||
velocity.y = new ParticleSystem.MinMaxCurve(-0.25f, -0.05f);
|
||||
velocity.z = new ParticleSystem.MinMaxCurve(-0.08f, 0.08f);
|
||||
|
||||
var collision = particles.collision;
|
||||
collision.enabled = true;
|
||||
collision.type = ParticleSystemCollisionType.World;
|
||||
collision.mode = ParticleSystemCollisionMode.Collision3D;
|
||||
collision.bounce = 0f;
|
||||
collision.lifetimeLoss = 0.15f;
|
||||
|
||||
var size = particles.sizeOverLifetime;
|
||||
size.enabled = true;
|
||||
AnimationCurve fade = new AnimationCurve(
|
||||
new Keyframe(0f, 1f),
|
||||
new Keyframe(0.75f, 1f),
|
||||
new Keyframe(1f, 0f));
|
||||
size.size = new ParticleSystem.MinMaxCurve(1f, fade);
|
||||
|
||||
var renderer = effect.GetComponent<ParticleSystemRenderer>();
|
||||
renderer.renderMode = ParticleSystemRenderMode.Mesh;
|
||||
renderer.mesh = CreateCrystalMesh();
|
||||
renderer.material = CreateParticleMaterial();
|
||||
particles.Play();
|
||||
return effect;
|
||||
}
|
||||
|
||||
// 创建低模菱形水晶碎片 Mesh。
|
||||
private Mesh CreateCrystalMesh()
|
||||
{
|
||||
Mesh mesh = new Mesh { name = "DeathCrystal" };
|
||||
mesh.vertices = new[]
|
||||
{
|
||||
new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 0f, 0f),
|
||||
new Vector3(0f, 0f, 0.5f), new Vector3(-0.5f, 0f, 0f),
|
||||
new Vector3(0f, 0f, -0.5f), new Vector3(0f, -0.5f, 0f)
|
||||
};
|
||||
mesh.triangles = new[]
|
||||
{
|
||||
0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1,
|
||||
5, 2, 1, 5, 3, 2, 5, 4, 3, 5, 1, 4
|
||||
};
|
||||
mesh.RecalculateNormals();
|
||||
mesh.RecalculateBounds();
|
||||
return mesh;
|
||||
}
|
||||
|
||||
// 创建带浅蓝发光效果的水晶材质。
|
||||
private Material CreateParticleMaterial()
|
||||
{
|
||||
Shader shader = Shader.Find("Standard");
|
||||
Material material = new Material(shader);
|
||||
material.color = deathEffectColor;
|
||||
material.SetFloat("_Metallic", 0.15f);
|
||||
material.SetFloat("_Glossiness", 0.85f);
|
||||
material.SetColor("_EmissionColor", deathEffectColor * 1.6f);
|
||||
material.EnableKeyword("_EMISSION");
|
||||
return material;
|
||||
}
|
||||
|
||||
// 根据单位模型或碰撞体计算血条位置和宽度。
|
||||
private void CalculateLayout()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user