插头修改提交

This commit is contained in:
2025-02-19 17:25:37 +08:00
parent 722a3013ab
commit 430ab63f5c
8 changed files with 292 additions and 49 deletions
@@ -67,7 +67,7 @@ namespace AibisDream.FixSystem
float t = Mathf.InverseLerp(config.dstMin, config.dstMax, (_start.position - _end.position).magnitude);
float F = Mathf.Lerp(config.forceMin, config.forceMax, t);
_points[0] = _start.position;
_points[^1] = _end.GetChild(0).position;
_points[^1] = _end.position;
for (int ik = 0; ik < config.k; ik++)
{
for (int i = 1; i < _points.Length - 1; i++)
@@ -67,8 +67,9 @@ namespace AibisDream.FixSystem
private void InitSystem()
{
//PlugRef.InitPlug(InitSocket);
PhysicCableRef.Init();
//PhysicCableRef.Init();
PlugRef.InitPlug(InitSocket);
}
public void Update()
{
@@ -81,7 +82,7 @@ namespace AibisDream.FixSystem
if (curSocket == InitSocket) return;
// 不在初始插孔里,就从当前插孔拔出来,插回初始插孔
PlugRef.PullUpSocket();
PlugRef.InsertSocket(InitSocket);
PlugRef.ReturnToStartPosition();
}
/// <summary>
+49 -12
View File
@@ -13,10 +13,12 @@ namespace AibisDream.FixSystem
#region
private Vector3 _startPos;
private Vector3 _startRotate;
private readonly Vector3 _pickupOffset = new(0, 0, 0);
private readonly Quaternion _pickupRotationOffset = Quaternion.Euler(0, 0, 30);
private readonly Quaternion initRotation = Quaternion.Euler(0, 0, 180);
#endregion
#region
@@ -29,11 +31,13 @@ namespace AibisDream.FixSystem
#endregion
private bool _isDragging;
private bool _isPhysicCableActive=false;
private void Awake()
{
InitComponentRef();
EventRegister();
_startPos = transform.position; // 初始化时记录初始位置
}
private void InitComponentRef()
@@ -53,14 +57,9 @@ namespace AibisDream.FixSystem
public void InitPlug(ISocket initSocket)
{
//InsertSocket(initSocket);
ReturnToStartPosition();
}
public void Update()
{
//_cableSystem.PhysicCableRef.physicLine.UpdateEndPoint(this.transform);
_cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform);
}
/// <summary>
/// 插入某个socket
@@ -129,11 +128,17 @@ namespace AibisDream.FixSystem
// 开启拖拽
_isDragging = true;
// 进行插拔动作
if (_cableSystem.curSocket != null) PullUpSocket();
// 调整插头形状
AdjustPlugPos();
// 关闭 PhysicCable 的更新,并显示 Cable 的 LineRenderer
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = false;
_isPhysicCableActive = false;
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = true;
}
private void OnPointerUp(BaseEventData eventData)
@@ -149,19 +154,51 @@ namespace AibisDream.FixSystem
}
else
{
// 没找到就插回初始Socket,需要播动画
// transform.DOMove(_cableSystem.InitSocket.GetSocketPos(), 0.1f).OnComplete(() =>
// {
// InsertSocket(_cableSystem.InitSocket);
// });
// 没找到就插回初始位置
ReturnToStartPosition();
}
}
public void ReturnToStartPosition()
{
transform.DOMove(_startPos, 0.1f).OnComplete(() =>
{
SwitchToPhysicCableState();
});
}
private void AdjustPlugPos()
{
transform.position += _pickupOffset;
transform.rotation = _pickupRotationOffset;
}
private void PlugPosBack()
{
transform.position -= _pickupOffset;
transform.rotation = initRotation;
}
private void SwitchToPhysicCableState()
{
// 隐藏 Cable 的 LineRenderer
PlugPosBack();
_cableSystem.PhysicCableRef.Init(transform.position);
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = false;
// 激活 PhysicCable
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = true;
_isPhysicCableActive = true;
}
private void Update()
{
if (_isPhysicCableActive)
{
_cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform);
}
}
void OnDrawGizmosSelected()
{