2025-09-02 11:08:15 +08:00
|
|
|
|
// UI/UIImageAnimator.cs
|
2025-09-06 12:25:55 +08:00
|
|
|
|
|
|
|
|
|
using Base;
|
2025-09-02 11:08:15 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2025-09-06 12:25:55 +08:00
|
|
|
|
// 引入Base命名空间以使用BaseAnimator
|
|
|
|
|
|
|
|
|
|
namespace Prefab
|
2025-09-02 11:08:15 +08:00
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
|
|
|
public class UIImageAnimator : BaseAnimator // 继承BaseAnimator
|
|
|
|
|
{
|
|
|
|
|
private Image _image; // UI Image组件
|
|
|
|
|
|
|
|
|
|
protected override void ValidateComponent()
|
|
|
|
|
{
|
|
|
|
|
_image = GetComponent<Image>();
|
|
|
|
|
if (_image == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("UIImageAnimator requires an Image component.", this);
|
|
|
|
|
enabled = false; // 禁用脚本如果组件缺失
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void SetDisplaySprite(Sprite sprite)
|
|
|
|
|
{
|
|
|
|
|
if (_image)
|
|
|
|
|
{
|
|
|
|
|
_image.sprite = sprite;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// [可选] 如果UIImageAnimator需要任何Awake后特有的初始化逻辑,可以在这里重写
|
|
|
|
|
// protected override void Awake()
|
|
|
|
|
// {
|
|
|
|
|
// base.Awake(); // 确保调用基类的Awake
|
|
|
|
|
// // 子类特有的初始化
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|