插线提交

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;
}
}
}
+57 -18
View File
@@ -16,9 +16,10 @@ namespace AibisDream.FixSystem
#region
private Vector3 _startPos;
private Vector3 _RetractedPos;
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
@@ -38,8 +39,9 @@ namespace AibisDream.FixSystem
private void Awake()
{
InitComponentRef();
EventRegister();
_startPos = transform.position; // 初始化时记录初始位置
EventRegister();
_RetractedPos = transform.position;
_startPos = new Vector3(transform.position.x+0.3f, transform.position.y - 2f, transform.position.z); // 初始化时记录初始位置
}
private void InitComponentRef()
@@ -60,10 +62,17 @@ namespace AibisDream.FixSystem
_trigger.Register(EventTriggerType.PointerUp, OnPointerUp);
}
public void InitPlug()
{
ReturnToStartPosition();
}
// public void InitPlug()
// {
// if (_cableSystem.isCableRetracted)
// {
// _cableSystem.RetractCable();
// }
// else
// {
// ReturnToStartPosition();
// }
// }
/// <summary>
/// 插入某个socket
@@ -127,20 +136,23 @@ namespace AibisDream.FixSystem
private void OnPointerDown(BaseEventData eventData)
{
GetComponent<SpriteRenderer>().sortingLayerName = "Tools";
GetComponent<SpriteRenderer>().sortingOrder = 48;
// 系统被锁定就返回
if (!_cableSystem.IsPlugAvailable()) return;
// 如果线缆是收起状态,先放下
if (_cableSystem.isCableRetracted)
{
_cableSystem.DropDownCable();
return;
}
// 首次拖拽后关闭高亮
if (GlobalVariableKit.IsPlugHighLight)
{
GlobalVariableKit.IsPlugHighLight = false;
_sprite.material.SetFloat(ShineFade, 0);
// 拖拽后还要高亮其他组件
// var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
// foreach (var module in bodyModuleSystem.BodyModules)
// {
// module.Highlight(true);
// }
DialogController.Instance.StartDialogNode("拿起插头");
}
@@ -179,11 +191,23 @@ namespace AibisDream.FixSystem
public void ReturnToStartPosition()
{
PlugPosBack();
transform.DOMove(_startPos, 0.1f).OnComplete(() => {
_cableSystem.CableReelRef.ResetRotation();
SwitchToPhysicCableState();
SwitchToPhysicCableState();
});
}
// public void DrownDownPlug()
// {
// transform.DOMove(_startPos, 0.1f).OnComplete(() => {
// _cableSystem.CableReelRef.ResetRotation();
// // 只有在非收起状态时才切换到物理线缆状态
// if (!_cableSystem.isCableRetracted)
// {
// SwitchToPhysicCableState();
// }
// });
// }
private void AdjustPlugPos()
{
@@ -197,20 +221,26 @@ namespace AibisDream.FixSystem
transform.rotation = _initRotation;
}
private void SwitchToPhysicCableState()
public void SwitchToPhysicCableState()
{
// 如果线缆是收起状态,不进行任何操作
// if (_cableSystem.isCableRetracted) return;
// 隐藏 Cable 的 LineRenderer
PlugPosBack();
_cableSystem.PhysicCableRef.Init(transform.position);
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = false;
// 激活 PhysicCable
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = true;
_isPhysicCableActive = true;
}
public void SetPhysicCableActive(bool active)
{
_isPhysicCableActive = active;
}
private void Update()
{
if (_isPhysicCableActive)
if (_isPhysicCableActive && !_cableSystem.isCableRetracted)
{
_cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform);
}
@@ -224,11 +254,20 @@ namespace AibisDream.FixSystem
public bool IsActive => true;
public bool IsAvailable => _cableSystem.BodyModuleSystem.isAvailable;
public bool IsAvailable => _cableSystem.BodyModuleSystem.isAvailable && !_cableSystem.isCableRetracted;
public GameObject GetGameObject()
{
return gameObject;
}
public void SetStartPos(Vector3 pos)
{
_startPos = pos;
}
public Vector3 GetStartPos()
{
return _startPos;
}
}
}