diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BaseSocket.cs b/Assets/Scripts/FixSystemNew/BodyModule/BaseSocket.cs index a43afcd19..200f1cbdd 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BaseSocket.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BaseSocket.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; namespace AibisDream.FixSystem { @@ -6,7 +6,7 @@ namespace AibisDream.FixSystem { public void PlugIn(); public void PlugOut(); - public Vector3 GetSocketPos(); + public Transform GetSocketPos(); public bool IsAvailable(); // 新增方法 } @@ -24,9 +24,9 @@ namespace AibisDream.FixSystem Debug.Log("Plug Out InitSocket"); } - public Vector3 GetSocketPos() + public Transform GetSocketPos() { - return transform.position; + return transform; } public bool IsAvailable() diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs index b45003ca2..076611cf9 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs @@ -6,6 +6,7 @@ using AibisDream.Framework; using Cinemachine; using JetBrains.Annotations; using UnityEngine; +using AibisDream.Kit; namespace AibisDream.FixSystem { @@ -18,7 +19,6 @@ namespace AibisDream.FixSystem private GameObject _bodyModuleGroup; private GameObject _headModuleGroup; - public CableSystem CableSystem { get; private set; } [HideInInspector] public HeatMapController heatMapController; #endregion @@ -28,7 +28,6 @@ namespace AibisDream.FixSystem private readonly ModuleSystemData _data = new(); public bool inHotErr; private int _heatValue; - public bool isAvailable; private int HeatValue { @@ -62,7 +61,6 @@ namespace AibisDream.FixSystem // 处理内部索引 _bodyModuleGroup = transform.Find("Body Module Group")?.gameObject; _headModuleGroup = transform.Find("Head Module Group")?.gameObject; - // CableSystem = FixPanelSystem.CableSystem; if (transform.Find("HeatMapController")) { heatMapController = transform.Find("HeatMapController").GetComponent(); @@ -108,7 +106,7 @@ namespace AibisDream.FixSystem continue; // 跳过不可用的模块 } - float tempDistance = Vector3.Distance(sourcePos, bodyModule.GetSocketPos()); + float tempDistance = Vector3.Distance(sourcePos, bodyModule.GetSocketPos().position); if (tempDistance < closestDistance) { @@ -134,6 +132,7 @@ namespace AibisDream.FixSystem public void OpenModuleSlots() { + AudioManager.Instance.PlaySfx("event:/ActionFB/mods_open"); foreach (var module in BodyModules) { module.OpenPlugSlot(); @@ -177,7 +176,7 @@ namespace AibisDream.FixSystem { heatMapController.ShowHeatMap(); DisableSystem(); - ResetPlug(); + FixPanelSystem.GetRepairPanel().ResetPlug(); } public void HideHeatMap() @@ -196,20 +195,12 @@ namespace AibisDream.FixSystem _heatValue = 0; } - /// - /// 插头重新插入初始插孔 - /// - public void ResetPlug() - { - CableSystem.ResetPlug(); - } - /// /// 激活交互系统 /// public void EnableSystem() { - isAvailable = true; + // isAvailable = true; } /// @@ -217,7 +208,7 @@ namespace AibisDream.FixSystem /// public void DisableSystem() { - isAvailable = false; + // isAvailable = false; } public void SwitchModuleGroup(ModuleState moduleState) diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleYarnCommand.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleYarnCommand.cs index 90ee87222..1962d1e15 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleYarnCommand.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleYarnCommand.cs @@ -1,6 +1,5 @@ -using System.Collections; +using System.Collections; using AibisDream.FixSystem; -using AibisDream.Framework; using Yarn.Unity; using UnityEngine; @@ -10,6 +9,7 @@ namespace AibisDream { private static BodyModuleSystem BodyModuleSystem => FixSystemCenter.SystemDic.Get(); private static PunchTapeSystem PunchTapeSystem => FixSystemCenter.SystemDic.Get(); + private static CablePanel CablePanel => FixPanelSystem.GetRepairPanel(); [YarnCommand("enable_cut")] public static void EnableCut(string moduleName) @@ -22,7 +22,7 @@ namespace AibisDream [YarnCommand("Reset_Plug")] public static void Reset_Plug() { - BodyModuleSystem.CableSystem.ResetPlug(); + CablePanel.ResetPlug(); } [YarnCommand("ShowHeatMap")] @@ -54,7 +54,7 @@ namespace AibisDream [YarnCommand("Temp_RemoveUFCover")] public static void Temp_RemoveUFCover() { - BodyModuleSystem.CableSystem.ResetPlug(); + CablePanel.ResetPlug(); var _UFModule = BodyModuleSystem.FindBodyModuleByName("UF").transform.GetComponent(); _UFModule.RemoveUFCover(); } @@ -142,13 +142,13 @@ namespace AibisDream [YarnCommand("DropCable")] public static void DropCable() { - BodyModuleSystem.CableSystem.DropDownCable(); + CablePanel.DropDownCable(); } [YarnCommand("RetractCable")] public static void RetractCable() { - BodyModuleSystem.CableSystem.PullUpCable(); + CablePanel.PullUpCable(); } [YarnCommand("StartHeadBreathing")] diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs index 209b37a8a..5084b4c80 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs @@ -13,7 +13,7 @@ namespace AibisDream.FixSystem private LineRenderer _stiffLineRenderer; // 用于渲染刚性部分 private Vector3[] _points; - private CableSystem _cableSystem; + private CablePanel _cablePanel; [SerializeField] private CableConfig config = CableConfig.GeneDefaultConfig(); @@ -49,8 +49,8 @@ namespace AibisDream.FixSystem private void InitComponentRefs() { - _cableSystem = transform.parent.GetComponent(); - + _cablePanel = transform.GetComponentInParent(); + // 复制第一个LineRenderer的属性到第二个 _stiffLineRenderer.startWidth = _lineRenderer.startWidth; _stiffLineRenderer.endWidth = _lineRenderer.startWidth; @@ -58,12 +58,12 @@ namespace AibisDream.FixSystem _stiffLineRenderer.startColor = _lineRenderer.startColor; _stiffLineRenderer.endColor = _lineRenderer.startColor; _stiffLineRenderer.sortingLayerName = - _cableSystem.CableReelRef.GetComponent().sortingLayerName; - _stiffLineRenderer.sortingOrder = _cableSystem.CableReelRef.GetComponent().sortingOrder - 1; + _cablePanel.CableReelRef.GetComponent().sortingLayerName; + _stiffLineRenderer.sortingOrder = _cablePanel.CableReelRef.GetComponent().sortingOrder - 1; // 连线起止点 - _start = _cableSystem.CableRootPos; - _end = _cableSystem.PlugRef.transform; + _start = _cablePanel.CableRootPos; + _end = _cablePanel.PlugRef.transform; } private void InitPoints() @@ -104,7 +104,7 @@ namespace AibisDream.FixSystem float F = Mathf.Lerp(config.forceMin, config.forceMax, t); // 计算出线方向(从转盘出线口到起始点) - Vector3 dir = (_start.position - _cableSystem.CableReelRef.transform.position).normalized; + Vector3 dir = (_start.position - _cablePanel.CableReelRef.transform.position).normalized; // 设置刚性部分 for (int i = 0; i < config.stiffCount; i++) diff --git a/Assets/Scripts/FixSystemNew/BodyModule/CableReel.cs b/Assets/Scripts/FixSystemNew/BodyModule/CableReel.cs index ceb0eb086..dcb7845da 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/CableReel.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/CableReel.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; namespace AibisDream.FixSystem { @@ -8,7 +8,7 @@ namespace AibisDream.FixSystem [SerializeField] private float torqueStrength = 200f; // 扭矩强度 [SerializeField] private float angularDamping = 5f; // 角速度阻尼 - private CableSystem cableSystem; + private CablePanel cablePanel; private float angularVelocity; // 角速度 private float currentAngle; // 当前角度 public Vector3 outletPos { get; private set; } // 出线口位置 @@ -17,8 +17,8 @@ namespace AibisDream.FixSystem private void Start() { - // 获取CableSystem引用 - cableSystem = transform.parent.GetComponent(); + // 获取CablePanel引用 + cablePanel = transform.GetComponentInParent(); currentAngle = transform.eulerAngles.z; // 获取SpriteRenderer并计算半径 @@ -56,16 +56,16 @@ namespace AibisDream.FixSystem public void UpdateRotation() { // 如果PhysicCable激活,不进行旋转 - if (cableSystem == null || cableSystem.PlugRef == null || - cableSystem.PhysicCableRef.GetComponent().enabled) return; + if (cablePanel == null || cablePanel.PlugRef == null || + cablePanel.PhysicCableRef.GetComponent().enabled) return; Vector2 center = transform.position; - + // 使用当前出线口位置 Vector2 outlet = outletPos; - + // 力向量(线缆拉力方向) - Vector2 force = (Vector2)cableSystem.PlugRef.transform.position - outlet; + Vector2 force = (Vector2)cablePanel.PlugRef.transform.position - outlet; // 杆臂向量(力作用点相对于圆心的位置) Vector2 r = outlet - center; diff --git a/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs b/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs index b1a0d45e3..46cfb6c71 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs @@ -1,5 +1,4 @@ -using AibisDream.Framework; -using UnityEngine; +using UnityEngine; using DG.Tweening; using AibisDream.Kit; @@ -24,14 +23,10 @@ namespace AibisDream.FixSystem #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; @@ -46,17 +41,6 @@ namespace AibisDream.FixSystem LoadCableState(); } - private void OnEnable() - { - EnumEventSystem.Global.Register(InteractionEventEnum.DialogEnd, HandleDialogueComplete); - EnumEventSystem.Global.Register(InteractionEventEnum.DialogStart, HandleDialogueStart); - } - - private void OnDisable() - { - EnumEventSystem.Global.UnRegister(InteractionEventEnum.DialogEnd, HandleDialogueComplete); - EnumEventSystem.Global.UnRegister(InteractionEventEnum.DialogStart, HandleDialogueStart); - } private void InitComponentRefs() { @@ -140,16 +124,6 @@ namespace AibisDream.FixSystem #region 系统可用状态 - private void HandleDialogueStart() - { - isInDialog = true; - } - - private void HandleDialogueComplete() - { - isInDialog = false; - } - public void Disable_plugInput() { isActive = false; @@ -160,15 +134,6 @@ namespace AibisDream.FixSystem isActive = true; } - /// - /// 查询插线系统是否可用 - /// - /// - public bool IsPlugAvailable() - { - return isActive && !isInDialog; - } - #endregion public void PullUpCable() @@ -177,7 +142,7 @@ namespace AibisDream.FixSystem //禁用plug交互 Disable_plugInput(); ResetPlug(); - PlugRef.SetPhysicCableActive(false); + // PlugRef.SetPhysicCableActive(false); PlugRef.GetComponent().sortingLayerName = CableReelRef.GetComponent().sortingLayerName; PlugRef.GetComponent().sortingOrder = 41; @@ -192,12 +157,11 @@ namespace AibisDream.FixSystem public void DropDownCable() { if (!isCableRetracted) return; - Debug.Log("DorpDown"); PlugRef.PullUpSocket(); CableReelRef.ResetRotation(); PlugRef.transform.DOMove(PlugRef.GetStartPos(), 0.1f).OnComplete(() => { - PlugRef.SwitchToPhysicCableState(); + // PlugRef.SwitchToPhysicCableState(); isCableRetracted = false; SaveCableState(); // 添加一个短暂的延迟来确保状态正确设置 @@ -221,7 +185,6 @@ namespace AibisDream.FixSystem CableReelRef.GetComponent().sortingLayerName; PlugRef.GetComponent().sortingOrder = 41; isCableRetracted = true; - //SaveCableState(); } } } \ No newline at end of file diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Modules/BodyModule.cs b/Assets/Scripts/FixSystemNew/BodyModule/Modules/BodyModule.cs index 2f9303ba1..c9ca8a27e 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Modules/BodyModule.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Modules/BodyModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using AibisDream.Framework; using Newtonsoft.Json; using UnityEngine; @@ -35,7 +35,6 @@ namespace AibisDream.FixSystem [Header("CutText闪烁效果")] private float cutTextFlickerThreshold = 0.4f; // 开始闪烁的阈值 private float cutTextFlickerInterval = 0.1f; // 闪烁间隔 - private float cutTextFlickerTimer = 0f; // 闪烁计时器 private bool isCutTextFlickering = false; // 是否正在闪烁 private Coroutine flickerCoroutine; // 闪烁协程引用 @@ -44,7 +43,6 @@ namespace AibisDream.FixSystem // 模块基本数据 [SerializeField] public BodyModuleData data; public bool available = true; - private bool _cutting; private bool _isOpen; private void Awake() @@ -102,9 +100,9 @@ namespace AibisDream.FixSystem { } - public Vector3 GetSocketPos() + public Transform GetSocketPos() { - return _socketPos.position; + return _socketPos; } public void OpenPlugSlot() diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs index fa2321627..bfefde6a6 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs @@ -1,3 +1,4 @@ +using System; using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; @@ -12,39 +13,46 @@ namespace AibisDream.FixSystem { private static readonly int ShineFade = Shader.PropertyToID("_ShineFade"); + private const string SortingLayerDragging = "Tools"; + private const int SortingOrderDragging = 48; + #region 插头当前信息 + [SerializeField] private Vector3 startPosOffset = new(0.3f, -2f, 0); private Vector3 _startPos; - - 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); + + private readonly Quaternion _pickupRotation = Quaternion.Euler(0, 0, 30); + private readonly Quaternion _defaultRotation = Quaternion.Euler(0, 0, 180); #endregion #region 索引 - private CableSystem _cableSystem; + private CablePanel cablePanel; private SpriteRenderer _sprite; private Transform _plugRootPos; private EventTriggerEx _trigger; + public Transform PlugRoot => _plugRootPos; + #endregion + public event Action OnInsertSocket; + public event Action OnPullUpSocket; + public event Action OnPlugPointerDown; + private bool _isDragging; - private bool _isPhysicCableActive; private void Awake() { InitComponentRef(); EventRegister(); - _startPos = new Vector3(transform.position.x + 0.3f, transform.position.y - 2f, - transform.position.z); // 初始化时记录初始位置 + _startPos = transform.position + startPosOffset; } private void InitComponentRef() { - _cableSystem = transform.parent.GetComponent(); + cablePanel = transform.GetComponentInParent(true); _sprite = GetComponent(); _plugRootPos = transform.Find("Plug Root Pos"); _trigger = GetComponent(); @@ -60,7 +68,6 @@ namespace AibisDream.FixSystem _trigger.Register(EventTriggerType.PointerUp, OnPointerUp); } - /// /// 插入某个socket /// @@ -68,21 +75,13 @@ namespace AibisDream.FixSystem private void InsertSocket(ISocket targetSocket) { // 修改插头位置 - transform.position = targetSocket.GetSocketPos(); - _cableSystem.CableRef.SetEndPos(transform); + transform.position = targetSocket.GetSocketPos().position; // 处理插槽插入 targetSocket.PlugIn(); - AudioManager.Instance.PlaySfx("event:/FollowInput/plugin"); _sprite.enabled = false; - _cableSystem.curSocket = targetSocket; - if (targetSocket is BodyModule bodyModule) - { - // 插入模块时触发插入事件 - EnumEventSystem.Global.Send(EventEnum.PlugIn); - _cableSystem.curBodyModule = bodyModule; - } + OnInsertSocket?.Invoke(targetSocket); } /// @@ -90,45 +89,14 @@ namespace AibisDream.FixSystem /// public void PullUpSocket() { - // 修改线头位置 - _cableSystem.CableRef.SetEndPos(_plugRootPos); - - _cableSystem.curSocket?.PlugOut(); - AudioManager.Instance.PlaySfx("event:/FollowInput/plugout"); _sprite.enabled = true; - if (_cableSystem.curSocket is BodyModule) - { - // 从模块拔出时触发事件 - EnumEventSystem.Global.Send(EventEnum.PlugOut); - _cableSystem.curBodyModule = null; - - // 清除屏幕 - var screenSystem = FixSystemCenter.SystemDic.Get(); - if (screenSystem != null) - { - screenSystem.ClearTextScreen(); - } - } - - _cableSystem.curSocket = null; + OnPullUpSocket?.Invoke(); } private void OnDrag(BaseEventData eventData) { - // 系统被锁定就返回 - if (!_cableSystem.IsPlugAvailable()) - { - Debug.Log("OnDrag - System not available"); - return; - } - - // 未被拖拽也返回 - if (!_isDragging) - { - Debug.Log("OnDrag - Not dragging"); - return; - } + if (!_isDragging) return; if (eventData is PointerEventData pointerData) { @@ -139,46 +107,30 @@ namespace AibisDream.FixSystem private void OnPointerDown(BaseEventData eventData) { if (eventData is PointerEventData { button: PointerEventData.InputButton.Right }) - { return; - } - - GetComponent().sortingLayerName = "Tools"; - GetComponent().sortingOrder = 48; - // 系统被锁定就返回 - if (!_cableSystem.IsPlugAvailable()) return; - - // 首次拖拽后关闭高亮 - if (GlobalVariableKit.IsPlugHighLight) - { - GlobalVariableKit.IsPlugHighLight = false; - _sprite.material.SetFloat(ShineFade, 0); - DialogController.Instance.StartDialogNode("拿起插头"); - } - // 开启拖拽 + _sprite.sortingLayerName = SortingLayerDragging; + _sprite.sortingOrder = SortingOrderDragging; + + OnPlugPointerDown?.Invoke(); + + TryCloseHighlight(); + _isDragging = true; - - // 进行插拔动作 - if (_cableSystem.curSocket != null) PullUpSocket(); - - // 调整插头形状 AdjustPlugPos(); - // 关闭 PhysicCable 的更新,并显示 Cable 的 LineRenderer - _cableSystem.PhysicCableRef.GetComponent().enabled = false; - _isPhysicCableActive = false; - _cableSystem.CableRef.ShowCable(); - - // 打开所有模块 - FixSystemCenter.SystemDic.Get().OpenModuleSlots(); - AudioManager.Instance.PlaySfx("event:/ActionFB/mods_open"); AudioManager.Instance.PlaySfx("event:/FollowInput/plugpick"); } + private void TryCloseHighlight() + { + if (!GlobalVariableKit.IsPlugHighLight) return; + GlobalVariableKit.IsPlugHighLight = false; + _sprite.material.SetFloat(ShineFade, 0); + } + private void OnPointerUp(BaseEventData eventData) { - Debug.Log("OnPointerUp"); if (eventData is PointerEventData { button: PointerEventData.InputButton.Right }) { return; @@ -188,61 +140,29 @@ namespace AibisDream.FixSystem _isDragging = false; // 寻找可吸附的Module - if (_cableSystem.TryFindClosestModule(transform.position, out var targetModule)) + if (cablePanel.TryFindClosestModule(transform.position, out var targetModule)) { - // 找到了就插入目标Module InsertSocket(targetModule); - FixSystemCenter.SystemDic.Get().CloseModuleSlots(targetModule); } else { - // 没找到就回到初始位置 ReturnToStartPosition(); - FixSystemCenter.SystemDic.Get().CloseModuleSlots(null); } } public void ReturnToStartPosition() { - PlugPosBack(); + transform.rotation = _defaultRotation; transform.DOMove(_startPos, 0.1f).OnComplete(() => { - _cableSystem.CableReelRef.ResetRotation(); - SwitchToPhysicCableState(); + cablePanel.CableReelRef.ResetRotation(); + cablePanel.SetCableMode(CableMode.Physic, transform); }); } private void AdjustPlugPos() { - transform.position += _pickupOffset; - transform.rotation = _pickupRotationOffset; - } - - private void PlugPosBack() - { - transform.position -= _pickupOffset; - transform.rotation = _initRotation; - } - - public void SwitchToPhysicCableState() - { - _cableSystem.PhysicCableRef.Init(transform.position); - _cableSystem.CableRef.HideCable(); - _cableSystem.PhysicCableRef.GetComponent().enabled = true; - _isPhysicCableActive = true; - } - - public void SetPhysicCableActive(bool active) - { - _isPhysicCableActive = active; - } - - private void Update() - { - if (_isPhysicCableActive && !_cableSystem.isCableRetracted) - { - _cableSystem.PhysicCableRef.physicLine.UpdatePlug(transform); - } + transform.rotation = _pickupRotation; } void OnDrawGizmosSelected() @@ -253,7 +173,7 @@ namespace AibisDream.FixSystem public bool IsActive => true; - public bool IsAvailable => _cableSystem.BodyModuleSystem.isAvailable && !_cableSystem.isCableRetracted; + public bool IsAvailable => !cablePanel.isCableRetracted; public GameObject GetGameObject() {