You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public enum TimeClass
{
,
}
public class TimeTool : MonoBehaviour
{
[Header("本地时间Text")]
public Text localText;
public bool localBool;
[Header("倒计时或者计时器")]
public Text text;
public TimeClass timeClass;
private int Minute, Second, CurrentTime;
[Header("传进来倒计时起始秒")]
public int jieTime;
private bool jsqBool, djsBool; //倒计时 和计时器
void Start()
{
// Opentimer();
}
void Update()
{
OpenLocalTime();
Timer();
}
public void Timer()
{
if (djsBool)
{
int timer = jieTime + CurrentTime - (int)(Time.time);
Minute = (timer / 60) % 60;
Second = timer % 60;
if (timer >= 0)
{
if (Minute < 10)
{
if (Second < 10)
{
text.text = "倒计时:" + "0" + Minute + ":0" + Second;
}
else
{
text.text = "倒计时:" + "0" + Minute + ":" + Second;
}
}
else
{
if (Second < 10)
{
text.text = "倒计时:" + Minute + ":0" + Second;
}
else
{
text.text = "倒计时:" + Minute + ":" + Second;
}
}
}
else
{
djsBool = false;
Debug.Log("倒计时结束");
}
}
if (jsqBool)
{
int timer = (int)Time.time - CurrentTime;
Minute = (timer / 60) % 60;
Second = timer % 60;
if (Minute < 10)
{
if (Second < 10)
{
text.text = "学习时长:" + "0" + Minute + ":0" + Second;
}
else
{
text.text = "学习时长:" + "0" + Minute + ":" + Second;
}
}
else
{
if (Second < 10)
{
text.text = "学习时长:" + Minute + ":0" + Second;
}
else
{
text.text = "学习时长:" + Minute + ":" + Second;
}
}
}
}
public void Opentimer()
{
switch (timeClass)
{
case TimeClass.:
CurrentTime = (int)Time.time;
djsBool = true;
break;
case TimeClass.:
CurrentTime = (int)Time.time;
jsqBool = true;
break;
}
}
public void OpenLocalTime()
{
if (localBool && localText != null)
{
localText.text = System.DateTime.Now.Year + "年" + System.DateTime.Now.Month + "月" + System.DateTime.Now.Day + "日" + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute.ToString();
}
}
}