提交存档
This commit is contained in:
+426
-11946
File diff suppressed because it is too large
Load Diff
@@ -175,6 +175,13 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
|
||||
|
||||
private List<CollisionEffect> collisionEffects = new List<CollisionEffect>();
|
||||
|
||||
// 涟漪效果相关常量
|
||||
private const float RIPPLE_SPREAD_FACTOR = 0.3f;
|
||||
private const float RIPPLE_DISTANCE_FACTOR = 2f;
|
||||
private const float RIPPLE_BRIGHTNESS_MULTIPLIER = 1.5f;
|
||||
private const float RIPPLE_TIME_FACTOR = 0.5f;
|
||||
private const float RIPPLE_EASE_FACTOR = 0.5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 添加按钮点击事件监听
|
||||
@@ -361,6 +368,18 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
|
||||
UpdateTargetVisibility();
|
||||
CleanExpiredTargetTriggerRipples();
|
||||
UpdateFloatingTexts(); // 添加更新文字效果
|
||||
|
||||
// 检查所有涟漪的碰撞
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
float currentTime = Time.time;
|
||||
foreach (var ripple in ripples)
|
||||
{
|
||||
float elapsed = currentTime - ripple.startTime;
|
||||
float spread = elapsed * rippleSpreadSpeed;
|
||||
CheckRippleCollisions(ripple.position, spread, currentTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleMouseInput()
|
||||
@@ -432,101 +451,67 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
|
||||
ref float rippleOffset, ref float brightness, ref Color targetColor,
|
||||
ref float maxTargetInfluence, ref float shapeDistortion, bool isTargetTrigger = false)
|
||||
{
|
||||
if (ripple == null) return;
|
||||
|
||||
// 计算基础参数
|
||||
float elapsed = currentTime - ripple.startTime;
|
||||
float spread = elapsed * (isTargetTrigger ? targetTriggerSpreadSpeed : rippleSpreadSpeed);
|
||||
float spreadSpeed = isTargetTrigger ? targetTriggerSpreadSpeed : rippleSpreadSpeed;
|
||||
float spread = elapsed * spreadSpeed;
|
||||
float dist = Vector2.Distance(new Vector2(x, z), ripple.position);
|
||||
|
||||
// 使用平滑的衰减函数,不再使用硬性限制
|
||||
float maxRadius = rippleMaxRadius; // 使用原始最大半径
|
||||
float t = Mathf.Clamp01(elapsed / (isTargetTrigger ? targetTriggerDuration : rippleDuration));
|
||||
// 计算时间相关参数
|
||||
float duration = isTargetTrigger ? targetTriggerDuration : rippleDuration;
|
||||
float t = Mathf.Clamp01(elapsed / duration);
|
||||
float fadeT = Mathf.Clamp01((t - rippleFadeStartTime) / (1f - rippleFadeStartTime));
|
||||
float fadeCurve = Mathf.Pow(1f - fadeT, rippleFadeCurve);
|
||||
|
||||
// 使用更平滑的缓动函数,但保持初始强度
|
||||
float ease = Mathf.SmoothStep(0, 1, Mathf.Sin(t * Mathf.PI * 0.5f)) * fadeCurve;
|
||||
|
||||
// 计算统一的衰减因子
|
||||
float distanceFactor = Mathf.Exp(-Mathf.Pow(dist / maxRadius, 2f) * 2f);
|
||||
float spreadFactor = Mathf.Exp(-Mathf.Pow((dist - spread) / (maxRadius * 0.3f), 2f) * rippleSharpness * (1f - t * 0.5f));
|
||||
float finalFactor = distanceFactor * spreadFactor;
|
||||
|
||||
|
||||
// 计算缓动效果
|
||||
float ease = CalculateEase(t, fadeCurve);
|
||||
|
||||
// 计算效果因子
|
||||
float finalFactor = CalculateEffectFactor(dist, spread, t);
|
||||
|
||||
// 应用涟漪效果
|
||||
rippleOffset += finalFactor * (isTargetTrigger ? targetTriggerStrength : rippleStrength) * ease;
|
||||
brightness += finalFactor * ease * 1.5f;
|
||||
|
||||
if (CheckObstacleCollision(ripple.position, spread, currentTime))
|
||||
return;
|
||||
|
||||
// 计算当前点与所有目标的距离,找到最近的目标
|
||||
float minTargetDist = float.MaxValue;
|
||||
Color nearestTargetColor = Color.white;
|
||||
float nearestTargetInfluence = 0f;
|
||||
|
||||
foreach (var target in targetPoints)
|
||||
{
|
||||
float step = fieldSize / (pointCount - 1);
|
||||
float halfField = fieldSize * 0.5f;
|
||||
float targetX = -halfField + target.gridPosition.x * step + fieldOffset.x;
|
||||
float targetZ = -halfField + target.gridPosition.y * step + fieldOffset.y;
|
||||
float targetDist = Vector2.Distance(new Vector2(x, z), new Vector2(targetX, targetZ));
|
||||
|
||||
// 使用完全相同的衰减计算方式
|
||||
float targetDistanceFactor = Mathf.Exp(-Mathf.Pow(targetDist / maxRadius, 2f) * 2f);
|
||||
float targetSpreadFactor = Mathf.Exp(-Mathf.Pow((targetDist - spread) / (maxRadius * 0.3f), 2f) * rippleSharpness * (1f - t * 0.5f));
|
||||
float targetInfluence = targetDistanceFactor * targetSpreadFactor;
|
||||
|
||||
// 更新最近的目标信息
|
||||
if (targetInfluence > nearestTargetInfluence)
|
||||
{
|
||||
nearestTargetInfluence = targetInfluence;
|
||||
nearestTargetColor = target.color;
|
||||
minTargetDist = targetDist;
|
||||
}
|
||||
|
||||
// 检查涟漪是否触碰到目标
|
||||
if (!isTargetTrigger && targetDist < 0.5f && target.lastTriggerTime < currentTime - targetTriggerDuration)
|
||||
{
|
||||
// 确保目标点之前没有被触发过
|
||||
if (target.lastTriggerTime <= 0)
|
||||
{
|
||||
target.lastTriggerTime = currentTime;
|
||||
target.isFound = true;
|
||||
target.visibility = 0.2f; // 初始可见度
|
||||
targetTriggerRipples.Add(new Ripple
|
||||
{
|
||||
position = new Vector2(targetX, targetZ),
|
||||
startTime = currentTime
|
||||
});
|
||||
|
||||
if (targetButtons.ContainsKey(target))
|
||||
{
|
||||
targetButtons[target].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
Vector3 textPosition = new Vector3(targetX, GetHeight(targetX - fieldOffset.x, targetZ - fieldOffset.y, time) + targetHeightOffset, targetZ);
|
||||
CreateFloatingText(textPosition, target.name, target.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据最近目标的影响程度,计算颜色过渡
|
||||
if (nearestTargetInfluence > 0)
|
||||
{
|
||||
// 使用目标影响程度来混合颜色,并考虑涟漪的衰减
|
||||
float colorBlend = nearestTargetInfluence * (1f - fadeT) * targetColorInfluenceStrength;
|
||||
targetColor = Color.Lerp(targetColor, nearestTargetColor, colorBlend);
|
||||
}
|
||||
float strength = isTargetTrigger ? targetTriggerStrength : rippleStrength;
|
||||
ApplyRippleEffect(finalFactor, ease, strength, ref rippleOffset, ref brightness);
|
||||
}
|
||||
|
||||
private bool CheckObstacleCollision(Vector2 ripplePos, float spread, float currentTime)
|
||||
private float CalculateEase(float t, float fadeCurve)
|
||||
{
|
||||
return Mathf.SmoothStep(0, 1, Mathf.Sin(t * Mathf.PI * RIPPLE_EASE_FACTOR)) * fadeCurve;
|
||||
}
|
||||
|
||||
private float CalculateEffectFactor(float dist, float spread, float t)
|
||||
{
|
||||
float maxRadius = rippleMaxRadius;
|
||||
float distRatio = dist / maxRadius;
|
||||
float spreadRatio = (dist - spread) / (maxRadius * RIPPLE_SPREAD_FACTOR);
|
||||
float timeFactor = 1f - t * RIPPLE_TIME_FACTOR;
|
||||
|
||||
// 计算距离衰减
|
||||
float distanceFactor = Mathf.Exp(-distRatio * distRatio * RIPPLE_DISTANCE_FACTOR);
|
||||
|
||||
// 计算扩散衰减
|
||||
float spreadFactor = Mathf.Exp(-spreadRatio * spreadRatio * rippleSharpness * timeFactor);
|
||||
|
||||
return distanceFactor * spreadFactor;
|
||||
}
|
||||
|
||||
private void ApplyRippleEffect(float finalFactor, float ease, float strength,
|
||||
ref float rippleOffset, ref float brightness)
|
||||
{
|
||||
rippleOffset += finalFactor * strength * ease;
|
||||
brightness += finalFactor * ease * RIPPLE_BRIGHTNESS_MULTIPLIER;
|
||||
}
|
||||
|
||||
private void CheckRippleCollisions(Vector2 ripplePos, float spread, float currentTime)
|
||||
{
|
||||
float step = fieldSize / (pointCount - 1);
|
||||
float halfField = fieldSize * 0.5f;
|
||||
bool collisionOccurred = false;
|
||||
|
||||
// 检查障碍物碰撞
|
||||
foreach (var obstacle in obstacles)
|
||||
{
|
||||
// 将网格位置转换为世界坐标
|
||||
float x = -halfField + obstacle.gridPosition.x * step + fieldOffset.x;
|
||||
float z = -halfField + obstacle.gridPosition.y * step + fieldOffset.y;
|
||||
Vector2 worldPos = new Vector2(x, z);
|
||||
@@ -560,11 +545,41 @@ public class LakeLineDrawer : ImmediateModeShapeDrawer
|
||||
CreateFloatingText(textPosition, obstacle.displayText, obstacleColor);
|
||||
obstacle.lastTextTime = currentTime;
|
||||
}
|
||||
|
||||
return true; // 碰撞发生
|
||||
}
|
||||
}
|
||||
return false; // 没有碰撞发生
|
||||
|
||||
// 检查目标碰撞
|
||||
foreach (var target in targetPoints)
|
||||
{
|
||||
float x = -halfField + target.gridPosition.x * step + fieldOffset.x;
|
||||
float z = -halfField + target.gridPosition.y * step + fieldOffset.y;
|
||||
Vector2 worldPos = new Vector2(x, z);
|
||||
|
||||
float dist = Vector2.Distance(ripplePos, worldPos);
|
||||
if (dist <= rippleMaxRadius && Mathf.Abs(dist - spread) < 0.5f && target.lastTriggerTime < currentTime - targetTriggerDuration)
|
||||
{
|
||||
// 确保目标点之前没有被触发过
|
||||
if (target.lastTriggerTime <= 0)
|
||||
{
|
||||
target.lastTriggerTime = currentTime;
|
||||
target.isFound = true;
|
||||
target.visibility = 0.2f; // 初始可见度
|
||||
targetTriggerRipples.Add(new Ripple
|
||||
{
|
||||
position = worldPos,
|
||||
startTime = currentTime
|
||||
});
|
||||
|
||||
if (targetButtons.ContainsKey(target))
|
||||
{
|
||||
targetButtons[target].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
Vector3 textPosition = new Vector3(x, GetHeight(x - fieldOffset.x, z - fieldOffset.y, time) + targetHeightOffset, z);
|
||||
CreateFloatingText(textPosition, target.name, target.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改GetHeight方法,使波浪更自然
|
||||
|
||||
Reference in New Issue
Block a user