资源清理
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.PlayerLoop;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
@@ -15,9 +12,6 @@ namespace AibisDream.FixSystem
|
||||
public PhysicCable PhysicCableRef { get; private set; }
|
||||
public Transform CableRootPos { get; private set; }
|
||||
|
||||
public Transform ControlPoint { get; private set; }
|
||||
public ISocket InitSocket { get; private set; }
|
||||
|
||||
public BodyModuleSystem BodyModuleSystem { get; private set; }
|
||||
|
||||
#endregion
|
||||
@@ -59,7 +53,6 @@ namespace AibisDream.FixSystem
|
||||
PlugRef = transform.Find("Plug").GetComponent<Plug>();
|
||||
CableRef = transform.Find("Cable").GetComponent<Cable>();
|
||||
CableRootPos = transform.Find("Cable Root Pos").transform;
|
||||
InitSocket = transform.Find("Init Socket").GetComponent<ISocket>();
|
||||
PhysicCableRef = transform.Find("PhysicCable").GetComponent<PhysicCable>();
|
||||
|
||||
BodyModuleSystem = transform.parent.GetComponent<BodyModuleSystem>();
|
||||
@@ -67,19 +60,12 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitSystem()
|
||||
{
|
||||
|
||||
//PhysicCableRef.Init();
|
||||
PlugRef.InitPlug(InitSocket);
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
|
||||
// 初始状态Plug垂下
|
||||
PlugRef.InitPlug();
|
||||
}
|
||||
|
||||
public void ResetPlug()
|
||||
{
|
||||
// 已经在初始插孔里了,不用动
|
||||
if (curSocket == InitSocket) return;
|
||||
// 不在初始插孔里,就从当前插孔拔出来,插回初始插孔
|
||||
PlugRef.PullUpSocket();
|
||||
PlugRef.ReturnToStartPosition();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using DG.Tweening;
|
||||
using MeadowGames.UINodeConnect4.GraphicRenderer;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
@@ -17,8 +16,7 @@ namespace AibisDream.FixSystem
|
||||
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,7 +30,7 @@ namespace AibisDream.FixSystem
|
||||
#endregion
|
||||
|
||||
private bool _isDragging;
|
||||
private bool _isPhysicCableActive=false;
|
||||
private bool _isPhysicCableActive;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -48,7 +46,7 @@ namespace AibisDream.FixSystem
|
||||
_plugRootPos = transform.Find("Plug Root Pos");
|
||||
_trigger = GetComponent<EventTriggerEx>();
|
||||
}
|
||||
|
||||
|
||||
private void EventRegister()
|
||||
{
|
||||
_trigger.Register(EventTriggerType.Drag, OnDrag);
|
||||
@@ -56,17 +54,16 @@ namespace AibisDream.FixSystem
|
||||
_trigger.Register(EventTriggerType.PointerUp, OnPointerUp);
|
||||
}
|
||||
|
||||
public void InitPlug(ISocket initSocket)
|
||||
public void InitPlug()
|
||||
{
|
||||
ReturnToStartPosition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 插入某个socket
|
||||
/// </summary>
|
||||
/// <param name="targetSocket">目标socket</param>
|
||||
public void InsertSocket(ISocket targetSocket)
|
||||
private void InsertSocket(ISocket targetSocket)
|
||||
{
|
||||
// 修改插头位置
|
||||
transform.position = targetSocket.GetSocketPos();
|
||||
@@ -93,18 +90,18 @@ 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;
|
||||
}
|
||||
|
||||
@@ -112,10 +109,10 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
// 系统被锁定就返回
|
||||
if (!_cableSystem.IsPlugAvailable()) return;
|
||||
|
||||
|
||||
// 未被拖拽也返回
|
||||
if (!_isDragging) return;
|
||||
|
||||
|
||||
if (eventData is PointerEventData pointerData)
|
||||
{
|
||||
transform.position = CommonUtil.GetMouseWorldPos(pointerData.position, transform);
|
||||
@@ -155,17 +152,14 @@ namespace AibisDream.FixSystem
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没找到就插回初始位置
|
||||
// 没找到就回到初始位置
|
||||
ReturnToStartPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnToStartPosition()
|
||||
{
|
||||
transform.DOMove(_startPos, 0.1f).OnComplete(() =>
|
||||
{
|
||||
SwitchToPhysicCableState();
|
||||
});
|
||||
transform.DOMove(_startPos, 0.1f).OnComplete(SwitchToPhysicCableState);
|
||||
}
|
||||
|
||||
private void AdjustPlugPos()
|
||||
@@ -173,26 +167,24 @@ namespace AibisDream.FixSystem
|
||||
transform.position += _pickupOffset;
|
||||
transform.rotation = _pickupRotationOffset;
|
||||
}
|
||||
|
||||
private void PlugPosBack()
|
||||
{
|
||||
transform.position -= _pickupOffset;
|
||||
transform.rotation = initRotation;
|
||||
transform.rotation = _initRotation;
|
||||
}
|
||||
|
||||
private void SwitchToPhysicCableState()
|
||||
{
|
||||
|
||||
// 隐藏 Cable 的 LineRenderer
|
||||
PlugPosBack();
|
||||
_cableSystem.PhysicCableRef.Init(transform.position);
|
||||
_cableSystem.PhysicCableRef.Init(transform.position);
|
||||
_cableSystem.CableRef.GetComponent<LineRenderer>().enabled = false;
|
||||
// 激活 PhysicCable
|
||||
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = true;
|
||||
_cableSystem.PhysicCableRef.GetComponent<LineRenderer>().enabled = true;
|
||||
_isPhysicCableActive = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isPhysicCableActive)
|
||||
|
||||
Reference in New Issue
Block a user