126 lines
3.3 KiB
C#
126 lines
3.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class CableSystem : MonoBehaviour
|
|
{
|
|
#region 组件索引
|
|
|
|
public Plug PlugRef { get; private set; }
|
|
public Cable CableRef { get; private set; }
|
|
public Transform CableRootPos { get; private set; }
|
|
public Socket InitSocket { get; private set; }
|
|
|
|
public BodyModuleSystem BodyModuleSystem { get; private set; }
|
|
private BodyModule[] _bodyModules;
|
|
|
|
#endregion
|
|
|
|
#region 系统状态
|
|
|
|
public bool isInDialog = false;
|
|
public bool isActive = true;
|
|
|
|
[HideInInspector] public Socket curSocket;
|
|
|
|
#endregion
|
|
|
|
#region 事件
|
|
|
|
public UnityEvent<Socket> plugInEvent;
|
|
public UnityEvent<Socket> plugOutEvent;
|
|
|
|
public UnityEvent plugStartDrag;
|
|
public UnityEvent plugEndDrag;
|
|
|
|
#endregion
|
|
|
|
public Vector3 InitSocketPos => InitSocket.transform.position;
|
|
|
|
private void Awake()
|
|
{
|
|
InitComponentRefs();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
InitSystem();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
DialogController.OnDialogueStart += HandleDialogueStart;
|
|
DialogController.OnDialogueComplete += HandleDialogueComplete;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
DialogController.OnDialogueStart -= HandleDialogueStart;
|
|
DialogController.OnDialogueComplete -= HandleDialogueComplete;
|
|
}
|
|
|
|
private void InitComponentRefs()
|
|
{
|
|
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<Socket>();
|
|
|
|
BodyModuleSystem = transform.parent.GetComponent<BodyModuleSystem>();
|
|
}
|
|
|
|
private void InitSystem()
|
|
{
|
|
PlugRef.InitPlug(InitSocket);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 寻找最接近的Module
|
|
/// </summary>
|
|
/// <param name="sourcePos">源位置</param>
|
|
/// <param name="targetModule">最近的Module</param>
|
|
/// <returns>是否能找到目标范围内的Module</returns>
|
|
public bool TryFindClosestSocket(Vector3 sourcePos, out BodyModule targetModule)
|
|
{
|
|
return BodyModuleSystem.TryFindClosestSocket(sourcePos, out targetModule);
|
|
}
|
|
|
|
#region 系统可用状态
|
|
|
|
private void HandleDialogueStart()
|
|
{
|
|
isInDialog = true;
|
|
}
|
|
|
|
private void HandleDialogueComplete()
|
|
{
|
|
isInDialog = false;
|
|
}
|
|
|
|
[YarnCommand("Disable_plugInput")]
|
|
public void Disable_plugInput()
|
|
{
|
|
isActive = false;
|
|
}
|
|
|
|
[YarnCommand("Enable_plugInput")]
|
|
public void Enable_plugInput()
|
|
{
|
|
isActive = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询插线系统是否可用
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsPlugAvailable()
|
|
{
|
|
return isActive && !isInDialog;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |