插线提交

This commit is contained in:
2025-05-30 17:47:02 +08:00
parent 73fd121052
commit 64ac24ca5e
4 changed files with 974 additions and 831 deletions
@@ -1,4 +1,6 @@
using UnityEngine;
using DG.Tweening;
using System;
namespace AibisDream.FixSystem
{
@@ -18,15 +20,21 @@ namespace AibisDream.FixSystem
#endregion
#region
public bool isInDialog;
public bool isActive = true;
public bool isCableRetracted = true; // 线缆是否收起
[SerializeField] private Transform retractedPos; // 收起位置
[SerializeField] private float dropDownDuration = 0.5f; // 放下动画时长
[SerializeField] private float swingDuration = 0.3f; // 摆动动画时长
[SerializeField] private float swingAngle = 15f; // 摆动角度
[HideInInspector] public ISocket curSocket;
[HideInInspector] public BodyModule curBodyModule;
#endregion
private void Awake()
{
InitComponentRefs();
@@ -62,8 +70,14 @@ namespace AibisDream.FixSystem
private void InitSystem()
{
// 初始状态Plug垂下
PlugRef.InitPlug();
if (isCableRetracted)
{
SetRetractCable();
}
else
{
PlugRef.ReturnToStartPosition();
}
}
private void Update()
@@ -73,10 +87,22 @@ namespace AibisDream.FixSystem
{
CableReelRef.UpdateRotation();
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (isCableRetracted)
{
DropDownCable();
}
else
{
PullUpCable();
}
}
}
public void ResetPlug()
{
Debug.Log("ResetPlug");
// 不在初始插孔里,就从当前插孔拔出来,插回初始插孔
PlugRef.PullUpSocket();
PlugRef.ReturnToStartPosition();
@@ -104,7 +130,7 @@ namespace AibisDream.FixSystem
{
isInDialog = false;
}
public void Disable_plugInput()
{
isActive = false;
@@ -125,5 +151,46 @@ namespace AibisDream.FixSystem
}
#endregion
public void PullUpCable()
{
if (isCableRetracted) return;
//禁用plug交互
Disable_plugInput();
ResetPlug();
PlugRef.SetPhysicCableActive(false);
PlugRef.GetComponent<SpriteRenderer>().sortingLayerName = CableReelRef.GetComponent<SpriteRenderer>().sortingLayerName;
PlugRef.GetComponent<SpriteRenderer>().sortingOrder = 41;
PlugRef.transform.DOMove(retractedPos.position, 0.1f).OnComplete(() =>
{
PhysicCableRef.GetComponent<LineRenderer>().enabled = false;
isCableRetracted = true;
});
}
public void DropDownCable()
{
if (!isCableRetracted) return;
PlugRef.PullUpSocket();
CableReelRef.ResetRotation();
PlugRef.transform.DOMove(PlugRef.GetStartPos(), 0.1f).OnComplete(() =>
{
PlugRef.SwitchToPhysicCableState();
isCableRetracted = false;
});
// 只有在非收起状态时才切换到物理线缆状态
}
public void SetRetractCable()
{
// 禁用物理线缆和普通线缆
PhysicCableRef.GetComponent<LineRenderer>().enabled = false;
CableRef.GetComponent<LineRenderer>().enabled = false;
// 设置Plug位置和层级
PlugRef.transform.position = retractedPos.position;
PlugRef.transform.rotation = retractedPos.rotation;
PlugRef.GetComponent<SpriteRenderer>().sortingLayerName = CableReelRef.GetComponent<SpriteRenderer>().sortingLayerName;
PlugRef.GetComponent<SpriteRenderer>().sortingOrder = 41;
}
}
}