powerfun-unity/Assets/CountDownAnimation.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2021-09-28 17:51:58 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using DG.Tweening;
using UnityEngine.UI;
public class CountDownAnimation : PFUIPanel
{
// Start is called before the first frame update
void Start()
{
}
public void StartTime(UnityAction action)
{
HandleAnimation("5", action);
}
void HandleAnimation(string s, UnityAction action)
{
GetComponent<Text>().text = s;
transform.GetComponent<RectTransform>().DOScale(Vector3.one * 2, 0.5f).onComplete = () =>
{
transform.GetComponent<RectTransform>().DOScale(Vector3.one * 0.5f, 0.5f).onComplete = ()=>
{
if (s == "Go")
{
action.Invoke();
gameObject.SetActive(false);
return;
}
var flag = int.TryParse(s,out int a);
if (flag)
{
if (a - 1 == 0)
{
HandleAnimation("Go", action);
}
else
{
HandleAnimation((a - 1).ToString(), action);
}
}
};
};
}
// Update is called once per frame
void Update()
{
}
}