YanCheng_Metrology/Assets/Scripts/Project/Objects/Other/ImageTips.cs

38 lines
1005 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using DG.Tweening;
/// <summary>
/// UIÌáʾ
/// </summary>
public class ImageTips : MonoBehaviour
{
public Image image; // UI Image×é¼þ
private RectTransform selfRect;
private Tween tween;
public void ShowTips(RectTransform target)
{
gameObject.SetActive(true);
selfRect = GetComponent<RectTransform>();
image.enabled = true;
selfRect.SetParent(target);
selfRect.anchoredPosition = Vector2.zero;
selfRect.sizeDelta = new Vector2(target.sizeDelta.x + 20f, target.sizeDelta.x + 20f);
tween = DOVirtual.Float(1, 0.2f, 1f, t =>
{
Color finalColor = image.color;
finalColor.a = t;
image.color = finalColor;
}).SetLoops(-1, LoopType.Yoyo);
}
public void HideTips()
{
if (tween != null)
tween.Kill(true);
transform.parent = null;
gameObject.SetActive(false);
}
}