using UnityEngine; using UnityEngine.Events; using UnityEngine.PlayerLoop; using Yarn.Unity; namespace AibisDream.FixSystem { public class CableSystem : MonoBehaviour { #region 组件索引 public Plug PlugRef { get; private set; } public Cable CableRef { get; private set; } 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 #region 系统状态 public bool isInDialog; 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(); CableRef = transform.Find("Cable").GetComponent(); CableRootPos = transform.Find("Cable Root Pos").transform; InitSocket = transform.Find("Init Socket").GetComponent(); PhysicCableRef = transform.Find("PhysicCable").GetComponent(); BodyModuleSystem = transform.parent.GetComponent(); } private void InitSystem() { //PhysicCableRef.Init(); PlugRef.InitPlug(InitSocket); } public void Update() { } public void ResetPlug() { // 已经在初始插孔里了,不用动 if (curSocket == InitSocket) return; // 不在初始插孔里,就从当前插孔拔出来,插回初始插孔 PlugRef.PullUpSocket(); PlugRef.ReturnToStartPosition(); } /// /// 寻找最接近的Module /// /// 源位置 /// 最近的Module /// 是否能找到目标范围内的Module 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; } public void Disable_plugInput() { isActive = false; } public void Enable_plugInput() { isActive = true; } /// /// 查询插线系统是否可用 /// /// public bool IsPlugAvailable() { return isActive && !isInDialog; } #endregion } }