45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class EventPartnerComponent : MonoBehaviour
|
||
{
|
||
public Image ComponentImage;
|
||
public GameObject FxLvlUp, FxAddScore;
|
||
public GameObject[] FxProgress;
|
||
private EventPartnerAct.Context _context;
|
||
[Tooltip("加分特效播放时长,一般默认为2")] [SerializeField] private float jiandaAddScoreFxDuration = 2f;
|
||
[Tooltip("升级特效播放时长,一般默认为2")] [SerializeField] private float jiandaUpgradeFxDuration = 2f;
|
||
|
||
public void Init(EventPartnerAct.Context ctx, int targetGrade, string imgUri)
|
||
{
|
||
_context = ctx;
|
||
SetComponent(targetGrade, imgUri);
|
||
}
|
||
|
||
public void SetComponent(int targetGrade, string imgUri)
|
||
{
|
||
ComponentImage.sprite = _context.GetSprite(imgUri);
|
||
for (int i = 0; i < FxProgress.Length; i++)
|
||
{
|
||
if (FxProgress[i] == null)
|
||
continue;
|
||
FxProgress[i].SetActive(i == targetGrade);
|
||
}
|
||
}
|
||
public async void UpgradeComponent(int targetGrade, string imgUri)
|
||
{
|
||
FxLvlUp.SetActive(false);
|
||
FxLvlUp.SetActive(true);
|
||
SetComponent(targetGrade, imgUri);
|
||
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(jiandaUpgradeFxDuration));
|
||
FxLvlUp.SetActive(false);
|
||
}
|
||
public async void PlayAddScoreFx()
|
||
{
|
||
FxAddScore.SetActive(false);
|
||
FxAddScore.SetActive(true);
|
||
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(jiandaAddScoreFxDuration));
|
||
FxAddScore.SetActive(false);
|
||
}
|
||
}
|