2024-12-26 18:03:45 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class Chooselitem8 : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject prefab;
|
|
|
|
|
public Transform PrefabTransform;
|
|
|
|
|
public Text text;
|
|
|
|
|
public static Chooselitem8 Instance;
|
|
|
|
|
public JSONReader JSONReader;
|
2024-12-26 23:18:09 +08:00
|
|
|
|
|
|
|
|
|
public Text Time;// Ҫ<>ı<EFBFBD><C4B1><EFBFBD>ɫ<EFBFBD><C9AB>Text<78><74><EFBFBD><EFBFBD>
|
|
|
|
|
private bool isRed = false; // <20><>ǰ<EFBFBD><C7B0>ɫ<EFBFBD>Ƿ<EFBFBD><C7B7>Ǻ<EFBFBD>ɫ
|
|
|
|
|
private float timeInSeconds; // <20><>ǰʱ<C7B0>䣬<EFBFBD><E4A3AC>λΪ<CEBB><CEAA>
|
|
|
|
|
public GameObject Timeobject;
|
|
|
|
|
private bool isRunning = true; // <20><><EFBFBD>Ƽ<EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-12-26 22:30:20 +08:00
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
2024-12-26 23:18:09 +08:00
|
|
|
|
InvokeRepeating(nameof(UpdateTimeDisplay), 0f, 1f);
|
2024-12-26 22:30:20 +08:00
|
|
|
|
}
|
2024-12-26 18:03:45 +08:00
|
|
|
|
public void CreateItem(int ID)
|
|
|
|
|
{
|
2024-12-26 23:18:09 +08:00
|
|
|
|
GameObject newitem = Instantiate(prefab, PrefabTransform);
|
2024-12-26 18:03:45 +08:00
|
|
|
|
foreach (var item in JSONReader.LanguageDictionary)
|
|
|
|
|
{
|
|
|
|
|
Language languageData = item.Value;
|
2024-12-26 23:18:09 +08:00
|
|
|
|
if (languageData.ID == ID)
|
2024-12-26 18:03:45 +08:00
|
|
|
|
{
|
2024-12-26 23:18:09 +08:00
|
|
|
|
text.text = languageData.Text;
|
2024-12-26 18:03:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-26 23:18:09 +08:00
|
|
|
|
private void UpdateTimeDisplay()
|
|
|
|
|
{
|
|
|
|
|
if (!isRunning) return;
|
|
|
|
|
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>Ϊ "MM:SS"
|
|
|
|
|
string formattedTime = FormatTime(timeInSeconds);
|
|
|
|
|
if (Time != null)
|
|
|
|
|
{
|
|
|
|
|
Time.text = formattedTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨ÿ<E4A3A8>룩
|
|
|
|
|
timeInSeconds++;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ﵽ10<31><30>
|
|
|
|
|
if (timeInSeconds >= 12)
|
|
|
|
|
{
|
|
|
|
|
isRunning = false; // ֹͣ<CDA3><D6B9>ʱ
|
|
|
|
|
CancelInvoke(nameof(UpdateTimeDisplay)); // ֹͣInvoke<6B><65><EFBFBD><EFBFBD>
|
|
|
|
|
Timeobject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void ColorText()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(ChangeTextColor());
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Э<>̣<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>л<EFBFBD>Text<78><74><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerator ChangeTextColor()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (Time != null)
|
|
|
|
|
{
|
|
|
|
|
// <20>л<EFBFBD><D0BB><EFBFBD>ɫ
|
|
|
|
|
Time.color = isRed ? Color.white : Color.red;
|
|
|
|
|
isRed = !isRed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>ȴ<EFBFBD>1<EFBFBD><31>
|
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><>ʽ<EFBFBD><CABD>ʱ<EFBFBD><CAB1>Ϊ "MM:SS"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">ʱ<>䣨<EFBFBD>룩</param>
|
|
|
|
|
/// <returns><3E><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|
|
|
|
private string FormatTime(float time)
|
|
|
|
|
{
|
|
|
|
|
int minutes = Mathf.FloorToInt(time / 60); // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
int seconds = Mathf.FloorToInt(time % 60); // <20><>
|
|
|
|
|
return $"{minutes:00}:{seconds:00}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 18:03:45 +08:00
|
|
|
|
|
|
|
|
|
}
|