56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using DG.Tweening;
|
|||
|
|
|
|||
|
|
public class PanelTips : BasePanel
|
|||
|
|
{
|
|||
|
|
[SerializeField] Text mTxtTips;
|
|||
|
|
[SerializeField] float mMoveVal1;
|
|||
|
|
[SerializeField] float mMoveVal2;
|
|||
|
|
|
|||
|
|
private Sequence mTweenSequence;
|
|||
|
|
|
|||
|
|
public void ShowTips(string pTip)
|
|||
|
|
{
|
|||
|
|
mTxtTips.gameObject.SetActive(true);
|
|||
|
|
mTxtTips.text = pTip;
|
|||
|
|
FlyTo(mTxtTips);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void FlyTo(Graphic graphic)
|
|||
|
|
{
|
|||
|
|
RectTransform rt = graphic.rectTransform;
|
|||
|
|
Vector3 tPos = rt.localPosition;
|
|||
|
|
tPos.y = 0;
|
|||
|
|
rt.localPosition = tPos;
|
|||
|
|
Color c = graphic.color;
|
|||
|
|
c.a = 0;
|
|||
|
|
graphic.color = c; //先将字体透明
|
|||
|
|
|
|||
|
|
if (mTweenSequence != null && mTweenSequence.IsPlaying())
|
|||
|
|
{
|
|||
|
|
mTweenSequence.Kill();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
mTweenSequence = DOTween.Sequence(); //创建空序列
|
|||
|
|
Tweener move1 = rt.DOMoveY(rt.position.y + mMoveVal1, 0.5f); //创建向上移动的第一个动画
|
|||
|
|
Tweener move2 = rt.DOMoveY(rt.position.y + mMoveVal2, 0.5f); //创建向上移动的第二个动画
|
|||
|
|
Tweener alpha1 = graphic.DOColor(new Color(c.r, c.g, c.b, 1), 0.5f); //创建Alpha由0到1渐变的动画
|
|||
|
|
Tweener alpha2 = graphic.DOColor(new Color(c.r, c.g, c.b, 0), 0.5f); //创建Alpha由1到0渐变的动画
|
|||
|
|
mTweenSequence.Append(move1); //先添加向上移动的动画
|
|||
|
|
mTweenSequence.Join(alpha1); //同时执行Alpha由0到1渐变的动画
|
|||
|
|
mTweenSequence.AppendInterval(1); //延迟1秒钟
|
|||
|
|
mTweenSequence.Append(move2); //添加向上移动的动画
|
|||
|
|
mTweenSequence.Join(alpha2); //同时执行Alpha由1到0渐变的动画
|
|||
|
|
mTweenSequence.onComplete = HideTip;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void HideTip()
|
|||
|
|
{
|
|||
|
|
mTweenSequence = null;
|
|||
|
|
mTxtTips.gameObject.SetActive(false);
|
|||
|
|
Close();
|
|||
|
|
}
|
|||
|
|
}
|