using System.Collections; using DG.Tweening; using UnityEngine; namespace AibisDream.FixSystem { public class TubeController : MonoBehaviour { [Header("插管蒙太奇整体位置")] public Vector3 showPos; public Vector3 hidePos; [Header("管子位置")] public Vector3 pullOutPos; public Vector3 linkPos; [Header("动画时间")] public float showDuration; public float plugDuration; private Transform _tube; private void Awake() { gameObject.SetActive(false); InitRefs(); } private void InitRefs() { _tube = transform.Find("插线"); _tube.localPosition = pullOutPos; transform.localPosition = hidePos; } /// /// 播放连接动画 /// /// 协程 public IEnumerator PlayLinkAnime() { yield return ShowAndHide(LinkAction()); } /// /// 播放拔出动画 /// /// 协程 public IEnumerator PlayPullOutAnime() { yield return ShowAndHide(PullOutAction()); } private IEnumerator LinkAction() { // 插线 Tween link = _tube.DOLocalMove(linkPos, plugDuration); while (link.active && !link.IsComplete()) { yield return null; } // TODO 插完线后更新人物图片 } private IEnumerator PullOutAction() { // 拔线 Tween pullOut = _tube.DOLocalMove(pullOutPos, plugDuration); while (pullOut.active && !pullOut.IsComplete()) { yield return null; } // TODO 插完线后更新人物图片 } private IEnumerator ShowAndHide(IEnumerator middleAction) { gameObject.SetActive(true); // 打开插管部分 Tween showTween = transform.DOLocalMove(showPos, showDuration); while (showTween.active && !showTween.IsComplete()) { yield return null; } // 暂停一下 yield return new WaitForSeconds(2f); // 中间动作 yield return middleAction; // 暂停一下 yield return new WaitForSeconds(2f); // 关闭插管部分 Tween hideTween = transform.DOLocalMove(hidePos, showDuration); while (hideTween.active && !hideTween.IsComplete()) { yield return null; } gameObject.SetActive(false); } } }