Files
ZHGD_Web/Assets/Scripts/UI/TitlePage.cs
2025-07-13 23:16:20 +08:00

247 lines
7.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Hanatric.Unity.MonoComponent;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Windows;
public class TitlePage : MonoBehaviour
{
[SerializeField]
private Toggle m_OneToggle;
[SerializeField]
private Toggle m_TwoToggle;
[SerializeField]
private Toggle m_ThreeToggle;
[SerializeField]
private Toggle m_FourToggle;
[SerializeField]
private Toggle m_FiveToggle;
[SerializeField]
private Toggle m_SixToggle;
[SerializeField]
private Toggle m_SevenToggle;
[SerializeField]
private Toggle m_EightToggle;
[SerializeField]
private List<GameObject> m_PageList = new List<GameObject>();
[SerializeField]
private TextMeshProUGUI m_TimeValueText;
[SerializeField]
private TextMeshProUGUI m_TempValueText;
[SerializeField]
private Image m_WeatherImage;
[SerializeField]
public Sprite[] m_WeatherIcons;
[SerializeField]
private GameObject m_LoadingPage;
[SerializeField]
private Image m_LoadingProcess;
[SerializeField]
private Text m_LoadingProcessText;
[SerializeField]
private string m_LastSceneName;
[SerializeField]
private List<string> m_SceneName;
// Start is called before the first frame update
void Start()
{
m_OneToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(0);
}
});
m_TwoToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(1);
}
});
m_ThreeToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(2);
}
});
m_FourToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(3);
}
});
m_FiveToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(4);
}
});
m_SixToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(5);
}
});
m_SevenToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(6);
}
});
m_EightToggle.onValueChanged.AddListener((b) =>
{
if (b)
{
ActivePage(7);
}
});
m_OneToggle.isOn = false;
m_OneToggle.isOn = true;
StopCoroutine("GetWeatherInfo");
StartCoroutine("GetWeatherInfo");
//LoadSceneAsync(m_SceneName[0]);
//ActivePage(0);
}
private IEnumerator GetWeatherInfo()
{
while(true)
{
HttpManager.Instance.Down((w) =>
{
MatchCollection result = System.Text.RegularExpressions.Regex.Matches(w, @"<span><b>.+</b>.+</span>");
string str = "";
string weather = "";
string tem = "";
foreach (Match match in result)
{
str = match.Value;
}
string pattern = "[\u4e00-\u9fa5]+";
MatchCollection matches = Regex.Matches(str, pattern);
foreach (Match match in matches)
{
weather = match.Value;
}
tem = str.Replace("<span>","");
tem = tem.Replace("</span>", "");
tem = tem.Replace(weather, "");
//<span><b>С<><D0A1></b>13 ~ 24<32><34></span>
Debug.Log(weather);
if (weather.Contains("<22><>"))
{
m_WeatherImage.sprite = m_WeatherIcons[0];
}
else if (weather.Contains("ѩ"))
{
m_WeatherImage.sprite = m_WeatherIcons[3];
}
else if (weather.Contains("<22><>"))
{
m_WeatherImage.sprite = m_WeatherIcons[2];
}
else if (weather.Contains("<22><><EFBFBD><EFBFBD>") || weather.Contains("<22><>") || weather.Contains("<22><>"))
{
m_WeatherImage.sprite = m_WeatherIcons[1];
}
else if (weather.Contains("<22><>"))
{
m_WeatherImage.sprite = m_WeatherIcons[4];
}
else if (weather.Contains(<><C9B3>"))
{
m_WeatherImage.sprite = m_WeatherIcons[5];
}
else
{
m_WeatherImage.sprite = m_WeatherIcons[0];
}
m_TempValueText.text = tem;
});
yield return new WaitForSeconds(12800);
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="index"></param>
private void ActivePage(int index)
{
LifeCycleManager.Instance.funMoudle = (FunMoudle)index;
for (int i = 0; i < m_PageList.Count; i++)
{
if (i == index)
{
m_PageList[i].SetActive(true);
LoadSceneAsync(m_SceneName[i]);
continue;
}
m_PageList[i].SetActive(false);
}
}
public void LoadSceneAsync(string sceneName)
{
SceneManager.LoadScene(sceneName);
//StartCoroutine(LoadSceneAsyncCoroutine(sceneName));
}
private IEnumerator LoadSceneAsyncCoroutine(string sceneName)
{
m_LoadingPage.gameObject.SetActive(true);
if (!string.IsNullOrEmpty(m_LastSceneName))
{
AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(m_LastSceneName);
m_LoadingProcess.fillAmount = 0;
m_LoadingProcessText.text = "<22><><EFBFBD><EFBFBD>ж<EFBFBD>س<EFBFBD><D8B3><EFBFBD>0%...";
while (!asyncUnLoad.isDone)
{
float progress = Mathf.Clamp01(asyncUnLoad.progress / 0.9f);
//Debug.Log("Loading progress: " + progress * 100 + "%");
m_LoadingProcess.fillAmount = progress;
m_LoadingProcessText.text = "<22><><EFBFBD><EFBFBD>ж<EFBFBD>س<EFBFBD><D8B3><EFBFBD>" + progress * 100 + "%...";
yield return null;
}
}
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName,LoadSceneMode.Additive);
m_LoadingProcess.fillAmount = 0;
m_LoadingProcessText.text = "<22><><EFBFBD>ڼ<EFBFBD><DABC>س<EFBFBD><D8B3><EFBFBD>0%...";
while (!asyncLoad.isDone)
{
float progress = Mathf.Clamp01(asyncLoad.progress / 0.9f);
//Debug.Log("Loading progress: " + progress * 100 + "%");
m_LoadingProcess.fillAmount = progress;
m_LoadingProcessText.text = "<22><><EFBFBD>ڼ<EFBFBD><DABC>س<EFBFBD><D8B3><EFBFBD>" + progress * 100 + "%...";
yield return null;
}
m_LastSceneName = sceneName;
m_LoadingPage.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
m_TimeValueText.text = DateTime.Now.ToString("HH:mm:ss yyyy.M.d");
}
}