73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
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 OnInit()
|
||
{
|
||
selfRect = GetComponent<RectTransform>();
|
||
HideTips();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 使用sizeDelta缩放
|
||
/// </summary>
|
||
/// <param name="target"></param>
|
||
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
|
||
}
|
||
|
||
/// <summary>
|
||
/// 针对父物体锚点在四个角的情况
|
||
/// </summary>
|
||
/// <param name="target"></param>
|
||
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);
|
||
}
|
||
} |