Files
aibis-dream/Assets/Scripts/FixSystemNew/CableSystem.cs
T
2024-11-30 08:04:03 +08:00

113 lines
3.0 KiB
C#

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 ISocket InitSocket { get; private set; }
public BodyModuleSystem BodyModuleSystem { get; private set; }
#endregion
#region 系统状态
public bool isInDialog = false;
public bool isActive = true;
[HideInInspector] public ISocket curSocket;
[HideInInspector] public BodyModule curBodyModule;
#endregion
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<ISocket>();
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 TryFindClosestModule(Vector3 sourcePos, out BodyModule targetModule)
{
return BodyModuleSystem.TryFindClosestModule(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
}
}