Ver.0.3.0.33

This commit is contained in:
2025-07-08 08:32:46 +00:00
parent 99f4dd67c2
commit 0ad5e29917
6831 changed files with 695623 additions and 234455 deletions
+81 -40
View File
@@ -2,7 +2,6 @@
using AibisDream.Kit;
using AibisDream.Utility;
using DG.Tweening;
using MeadowGames.UINodeConnect4.GraphicRenderer;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -11,14 +10,15 @@ namespace AibisDream.FixSystem
[RequireComponent(typeof(EventTriggerEx))]
public class Plug : MonoBehaviour, IInteraction
{
private static readonly int ShineFade = Shader.PropertyToID("_ShineFade");
#region
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 _initRotation = Quaternion.Euler(0, 0, 180);
#endregion
@@ -32,13 +32,14 @@ namespace AibisDream.FixSystem
#endregion
private bool _isDragging;
private bool _isPhysicCableActive=false;
private bool _isPhysicCableActive;
private void Awake()
{
InitComponentRef();
EventRegister();
_startPos = transform.position; // 初始化时记录初始位置
_startPos = new Vector3(transform.position.x + 0.3f, transform.position.y - 2f,
transform.position.z); // 初始化时记录初始位置
}
private void InitComponentRef()
@@ -47,8 +48,11 @@ namespace AibisDream.FixSystem
_sprite = GetComponent<SpriteRenderer>();
_plugRootPos = transform.Find("Plug Root Pos");
_trigger = GetComponent<EventTriggerEx>();
// 处理插头高亮
_sprite.material.SetFloat(ShineFade, GlobalVariableKit.IsPlugHighLight ? 1 : 0);
}
private void EventRegister()
{
_trigger.Register(EventTriggerType.Drag, OnDrag);
@@ -56,17 +60,12 @@ namespace AibisDream.FixSystem
_trigger.Register(EventTriggerType.PointerUp, OnPointerUp);
}
public void InitPlug(ISocket initSocket)
{
ReturnToStartPosition();
}
/// <summary>
/// 插入某个socket
/// </summary>
/// <param name="targetSocket">目标socket</param>
public void InsertSocket(ISocket targetSocket)
private void InsertSocket(ISocket targetSocket)
{
// 修改插头位置
transform.position = targetSocket.GetSocketPos();
@@ -93,39 +92,62 @@ namespace AibisDream.FixSystem
{
// 修改线头位置
_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;
}
_cableSystem.curSocket = null;
}
private void OnDrag(BaseEventData eventData)
{
// 系统被锁定就返回
if (!_cableSystem.IsPlugAvailable()) return;
if (!_cableSystem.IsPlugAvailable())
{
Debug.Log("OnDrag - System not available");
return;
}
// 未被拖拽也返回
if (!_isDragging) return;
if (!_isDragging)
{
Debug.Log("OnDrag - Not dragging");
return;
}
if (eventData is PointerEventData pointerData)
{
transform.position = CommonUtil.GetMouseWorldPos(pointerData.position, transform);
transform.position = CameraKit.GetMouseWorldPos(pointerData.position);
}
}
private void OnPointerDown(BaseEventData eventData)
{
if (eventData is PointerEventData { button: PointerEventData.InputButton.Right })
{
return;
}
GetComponent<SpriteRenderer>().sortingLayerName = "Tools";
GetComponent<SpriteRenderer>().sortingOrder = 48;
// 系统被锁定就返回
if (!_cableSystem.IsPlugAvailable()) return;
// 首次拖拽后关闭高亮
if (GlobalVariableKit.IsPlugHighLight)
{
GlobalVariableKit.IsPlugHighLight = false;
_sprite.material.SetFloat(ShineFade, 0);
DialogController.Instance.StartDialogNode("拿起插头");
}
// 开启拖拽
_isDragging = true;
@@ -139,11 +161,21 @@ namespace AibisDream.FixSystem
// 关闭 PhysicCable 的更新,并显示 Cable 的 LineRenderer
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = false;
_isPhysicCableActive = false;
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = true;
_cableSystem.CableRef.ShowCable();
// 打开所有模块
FixSystemCenter.SystemDic.Get<BodyModuleSystem>().OpenModuleSlots();
AudioManager.Instance.PlaySfx("event:/ActionFB/mods_open");
AudioManager.Instance.PlaySfx("event:/FollowInput/plugpick");
}
private void OnPointerUp(BaseEventData eventData)
{
if (eventData is PointerEventData { button: PointerEventData.InputButton.Right })
{
return;
}
// 停止拖拽
_isDragging = false;
@@ -152,20 +184,24 @@ namespace AibisDream.FixSystem
{
// 找到了就插入目标Module
InsertSocket(targetModule);
FixSystemCenter.SystemDic.Get<BodyModuleSystem>().CloseModuleSlots(targetModule);
}
else
{
// 没找到就回初始位置
// 没找到就回初始位置
ReturnToStartPosition();
FixSystemCenter.SystemDic.Get<BodyModuleSystem>().CloseModuleSlots(null);
}
}
public void ReturnToStartPosition()
{
transform.DOMove(_startPos, 0.1f).OnComplete(() =>
{
PlugPosBack();
transform.DOMove(_startPos, 0.1f).OnComplete(() =>
{
_cableSystem.CableReelRef.ResetRotation();
SwitchToPhysicCableState();
});
});
}
private void AdjustPlugPos()
@@ -173,31 +209,31 @@ namespace AibisDream.FixSystem
transform.position += _pickupOffset;
transform.rotation = _pickupRotationOffset;
}
private void PlugPosBack()
{
transform.position -= _pickupOffset;
transform.rotation = initRotation;
transform.rotation = _initRotation;
}
private void SwitchToPhysicCableState()
public void SwitchToPhysicCableState()
{
// 隐藏 Cable 的 LineRenderer
PlugPosBack();
_cableSystem.PhysicCableRef.Init(transform.position);
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = false;
// 激活 PhysicCable
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = true;
_cableSystem.PhysicCableRef.Init(transform.position);
_cableSystem.CableRef.HideCable();
_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);
_cableSystem.PhysicCableRef.physicLine.UpdatePlug(transform);
}
}
@@ -209,11 +245,16 @@ 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 Vector3 GetStartPos()
{
return _startPos;
}
}
}