56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using ZXKFramework;
|
|||
|
|
namespace YiLiao.JingMaiLiuZhiZhen
|
|||
|
|
{
|
|||
|
|
public class SpriteToUIImage : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public SpriteRenderer spriteRenderer;
|
|||
|
|
public Image uiImage;
|
|||
|
|
public Animator spriteAnimator; // <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>SpriteRenderer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Animator<6F><72><EFBFBD><EFBFBD>
|
|||
|
|
Coroutine coroutine;
|
|||
|
|
private bool isAnimationFinished = false;
|
|||
|
|
private void OnEnable()
|
|||
|
|
{
|
|||
|
|
// <20><>GameObject<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
|
isAnimationFinished = false;
|
|||
|
|
if (spriteAnimator != null)
|
|||
|
|
{
|
|||
|
|
spriteAnimator.Play(spriteAnimator.GetCurrentAnimatorClipInfo(0)[0].clip.name);
|
|||
|
|
coroutine = Game.Instance?.IEnumeratorManager.Run(4f, () => {
|
|||
|
|
isAnimationFinished = true;
|
|||
|
|
gameObject.SetActive(false);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnDisable()
|
|||
|
|
{
|
|||
|
|
// <20><>GameObject<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>
|
|||
|
|
isAnimationFinished = true;
|
|||
|
|
Game.Instance?.IEnumeratorManager.Stop(coroutine);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
if (spriteRenderer != null && uiImage != null && !isAnimationFinished)
|
|||
|
|
{
|
|||
|
|
uiImage.sprite = spriteRenderer.sprite;
|
|||
|
|
//CheckAnimationState();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//void CheckAnimationState()
|
|||
|
|
//{
|
|||
|
|
// if (spriteAnimator != null)
|
|||
|
|
// {
|
|||
|
|
// AnimatorStateInfo currentState = spriteAnimator.GetCurrentAnimatorStateInfo(0);
|
|||
|
|
// if (currentState.normalizedTime >= 1f && !currentState.loop)
|
|||
|
|
// {
|
|||
|
|
// isAnimationFinished = true;
|
|||
|
|
// gameObject.SetActive(false);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
}
|