103 lines
2.8 KiB
C#
103 lines
2.8 KiB
C#
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()
|
|
{
|
|
InitRefs();
|
|
}
|
|
|
|
private void InitRefs()
|
|
{
|
|
_tube = transform.Find("插线");
|
|
|
|
_tube.localPosition = pullOutPos;
|
|
transform.localPosition = hidePos;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放连接动画
|
|
/// </summary>
|
|
/// <returns>协程</returns>
|
|
public IEnumerator PlayLinkAnime()
|
|
{
|
|
yield return ShowAndHide(LinkAction());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放拔出动画
|
|
/// </summary>
|
|
/// <returns>协程</returns>
|
|
public IEnumerator PlayPullOutAnime()
|
|
{
|
|
yield return ShowAndHide(PullOutAction());
|
|
}
|
|
|
|
private IEnumerator LinkAction()
|
|
{
|
|
// 插线
|
|
Tween link = _tube.DOLocalMove(linkPos, plugDuration);
|
|
while (link.active && !link.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
// 插完线后更新人物图片
|
|
ClinicYarnCommand.AddLinkDevice();
|
|
}
|
|
|
|
private IEnumerator PullOutAction()
|
|
{
|
|
// 拔线
|
|
Tween pullOut = _tube.DOLocalMove(pullOutPos, plugDuration);
|
|
while (pullOut.active && !pullOut.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
// 插完线后更新人物图片
|
|
ClinicYarnCommand.RemoveLinkDevice();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |