324 lines
9.1 KiB
C#
324 lines
9.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
|
|
public class UIInput_AnHuiBaoShiData : UIPanelData
|
|
{
|
|
}
|
|
public partial class UIInput_AnHuiBaoShi : UIPanel
|
|
{
|
|
|
|
public int CurrentInputIndex;//当前索引次数
|
|
[Header("所有的图片")]
|
|
public Image[] images;
|
|
|
|
[Header("设置最大目标值")]
|
|
public float[] targetMax; // 设置最大目标值
|
|
[Header("设置最小目标值")]
|
|
public float[] targetMin; // 设置最小目标值
|
|
|
|
[Header("最大目标值错误次数")]
|
|
public int errowIntMax = 0;//最大目标值错误次数
|
|
[Header("最小目标值错误次数")]
|
|
public int errowIntMin = 0;//最小目标值错误次数
|
|
[Header("错误弹窗")]
|
|
public GameObject errowTip;//错误弹窗
|
|
public Button errowTipClickBtn;//错误弹窗,确认按钮
|
|
|
|
|
|
private string tMP_InputField1Value= "1.769";
|
|
|
|
private string tMP_InputField2Value= "1.762";
|
|
|
|
private string tMP_InputField3Value = "0.007";
|
|
|
|
public int tMP_InputField1ErrowIndex = 0;
|
|
public int tMP_InputField2ErrowIndex = 0;
|
|
public int tMP_InputField3ErrowIndex = 0;
|
|
|
|
|
|
|
|
public GameObject ZheSheInput;//输入三个数值的输入框
|
|
|
|
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UIInput_AnHuiBaoShiData ?? new UIInput_AnHuiBaoShiData();
|
|
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
|
|
|
|
ZheSheInput.gameObject.SetActive(false);
|
|
|
|
CurrentInputIndex = 0;
|
|
errowIntMax = 0;
|
|
errowIntMin = 0;
|
|
|
|
|
|
InputFieldmax.onEndEdit.RemoveAllListeners();
|
|
InputFieldmin.onEndEdit.RemoveAllListeners();
|
|
|
|
InputFieldmax.onEndEdit.AddListener(CheckInputMax);
|
|
InputFieldmin.onEndEdit.AddListener(CheckInputMin);
|
|
|
|
tMP_InputField1.onEndEdit.RemoveAllListeners();
|
|
tMP_InputField2.onEndEdit.RemoveAllListeners();
|
|
tMP_InputField3.onEndEdit.RemoveAllListeners();
|
|
tMP_InputField1.onEndEdit.AddListener(CheacktMP_InputField1String);
|
|
tMP_InputField2.onEndEdit.AddListener(CheacktMP_InputField2String);
|
|
tMP_InputField3.onEndEdit.AddListener(CheacktMP_InputField3String);
|
|
|
|
}
|
|
public void CheackAllInputField()
|
|
{
|
|
|
|
if (tMP_InputField1.text== tMP_InputField1Value && tMP_InputField2.text == tMP_InputField2Value&&
|
|
tMP_InputField3.text == tMP_InputField3Value )
|
|
{
|
|
|
|
StringEventSystem.Global.Send("InputUI使用结束");
|
|
}
|
|
|
|
}
|
|
|
|
private void CheacktMP_InputField1String(string userInput)
|
|
{
|
|
if (userInput==tMP_InputField1Value)
|
|
{
|
|
tMP_InputField1.text = tMP_InputField1Value;
|
|
tMP_InputField1.DeactivateInputField();
|
|
tMP_InputField1.readOnly = true;
|
|
CheackAllInputField();
|
|
}
|
|
else
|
|
{
|
|
tMP_InputField1ErrowIndex++;
|
|
if (tMP_InputField1ErrowIndex>=3)
|
|
{
|
|
tMP_InputField1.text = tMP_InputField1Value;
|
|
tMP_InputField1.DeactivateInputField();
|
|
tMP_InputField1.readOnly = true;
|
|
CheackAllInputField();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
|
|
errowTip.gameObject.SetActive(true);
|
|
tMP_InputField1.text = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
private void CheacktMP_InputField2String(string userInput)
|
|
{
|
|
if (userInput == tMP_InputField2Value)
|
|
{
|
|
tMP_InputField2.text = tMP_InputField2Value;
|
|
tMP_InputField2.DeactivateInputField();
|
|
tMP_InputField2.readOnly = true; CheackAllInputField();
|
|
}
|
|
else
|
|
{
|
|
tMP_InputField2ErrowIndex++;
|
|
if (tMP_InputField2ErrowIndex >= 3)
|
|
{
|
|
tMP_InputField2.text = tMP_InputField2Value;
|
|
tMP_InputField2.DeactivateInputField();
|
|
tMP_InputField2.readOnly = true;
|
|
CheackAllInputField();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
|
|
errowTip.gameObject.SetActive(true);
|
|
tMP_InputField2.text = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CheacktMP_InputField3String(string userInput)
|
|
{
|
|
if (userInput == tMP_InputField3Value)
|
|
{
|
|
tMP_InputField3.text = tMP_InputField3Value;
|
|
tMP_InputField3.DeactivateInputField();
|
|
tMP_InputField3.readOnly = true; CheackAllInputField();
|
|
}
|
|
else
|
|
{
|
|
tMP_InputField3ErrowIndex++;
|
|
if (tMP_InputField3ErrowIndex >= 3)
|
|
{
|
|
tMP_InputField3.text = tMP_InputField3Value;
|
|
tMP_InputField3.DeactivateInputField();
|
|
tMP_InputField3.readOnly = true;
|
|
CheackAllInputField();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
|
|
errowTip.gameObject.SetActive(true);
|
|
tMP_InputField3.text = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入最大值
|
|
/// </summary>
|
|
/// <param name="userInput"></param>
|
|
private void CheckInputMax(string userInput)
|
|
{
|
|
var v = targetMax[CurrentInputIndex].ToString();
|
|
if (v != userInput)
|
|
{
|
|
//第四次,填入正确答案
|
|
if (errowIntMax >= 2)
|
|
{
|
|
|
|
InputFieldmax.text = targetMax[CurrentInputIndex].ToString();
|
|
InputFieldmax.DeactivateInputField();
|
|
InputFieldmax.readOnly = true;
|
|
Invoke("SetNextInput", 0.3f);
|
|
return;
|
|
}
|
|
errowIntMax++;
|
|
errowTip.gameObject.SetActive(true);
|
|
InputFieldmax.text = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
//正确++
|
|
else
|
|
{
|
|
Debug.Log("填写数值正确");
|
|
userInput= targetMax.ToString();
|
|
SetNextInput();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入最小值
|
|
/// </summary>
|
|
/// <param name="userInput"></param>
|
|
private void CheckInputMin(string userInput)
|
|
{
|
|
|
|
var v = targetMin[CurrentInputIndex].ToString();
|
|
if (v != userInput)
|
|
{
|
|
//第四次,填入正确答案
|
|
if (errowIntMin >= 2)
|
|
{
|
|
|
|
InputFieldmin.text = targetMin[CurrentInputIndex].ToString();
|
|
InputFieldmin.DeactivateInputField();
|
|
InputFieldmin.readOnly = true;
|
|
|
|
Invoke("SetNextInput",0.3f);
|
|
return;
|
|
}
|
|
errowIntMin++;
|
|
errowTip.gameObject.SetActive(true);
|
|
InputFieldmin.text = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
//正确++
|
|
else
|
|
{
|
|
Debug.Log("填写数值正确");
|
|
userInput = targetMax.ToString();
|
|
SetNextInput();
|
|
|
|
}
|
|
}
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
StringEventSystem.Global.Send("InputUI使用结束");
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
|
|
private void SetNextInput()
|
|
{
|
|
if (InputFieldmax.text == targetMax[CurrentInputIndex].ToString()&& InputFieldmin.text ==targetMin[CurrentInputIndex].ToString())
|
|
{
|
|
//InputFieldmax.ActivateInputField();
|
|
//InputFieldmin.ActivateInputField();
|
|
//重置
|
|
errowTip.gameObject.SetActive(false);
|
|
errowIntMax = 0;
|
|
errowIntMin = 0;
|
|
|
|
InputFieldmax.readOnly = false;
|
|
InputFieldmin.readOnly = false;
|
|
|
|
|
|
InputFieldmax.text = string.Empty;
|
|
InputFieldmin.text = string.Empty;
|
|
|
|
|
|
|
|
|
|
CurrentInputIndex++;
|
|
if (CurrentInputIndex < images.Length)
|
|
{
|
|
|
|
// 先递增索引
|
|
|
|
foreach (var item in images)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
images[CurrentInputIndex].gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
foreach (var item in images)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
ZheSheInput.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|