赞
踩
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class UIPalpating : MonoBehaviour
- {
- /// <summary>
- /// 物体的Image组件
- /// </summary>
- Image UIImage = null;
- /// <summary>
- /// 当前颜色
- /// </summary>
- Color UIColor = new Color(1, 1, 1, 1);
- /// <summary>
- /// 保存原有状态
- /// </summary>
- float oldColorValue = 0;
- /// <summary>
- /// 闪烁标志
- /// </summary>
- bool palpatFlag = true;
- /// <summary>
- /// 闪烁速度
- /// </summary>
- [Tooltip("闪烁速度")]
- [Range(1f, 15f)] public float PalpatSpeed = 1f;
- /// <summary>
- /// 闪烁标志
- /// </summary>
- [Tooltip("闪烁标志")]
- public bool isOn = false;
- void Start()
- {
- UIImage = GetComponent<Image>();
- if (UIImage != null)
- {
- UIColor = UIImage.color;
- oldColorValue = UIColor.a;
- }
- }
- void Update()
- {
- try
- {
- if (isOn && UIImage != null)
- {
- UIAutoPalpating();
- }
- }
- catch (System.Exception ex)
- {
- Debug.Log(ex.Message);
- }
- }
- /// <summary>
- /// UI闪动
- /// </summary>
- void UIAutoPalpating()
- {
- if (UIImage.color.a <= 0)
- {
- palpatFlag = true; // 加
- }
- else if (UIImage.color.a >= oldColorValue)
- {
- palpatFlag = false; // 减
- }
- if (palpatFlag)
- {
- UIColor.a += Time.deltaTime * 0.5f * PalpatSpeed;
- }
- else
- {
- UIColor.a -= Time.deltaTime * 0.5f * PalpatSpeed;
- }
- UIImage.color = UIColor;
- }
- /// <summary>
- /// UI恢复
- /// </summary>
- public void UIAutoReset()
- {
- isOn = false;
- UIColor.a = 1f;
- UIImage.color = UIColor;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。