``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 地面裂纹特效控制器
|
|
/// 挂在平躺的 Quad 上,砸地/劈砍命中时调用 Play()
|
|
/// 流程:扩散(0→1) → 保持 → 淡出 → 结束
|
|
/// </summary>
|
|
[RequireComponent(typeof(Renderer))]
|
|
public class GroundCrack : MonoBehaviour
|
|
{
|
|
[Header("时间")]
|
|
public float spreadTime = 0.3f; // 裂纹扩散时间
|
|
public float holdTime = 0.8f; // 保持时间
|
|
public float fadeTime = 0.6f; // 淡出时间
|
|
|
|
[Header("外观")]
|
|
public Color crackColor = Color.black; // 裂纹颜色(黑=普通地裂,红=熔岩,紫=暗影)
|
|
public Color glowColor = new Color(1f, 0.3f, 0f, 0f); // 发光色(A=0不发光)
|
|
|
|
[Header("测试")]
|
|
public bool autoPlayOnStart = true;
|
|
|
|
private Material mat;
|
|
private float timer;
|
|
private int state; // 0=扩散 1=保持 2=淡出 3=结束
|
|
private bool initialized;
|
|
|
|
void Start()
|
|
{
|
|
Init();
|
|
if (autoPlayOnStart) Play();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
if (initialized) return;
|
|
mat = GetComponent<Renderer>().material;
|
|
mat.SetFloat("_Progress", 0f);
|
|
mat.SetFloat("_Opacity", 0f);
|
|
initialized = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 砸地/劈砍命中时调用
|
|
/// </summary>
|
|
[ContextMenu("▶ 播放一次")]
|
|
public void Play()
|
|
{
|
|
Init();
|
|
timer = 0f;
|
|
state = 0;
|
|
mat.SetFloat("_Opacity", 1f);
|
|
mat.SetFloat("_Progress", 0f);
|
|
mat.SetColor("_CrackColor", crackColor);
|
|
mat.SetColor("_GlowColor", glowColor);
|
|
Debug.Log("[GroundCrack] 裂纹触发");
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (state >= 3) return;
|
|
|
|
timer += Time.deltaTime;
|
|
|
|
if (state == 0) // 扩散
|
|
{
|
|
float p = Mathf.Clamp01(timer / spreadTime);
|
|
mat.SetFloat("_Progress", p);
|
|
if (timer >= spreadTime) { state = 1; timer = 0f; }
|
|
}
|
|
else if (state == 1) // 保持
|
|
{
|
|
if (timer >= holdTime) { state = 2; timer = 0f; }
|
|
}
|
|
else if (state == 2) // 淡出
|
|
{
|
|
float f = 1f - Mathf.Clamp01(timer / fadeTime);
|
|
mat.SetFloat("_Opacity", f);
|
|
if (timer >= fadeTime)
|
|
{
|
|
state = 3;
|
|
mat.SetFloat("_Opacity", 0f);
|
|
Debug.Log("[GroundCrack] 裂纹结束");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//(注:内容由AI生成)
|