using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using DG.Tweening;
///
/// UI提示
///
public class ImageTips : MonoBehaviour
{
public Image image; // UI Image组件
private RectTransform selfRect;
private Tween tween;
public void OnInit()
{
selfRect = GetComponent();
HideTips();
}
///
/// 使用sizeDelta缩放
///
///
public void ShowTips(RectTransform target)
{
gameObject.SetActive(true);
image.enabled = true;
selfRect.SetParent(target);
selfRect.anchoredPosition = Vector2.zero;
selfRect.localScale = Vector2.one; //HQB高亮大小不定,调整缩放
selfRect.sizeDelta = new Vector2(target.sizeDelta.x + 20f, target.sizeDelta.y + 20f);
tween = DOVirtual.Float(1, 0.3f, 0.5f, t =>
{
Color finalColor = image.color;
finalColor.a = t;
image.color = finalColor;
}).SetLoops(-1, LoopType.Yoyo); //HQB 原始数值:1,0.2,1
}
///
/// 针对父物体锚点在四个角的情况
///
///
public void ShowTipsExtend(RectTransform target)
{
gameObject.SetActive(true);
image.enabled = true;
selfRect.anchorMax = target.anchorMax;
selfRect.anchorMin = target.anchorMin;
selfRect.SetParent(target);
selfRect.anchoredPosition = target.anchoredPosition;
selfRect.offsetMin = new Vector2(-25f, -25f);
selfRect.offsetMax = new Vector2(25f, 25f);
;
//selfRect.localScale = Vector2.one;//HQB高亮大小不定,调整缩放
tween = DOVirtual.Float(1, 0.3f, 0.5f, t =>
{
Color finalColor = image.color;
finalColor.a = t;
image.color = finalColor;
}).SetLoops(-1, LoopType.Yoyo); //HQB 原始数值:1,0.2,1
}
public void HideTips()
{
if (tween != null)
tween.Kill(true);
if (transform.parent != null)
transform.parent = null;
gameObject.SetActive(false);
}
}