feat(cable): 线缆暖色配色与拉紧驱动线盘转动

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-21 22:16:41 +08:00
co-authored by Cursor
parent 74f5989802
commit 6159704116
5 changed files with 75 additions and 48 deletions
@@ -285,7 +285,8 @@ namespace AibisDream.FixSystem
{
heatMapController.ShowHeatMap();
DisableSystem();
FixPanelSystem.GetRepairPanel<CablePanel>().ResetPlug();
// 散热期间收起插头,避免插线状态与热力图交互冲突
FixPanelSystem.GetRepairPanel<CablePanel>().PullUpCable();
}
public void HideHeatMap()
@@ -7,6 +7,8 @@ namespace AibisDream.FixSystem
[Header("转盘设置")]
[SerializeField] private float torqueStrength = 200f; // 扭矩强度
[SerializeField] private float angularDamping = 5f; // 角速度阻尼
[SerializeField] private float maxHalfAngle = 60f; // 单侧最大转角(总范围约 2× 此值 ≈ 120°)
[SerializeField] private float returnSpeed = 4f; // 闲置回正速度
private CablePanel cablePanel;
private float angularVelocity; // 角速度
@@ -61,42 +63,48 @@ namespace AibisDream.FixSystem
}
/// <summary>拖拽/插接中朝拉力方向施加扭矩;闲置时缓动回正。</summary>
public void UpdateRotation(bool active)
public void UpdateRotation(bool active, float tautness = 1f)
{
if (cablePanel == null || cablePanel.PlugRef == null) return;
if (!active)
{
angularVelocity = 0f;
currentAngle = Mathf.LerpAngle(currentAngle, 0f, 4f * Time.deltaTime);
transform.rotation = Quaternion.Euler(0, 0, currentAngle);
UpdateOutletPosition();
currentAngle = Mathf.LerpAngle(currentAngle, 0f, returnSpeed * Time.deltaTime);
ApplyRotation();
return;
}
// 线缆还有余量时不驱动转盘,避免"还没拉紧就先转"
if (tautness <= 0f)
{
angularVelocity *= Mathf.Exp(-angularDamping * Time.deltaTime);
ApplyRotation();
return;
}
Vector2 center = transform.position;
// 使用当前出线口位置
Vector2 outlet = outletPos;
// 力向量(线缆拉力方向)
Vector2 force = (Vector2)cablePanel.PlugRef.transform.position - outlet;
// 杆臂向量(力作用点相对于圆心的位置)
Vector2 r = outlet - center;
// 计算 2D 扭矩:r × F
float torque = (r.x * force.y - r.y * force.x);
// 应用扭矩 + 阻尼
float torque = (r.x * force.y - r.y * force.x) * tautness;
angularVelocity += torque * torqueStrength * Time.deltaTime;
angularVelocity *= Mathf.Exp(-angularDamping * Time.deltaTime); // 简易阻尼
// 应用旋转
angularVelocity *= Mathf.Exp(-angularDamping * Time.deltaTime);
currentAngle += angularVelocity * Time.deltaTime;
currentAngle = Mathf.Clamp(currentAngle, -maxHalfAngle, maxHalfAngle);
if (currentAngle <= -maxHalfAngle && angularVelocity < 0f) angularVelocity = 0f;
if (currentAngle >= maxHalfAngle && angularVelocity > 0f) angularVelocity = 0f;
ApplyRotation();
}
private void ApplyRotation()
{
transform.rotation = Quaternion.Euler(0, 0, currentAngle);
// 更新出线口位置
UpdateOutletPosition();
}
}