fix(fix-system): 修复线盘底座旋转未生效
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,14 +196,14 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 拖拽/插接时转盘朝拉力方向转动,闲置时缓动回正
|
||||
// 拖拽/插接时转盘朝插头方向转动,闲置时缓动回正。
|
||||
// 不再要求线缆完全绷紧,否则送线会让 tautness 长时间为 0,视觉上看不到旋转。
|
||||
if (CableReelRef != null && physicCableRef != null
|
||||
&& physicCableRef.State != PhysicCable.CableState.Hidden)
|
||||
{
|
||||
bool active = physicCableRef.State == PhysicCable.CableState.Dragging
|
||||
|| physicCableRef.State == PhysicCable.CableState.Plugged;
|
||||
float tautness = active ? physicCableRef.GetTautness() : 0f;
|
||||
CableReelRef.UpdateRotation(active, tautness);
|
||||
CableReelRef.UpdateRotation(active);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user