CultivationOfBrewing-2/Assets/Scripts/Project/Objects/Other/ImageTips.cs

73 lines
2.2 KiB
C#
Raw Permalink 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 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);
}
}