Added Timer

New version featuring a timer
This commit is contained in:
Gerard Gascón 2021-06-11 19:34:49 +02:00 committed by GitHub
parent f7c4067db4
commit 750d7f6b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 186 additions and 23 deletions

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using TMPro;
namespace SimpleTools.Timer{
public static class TimerUtility {
public static Timer SetupTimer(this TMP_Text container, TimerType timerType, float countdownTime = 60f){
Timer t = container.gameObject.AddComponent<Timer>();
float elapsedTime = 0f;
string text = string.Empty;
TimeSpan timePlaying = TimeSpan.Zero;
switch (timerType){
case TimerType.Countdown:
elapsedTime = countdownTime;
timePlaying = TimeSpan.FromSeconds(elapsedTime);
text = timePlaying.ToString("m':'ss'.'ff");
break;
case TimerType.Clock:
text = DateTime.Now.ToString("HH:mm:ss");
break;
}
t.Setup(elapsedTime, true, timePlaying, container, timerType, text);
return t;
}
}
}