VirtualFramework/Assets/Scripts/UI/UIInput_AnHuiBaoShi.cs

316 lines
8.9 KiB
C#
Raw Normal View History

2025-02-06 17:23:24 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
2025-02-07 18:03:05 +08:00
using System.ComponentModel;
using System.Linq;
2025-02-06 17:23:24 +08:00
namespace QFramework.Example
{
2025-02-07 18:03:05 +08:00
2025-02-06 17:23:24 +08:00
public class UIInput_AnHuiBaoShiData : UIPanelData
{
}
public partial class UIInput_AnHuiBaoShi : UIPanel
2025-02-07 18:03:05 +08:00
{
public int CurrentInputIndex;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Header("<22><><EFBFBD>е<EFBFBD>ͼƬ")]
public Image[] images;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ")]
public float[] targetMax; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СĿ<D0A1><C4BF>ֵ")]
public float[] targetMin; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СĿ<D0A1><C4BF>ֵ
[Header("<22><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public int errowIntMax = 0;//<2F><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Header("<22><>СĿ<D0A1><C4BF>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public int errowIntMin = 0;//<2F><>СĿ<D0A1><C4BF>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Header("<22><><EFBFBD>󵯴<EFBFBD>")]
public GameObject errowTip;//<2F><><EFBFBD>󵯴<EFBFBD>
public Button errowTipClickBtn;//<2F><><EFBFBD>󵯴<EFBFBD><F3B5AFB4><EFBFBD>ȷ<EFBFBD>ϰ<EFBFBD>ť
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;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
protected override void OnInit(IUIData uiData = null)
2025-02-06 17:23:24 +08:00
{
mData = uiData as UIInput_AnHuiBaoShiData ?? new UIInput_AnHuiBaoShiData();
2025-02-07 18:03:05 +08:00
2025-02-06 17:23:24 +08:00
}
protected override void OnOpen(IUIData uiData = null)
{
2025-02-07 18:03:05 +08:00
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 )
{
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
StringEventSystem.Global.Send("InputUIʹ<49>ý<EFBFBD><C3BD><EFBFBD>");
}
2025-02-06 17:23:24 +08:00
}
2025-02-07 18:03:05 +08:00
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;
}
}
}
private void CheckInputMax(string userInput)
{
var v = targetMax[CurrentInputIndex].ToString();
if (v != userInput)
{
//<2F><><EFBFBD>ĴΣ<C4B4><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
if (errowIntMax >= 1)
{
InputFieldmax.text = targetMax[CurrentInputIndex].ToString();
InputFieldmax.DeactivateInputField();
InputFieldmax.readOnly = true;
SetNextInput();
return;
}
errowIntMax++;
errowTip.gameObject.SetActive(true);
InputFieldmax.text = string.Empty;
}
//<2F><>ȷ++
else
{
Debug.Log("<22><>д<EFBFBD><D0B4>ֵ<EFBFBD><D6B5>ȷ");
userInput= targetMax.ToString();
SetNextInput();
}
}
private void CheckInputMin(string userInput)
{
var v = targetMin[CurrentInputIndex].ToString();
if (v != userInput)
{
//<2F><><EFBFBD>ĴΣ<C4B4><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
if (errowIntMin >= 1)
{
InputFieldmin.text = targetMin[CurrentInputIndex].ToString();
InputFieldmin.DeactivateInputField();
InputFieldmin.readOnly = true;
SetNextInput();
return;
}
errowIntMin++;
errowTip.gameObject.SetActive(true);
InputFieldmin.text = string.Empty;
}
//<2F><>ȷ++
else
{
Debug.Log("<22><>д<EFBFBD><D0B4>ֵ<EFBFBD><D6B5>ȷ");
userInput = targetMax.ToString();
SetNextInput();
}
}
protected override void OnShow()
2025-02-06 17:23:24 +08:00
{
}
protected override void OnHide()
{
StringEventSystem.Global.Send("InputUIʹ<49>ý<EFBFBD><C3BD><EFBFBD>");
}
protected override void OnClose()
{
}
2025-02-07 18:03:05 +08:00
private void SetNextInput()
{
if (InputFieldmax.text == targetMax[CurrentInputIndex].ToString()&& InputFieldmin.text ==targetMin[CurrentInputIndex].ToString())
{
//InputFieldmax.ActivateInputField();
//InputFieldmin.ActivateInputField();
//<2F><><EFBFBD><EFBFBD>
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)
{
Debug.Log(CurrentInputIndex+"??????????");
// <20>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
}
}
}
}
2025-02-06 17:23:24 +08:00
}