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(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) { _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; } } }