fix(fix-system): 修复线盘底座旋转未生效

This commit is contained in:
2026-07-26 13:04:50 +08:00
parent 6eaa4545bb
commit cd1fbe4e02
3 changed files with 24 additions and 7 deletions
@@ -21,6 +21,9 @@ namespace AibisDream.FixSystem
{
// 获取CablePanel引用
cablePanel = transform.GetComponentInParent<CablePanel>();
// 兼容尚未重新保存的旧场景/预制体:新增序列化字段缺失时仍使用设计默认值。
if (maxHalfAngle <= 0f) maxHalfAngle = 60f;
if (returnSpeed <= 0f) returnSpeed = 4f;
currentAngle = transform.eulerAngles.z;
// 获取SpriteRenderer并计算半径
@@ -62,10 +65,24 @@ namespace AibisDream.FixSystem
UpdateRotation(true);
}
/// <summary>
/// 供旧 CableSystem 使用:以插头位置驱动线盘,并在收线时缓动回正。
/// </summary>
public void UpdateRotation(Transform plugTransform, bool active)
{
UpdateRotation(plugTransform, active, 1f);
}
/// <summary>拖拽/插接中朝拉力方向施加扭矩;闲置时缓动回正。</summary>
public void UpdateRotation(bool active, float tautness = 1f)
{
if (cablePanel == null || cablePanel.PlugRef == null) return;
UpdateRotation(cablePanel.PlugRef.transform, active, tautness);
}
private void UpdateRotation(Transform plugTransform, bool active, float tautness)
{
if (plugTransform == null) return;
if (!active)
{
@@ -85,7 +102,7 @@ namespace AibisDream.FixSystem
Vector2 center = transform.position;
Vector2 outlet = outletPos;
Vector2 force = (Vector2)cablePanel.PlugRef.transform.position - outlet;
Vector2 force = (Vector2)plugTransform.position - outlet;
Vector2 r = outlet - center;
float torque = (r.x * force.y - r.y * force.x) * tautness;
@@ -108,4 +125,4 @@ namespace AibisDream.FixSystem
UpdateOutletPosition();
}
}
}
}
@@ -98,10 +98,10 @@ namespace AibisDream.FixSystem
private void Update()
{
// 获取线缆方向并更新转盘旋转
// 以正下方为中心驱动线盘旋转;CableReel 内部限制为左右各 60°。
if (CableRef != null && CableReelRef != null)
{
CableReelRef.UpdateRotation();
CableReelRef.UpdateRotation(PlugRef != null ? PlugRef.transform : null, !isCableRetracted);
}
}