石头
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public void ResetPlug()
|
||||
{
|
||||
// 已经在初始插孔里了,不用动
|
||||
if (curSocket == InitSocket) return;
|
||||
// 不在初始插孔里,就从当前插孔拔出来,插回初始插孔
|
||||
PlugRef.PullUpSocket();
|
||||
PlugRef.InsertSocket(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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user