using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using ZXKFramework; namespace DongWuYiXue.DaoNiaoShu { public class TxtSelectManager : MonoBehaviour { TxtOption[] txtOptions; public TxtOption[] answers; public void Init() { txtOptions = GetComponentsInChildren(); for (int i = 0; i < txtOptions.Length; i++) { txtOptions[i].Interactable(); txtOptions[i].UnSelect(); txtOptions[i].SetNormalColor(); } } public bool Check() { //判断逻辑 TxtOption[] yourSelect = txtOptions.ToList().FindAll(e => e.isSelect == true).ToArray(); bool isTrue = AreArraysEqual(yourSelect, answers); for (int i = 0; i < answers.Length; i++) { answers[i].SetRightColor(); } for (int i = 0; i < yourSelect.Length; i++) { if (!answers.Contains(yourSelect[i])) { yourSelect[i].SetFalseColor(); } } for (int i = 0; i < txtOptions.Length; i++) { txtOptions[i].UnInteractable(); } return isTrue; } bool AreArraysEqual(TxtOption[] array1, TxtOption[] array2) { if (array1 == null && array2 == null) return true; // 如果都为null,返回true if (array1 == null || array2 == null) return false; // 如果任一数组为null,返回false if (array1.Length != array2.Length) return false; // 如果长度不同,返回false return array1.SequenceEqual(array2); // 使用SequenceEqual判断内容是否完全相同 } public string GetYourAnswer() { TxtOption[] yourSelect = txtOptions.ToList().FindAll(e => e.isSelect == true).ToArray(); string str = ""; for (int i = 0; i < yourSelect.Length; i++) { str += yourSelect[i].name; } if(string.IsNullOrEmpty(str)) { return "空"; } return str; } } }