2025-09-08 17:37:12 +08:00

52 lines
1.8 KiB
C#
Raw 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 System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace DongWuYiXue.DaoNiaoShu
{
public class TxtSelectManager : MonoBehaviour
{
TxtOption[] txtOptions;
public TxtOption[] answers;
public void Init()
{
txtOptions = GetComponentsInChildren<TxtOption>();
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判断内容是否完全相同
}
}
}