powerfun-unity/Assets/CountDownAnimation.cs

61 lines
1.7 KiB
C#
Raw Permalink 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,UnityAction action2)
2021-09-28 17:51:58 +08:00
{
HandleAnimation("5", action, action2);
2021-09-28 17:51:58 +08:00
}
void HandleAnimation(string s, UnityAction action, UnityAction action2)
2021-09-28 17:51:58 +08:00
{
2021-09-28 20:35:05 +08:00
var text = transform.Find("Text");
text.GetComponent<Text>().text = s;
text.transform.GetComponent<RectTransform>().DOScale(Vector3.one * 2, 0.5f).onComplete = () =>
2021-09-28 17:51:58 +08:00
{
2021-09-28 20:35:05 +08:00
text.GetComponent<RectTransform>().DOScale(Vector3.one * 0.5f, 0.5f).onComplete = ()=>
2021-09-28 17:51:58 +08:00
{
if (s == "Go")
{
action.Invoke();
gameObject.SetActive(false);
return;
}
var flag = int.TryParse(s,out int a);
if (flag)
{
if (a == 1 && action2 != null)
{
action2.Invoke();
}
2021-09-28 17:51:58 +08:00
if (a - 1 == 0)
{
HandleAnimation("Go", action, action2);
2021-09-28 17:51:58 +08:00
}
else
2021-09-28 17:51:58 +08:00
{
HandleAnimation((a - 1).ToString(), action, action2);
2021-09-28 17:51:58 +08:00
}
}
};
};
}
// Update is called once per frame
void Update()
{
}
}