This commit is contained in:
2025-05-08 19:41:02 +08:00
parent e461982627
commit 3a1ac08c14
@@ -111,7 +111,6 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
private struct CollisionEffect
{
public Vector2 position;
public Vector2 direction; // 撞击方向
public float startTime;
}
@@ -293,13 +292,9 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
obstacle.riseProgress = Mathf.Max(obstacle.riseProgress, obstacle.visibility);
}
// 计算撞击方向(从涟漪中心指向障碍物)
Vector2 hitDirection = (worldPos - ripplePos).normalized;
collisionEffects.Add(new CollisionEffect
{
position = worldPos,
direction = hitDirection,
startTime = currentTime
});
}
@@ -639,21 +634,22 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
float elapsed = Time.time - effect.startTime;
float t = elapsed / collisionEffectDuration;
// 计算当前效果的大小和透明度
float scale = Mathf.Lerp(0f, collisionEffectSize, t);
float alpha = Mathf.Lerp(1f, 0f, t);
Color effectColor = collisionEffectColor;
effectColor.a *= alpha;
// 使用效果位置的世界坐标
// 计算效果位置
Vector3 effectPos = new Vector3(effect.position.x,
GetHeight(effect.position.x, effect.position.y, time),
GetHeight(effect.position.x - fieldOffset.x, effect.position.y - fieldOffset.y, time),
effect.position.y);
// 设置虚线样式
Draw.UseDashes = true;
Draw.DashStyle = DashStyle.RelativeDashes(DashType.Basic, 0.5f, 0.5f, DashSnapping.Tiling, 0f, 0f);
// 绘制同心圆涟漪,但根据撞击方向调整形状
// 绘制同心圆涟漪
for (int i = 0; i < collisionEffectRingCount; i++)
{
float ringScale = scale * (i + 1) / collisionEffectRingCount;
@@ -661,30 +657,8 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
Color ringColor = effectColor;
ringColor.a *= ringAlpha;
// 计算椭圆的长轴和短轴
float majorAxis = ringScale;
float minorAxis = ringScale * 0.7f; // 短轴略短,形成椭圆
// 计算旋转角度(使长轴与撞击方向对齐)
float angle = Mathf.Atan2(effect.direction.y, effect.direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.Euler(0, angle, 0);
// 绘制椭圆环
int segments = 32;
Vector3 prevPoint = Vector3.zero;
for (int j = 0; j <= segments; j++)
{
float angle2 = (float)j / segments * Mathf.PI * 2;
float x = Mathf.Cos(angle2) * majorAxis;
float z = Mathf.Sin(angle2) * minorAxis;
Vector3 point = rotation * new Vector3(x, 0, z) + effectPos;
if (j > 0)
{
Draw.Line(prevPoint, point, lineWidth * (1f - t), ringColor);
}
prevPoint = point;
}
// 使用Shapes的Ring方法绘制虚线圆环
Draw.Ring(effectPos, Vector3.up, ringScale, lineWidth * (1f - t), ringColor);
}
// 恢复默认样式
@@ -706,6 +680,15 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
continue;
}
// 在游戏模式下,如果从未被涟漪影响过,保持不可见
if (obstacle.lastRippleTime <= 0f)
{
obstacle.visibility = 0f;
obstacle.riseProgress = 0f;
obstacle.colorFadeProgress = 0f;
continue;
}
// 如果超过6秒没有被涟漪影响,开始逐渐消失
if (currentTime - obstacle.lastRippleTime > 6f)
{