using SK.Framework; using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; public class NewLogic : MonoBehaviour { public GameObject firstCam; public GameObject thirdCam; public List partTogs = new List(); public TextMeshProUGUI pingfen; // Start is called before the first frame update void Start() { foreach (var part in partTogs) { part.onValueChanged.AddListener((isOn) => OnToggleValueChanged(part, isOn)); } RandomScore(); RandomTime(); } /// /// Toggle值改变时的回调 /// private void OnToggleValueChanged(Toggle toggle, bool isOn) { if (isOn) { if (toggle.name == "first") { ChangeCamToFirst(); } else { ChangeCamToThird(); } } } void LateUpdate() { if (Input.GetKeyDown(KeyCode.Alpha1)) { } if (Input.GetKeyDown(KeyCode.Alpha2)) { } } public void ChangeCamToFirst() { if (firstCam.gameObject.activeInHierarchy) return; firstCam.SetActive(true); thirdCam.SetActive(false); } public void ChangeCamToThird() { if (thirdCam.gameObject.activeInHierarchy) return; thirdCam.SetActive(true); firstCam.SetActive(false); } /// /// 部件展示场景 /// public void LoadSceneToNew() { SceneLoader.LoadAsync("PartKnow"); } /// /// 返回主场景 /// public void ReturnMainScene() { SceneLoader.LoadAsync("GameSencePC"); } public Text timeText; public void RandomTime() { int min = Random.Range(10, 14); int sec=Random.Range(10, 50); timeText.text = "耗时:" + "" + min.ToString() + ":" + sec.ToString() + ""; } public List textMeshProUGUIs = new List(); public TextMeshProUGUI score; private int AllScore; public void RandomScore() { foreach (var text in textMeshProUGUIs) { int result=Random.Range(4, int.Parse( text.name)+1); AllScore += result; ReplaceNumberInColorTag(text, result); } ReplaceNumberInColorTag(score, AllScore); ShowResult(AllScore); } void ShowResult(int score) { if(score>=90&&score<100) { pingfen.text = "评分:" + "" + "优秀" + ""; } if(score>=80&&score<90) { pingfen.text = "评分:" + "" + "良好" + ""; } if(score<80&&score>=70) { pingfen.text = "评分:" + "" + "一般" + ""; } if(score<70&&score>=60) { pingfen.text = "评分:" + "" + "需改进" + ""; } if(score<60) { pingfen.text = "评分:" + "" + "差" + ""; } } /// /// 修复版本:正确替换颜色标签内的数字 /// public void ReplaceNumberInColorTag(TextMeshProUGUI text, int newNumber, string colorHex = "#6CFFE7") { if (text == null) return; string originalText = text.text; // 方法1:使用 MatchEvaluator 避免 $ 字符问题 string pattern = $@"(\d+)"; string newText = Regex.Replace(originalText, pattern, match => $"{newNumber}"); text.text = newText; } public void ReloadScene() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }