89 lines
2.1 KiB
C#
89 lines
2.1 KiB
C#
using System.Collections;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class FadeImage : IFadeObject
|
|
{
|
|
private readonly Image _image;
|
|
|
|
public FadeImage(Image rawImage)
|
|
{
|
|
_image = rawImage;
|
|
}
|
|
|
|
#region 基本操作
|
|
|
|
public void Show()
|
|
{
|
|
_image.gameObject.SetActive(true);
|
|
_image.color = Color.white;
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
_image.gameObject.SetActive(false);
|
|
_image.color = Color.clear;
|
|
}
|
|
|
|
public void SwitchImage(string imagePath)
|
|
{
|
|
_image.sprite = Resources.Load<Sprite>(imagePath);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 淡入
|
|
|
|
public void FadeIn(float duration)
|
|
{
|
|
_image.gameObject.SetActive(true);
|
|
_image.DOBlendableColor(Color.white, duration);
|
|
}
|
|
|
|
public IEnumerator FadeInSync(float duration)
|
|
{
|
|
_image.gameObject.SetActive(true);
|
|
var tweener = _image.DOBlendableColor(Color.white, duration);
|
|
yield return tweener;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 淡出
|
|
|
|
public void FadeOut(float duration)
|
|
{
|
|
Debug.Log("Fade out");
|
|
_image.gameObject.SetActive(true);
|
|
_image.DOBlendableColor(Color.clear, duration).onComplete += () =>
|
|
{
|
|
_image.gameObject.SetActive(false);
|
|
};
|
|
}
|
|
|
|
public IEnumerator FadeOutSync(float duration)
|
|
{
|
|
_image.gameObject.SetActive(true);
|
|
var tweener = _image.DOBlendableColor(Color.clear, duration);
|
|
if (!tweener.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
// yield return tweener;
|
|
_image.gameObject.SetActive(false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
public IEnumerator MoveTo(Vector3 targetPos, float duration)
|
|
{
|
|
Debug.Log("Image 不能移动");
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|