add:添加UI逻辑内容

master
zc 2024-11-07 22:49:10 +08:00
parent 2f60e3557b
commit 775ef42a74
12 changed files with 107 additions and 55 deletions

View File

@ -17,10 +17,10 @@ namespace ZC
public override void Init()
{
base.Init();
this.txt_Title = self.transform.FindChildDeep<TMP_Text>("txt_Title");
this.txt_Content = self.transform.FindChildDeep<TMP_Text>("txt_Content");
this.img_Pic = self.transform.FindChildDeep<Image>("img_Pic");
this.btn_Close = self.transform.FindChildDeep<Button>("btn_Close");
this.txt_Title = GetValue<TMP_Text>("txt_Title");
this.txt_Content = GetValue<TMP_Text>("txt_Content");
this.img_Pic = GetValue<Image>("img_Pic");
this.btn_Close = GetValue<Button>("btn_Close");
btn_Close.onClick.AddListener(ClickClose);
}

View File

@ -38,30 +38,30 @@ namespace ZC
public override void Init()
{
base.Init();
txt_Title = _uiGameObjectBinding.GetValue("txt_Title").GetComponent<TMP_Text>();
txt_TrueOption = _uiGameObjectBinding.GetValue("txt_TrueOption").GetComponent<TMP_Text>();
txt_JXContent = _uiGameObjectBinding.GetValue("txt_JXContent").GetComponent<TMP_Text>();
txt_Label0 = _uiGameObjectBinding.GetValue("txt_Label0").GetComponent<TMP_Text>();
txt_Label1 = _uiGameObjectBinding.GetValue("txt_Label1").GetComponent<TMP_Text>();
txt_Label2 = _uiGameObjectBinding.GetValue("txt_Label2").GetComponent<TMP_Text>();
txt_Label3 = _uiGameObjectBinding.GetValue("txt_Label3").GetComponent<TMP_Text>();
tog_Option0 = _uiGameObjectBinding.GetValue("tog_Option0").GetComponent<Toggle>();
tog_Option1 = _uiGameObjectBinding.GetValue("tog_Option1").GetComponent<Toggle>();
tog_Option2 = _uiGameObjectBinding.GetValue("tog_Option2").GetComponent<Toggle>();
tog_Option3 = _uiGameObjectBinding.GetValue("tog_Option3").GetComponent<Toggle>();
btn_Last = _uiGameObjectBinding.GetValue("btn_Last").GetComponent<Button>();
btn_Close = _uiGameObjectBinding.GetValue("btn_Close").GetComponent<Button>();
btn_Next = _uiGameObjectBinding.GetValue("btn_Next").GetComponent<Button>();
Answer = _uiGameObjectBinding.GetValue("Answer").GetComponent<Transform>();
Result = _uiGameObjectBinding.GetValue("Result").GetComponent<Transform>();
txt_TrueCount = _uiGameObjectBinding.GetValue("txt_TrueCount").GetComponent<TMP_Text>();
txt_ScoreCount = _uiGameObjectBinding.GetValue("txt_ScoreCount").GetComponent<TMP_Text>();
txt_FalseCount = _uiGameObjectBinding.GetValue("txt_FalseCount").GetComponent<TMP_Text>();
btn_TryAgain = _uiGameObjectBinding.GetValue("btn_TryAgain").GetComponent<Button>();
btn_Finish = _uiGameObjectBinding.GetValue("btn_Finish").GetComponent<Button>();
txt_Title = GetValue<TMP_Text>("txt_Title");
txt_TrueOption = GetValue<TMP_Text>("txt_TrueOption");
txt_JXContent = GetValue<TMP_Text>("txt_JXContent");
txt_Label0 = GetValue<TMP_Text>("txt_Label0");
txt_Label1 = GetValue<TMP_Text>("txt_Label1");
txt_Label2 = GetValue<TMP_Text>("txt_Label2");
txt_Label3 = GetValue<TMP_Text>("txt_Label3");
tog_Option0 = GetValue<Toggle>("tog_Option0");
tog_Option1 = GetValue<Toggle>("tog_Option1");
tog_Option2 = GetValue<Toggle>("tog_Option2");
tog_Option3 = GetValue<Toggle>("tog_Option3");
btn_Last = GetValue<Button>("btn_Last");
btn_Close = GetValue<Button>("btn_Close");
btn_Next = GetValue<Button>("btn_Next");
Answer = GetValue<Transform>("Answer");
Result = GetValue<Transform>("Result");
txt_TrueCount = GetValue<TMP_Text>("txt_TrueCount");
txt_ScoreCount = GetValue<TMP_Text>("txt_ScoreCount");
txt_FalseCount = GetValue<TMP_Text>("txt_FalseCount");
btn_TryAgain = GetValue<Button>("btn_TryAgain");
btn_Finish = GetValue<Button>("btn_Finish");
btn_Last.onClick.AddListener(ClickLastButton);
btn_Close.onClick.AddListener(ClickCloseButton);

View File

@ -0,0 +1,21 @@
using TMPro;
namespace ZC
{
[UIType(UIType.BigTipsUI)]
public class BigTipsUI : UIBase
{
private TMP_Text txt_Tips;
public override void Init()
{
base.Init();
txt_Tips = GetValue<TMP_Text>("txt_Tips");
}
public void SetData(string str)
{
txt_Tips.text = str;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8092e0a6ecd1401bad5f73c247b49aa5
timeCreated: 1730989169

View File

@ -16,9 +16,9 @@ namespace ZC
public override void Init()
{
base.Init();
this.txt_Title = self.transform.FindChildDeep<TMP_Text>("txt_Title");
this.txt_Content = self.transform.FindChildDeep<TMP_Text>("txt_Content");
this.btn_Close = self.transform.FindChildDeep<Button>("btn_Close");
this.txt_Title = GetValue<TMP_Text>("txt_Title");
this.txt_Content = GetValue<TMP_Text>("txt_Content");
this.btn_Close = GetValue<Button>("btn_Close");
btn_Close.onClick.AddListener(ClickClose);
}

View File

@ -1,4 +1,5 @@
using TMPro;
using System;
using TMPro;
using Unity.Loader;
using UnityEngine.UI;
@ -7,7 +8,7 @@ namespace ZC
[UIType(UIType.MainUI)]
public class MainUI : UIBase
{
private Button btn_Tips;
private Button btn_Start;
private TMP_Text txt_Score;
private TMP_Text txt_Progress;
private TMP_Text txt_Time;
@ -15,18 +16,21 @@ namespace ZC
public override void Init()
{
base.Init();
btn_Tips = self.transform.FindChildDeep<Button>("btn_Tips");
txt_Score = self.transform.FindChildDeep<TMP_Text>("txt_Score");
txt_Progress = self.transform.FindChildDeep<TMP_Text>("txt_Progress");
txt_Time = self.transform.FindChildDeep<TMP_Text>("txt_Time");
btn_Start = GetValue<Button>("btn_Start");
txt_Score = GetValue<TMP_Text>("txt_Score");
txt_Progress = GetValue<TMP_Text>("txt_Progress");
txt_Time = GetValue<TMP_Text>("txt_Time");
btn_Tips.onClick.AddListener(OnClickBtnTips);
Global.Instance.runTime += UpdateTime;
btn_Start.onClick.AddListener(OnClickBtnStart);
Global.Instance.updateTime += UpdateTime;
Global.Instance.updateScore += UpdateScore;
Global.Instance.updateProgress += UpdateProgress;
}
private void UpdateTime(string obj)
{
txt_Time.text = $"实训时间:{obj}";
var dateTime = System.DateTime.Now;
txt_Time.text = $"实训时间:{dateTime.Year}年{dateTime.Month}月{dateTime.Day}日";
}
private void UpdateScore(string obj)
@ -36,12 +40,11 @@ namespace ZC
private void UpdateProgress(string obj)
{
txt_Progress.text = $"实训进度:{obj}";
txt_Progress.text = $"实训进度:{obj}%";
}
private void OnClickBtnTips()
private void OnClickBtnStart()
{
}
}
}

View File

@ -15,9 +15,9 @@ namespace ZC
public override void Init()
{
base.Init();
this.txt_Title = self.transform.FindChildDeep<TMP_Text>("txt_Title");
this.txt_Content = self.transform.FindChildDeep<TMP_Text>("txt_Content");
this.btn_Close = self.transform.FindChildDeep<Button>("btn_Close");
this.txt_Title = GetValue<TMP_Text>("txt_Title");
this.txt_Content = GetValue<TMP_Text>("txt_Content");
this.btn_Close = GetValue<Button>("btn_Close");
btn_Close.onClick.AddListener(ClickClose);
}

View File

@ -15,7 +15,7 @@ namespace ZC
public override void Init()
{
base.Init();
this.tog_Item = self.transform.FindChildDeep<Toggle>("tog_Item");
this.tog_Item = GetValue<Toggle>("tog_Item");
// TODO:
// ListDatas = ZCGame

View File

@ -34,6 +34,11 @@ namespace ZC
_uiGameObjectBinding = _self.GetComponent<GameObjectBinding>();
}
internal T GetValue<T>(string name) where T : Component
{
return _uiGameObjectBinding.GetValue<T>(name);
}
public virtual void Init()
{
_isPause = false;

View File

@ -19,6 +19,18 @@ namespace ZC
}
}
throw new NullReferenceException($"没有找到绑定这个名字的物体name{nameStr}");
}
public T GetValue<T>(string nameStr)where T: Component
{
foreach (var data in Datas)
{
if (data.name == nameStr)
{
return data.go.GetComponent<T>();
}
}
throw new NullReferenceException($"没有找到绑定这个名字的物体name{nameStr}");
}
}

View File

@ -4,12 +4,18 @@
{
LoadingUI,
GameUI,
AnswerUI,
AnalysisReportUI,
IntroduceUI,
MinTipsUI,
TaskListUI,
MainUI,
// 老年人
AnswerUI, // 答题面板
AnalysisReportUI, // 报告解读
IntroduceUI, // 介绍面板
MinTipsUI, // 小提示
TaskListUI, // 任务列表
MainUI, // 主面板(顶部属性)
BigTipsUI, // 大提示
ModelDisplayUI, // 设备认知
DialogueUI, // 对话面板
BasicInformationUI, // 基本资料面板
BlackUI, // 半透明黑面板(底)
}
public enum UILayer

View File

@ -22,7 +22,9 @@ namespace Unity.Loader
public GlobalData Data => _globalData;
// Action
public Action<string> runTime;
public Action<string> updateTime;
public Action<string> updateScore;
public Action<string> updateProgress;
private void Awake()
{
@ -40,7 +42,7 @@ namespace Unity.Loader
private void Update()
{
time += Time.fixedTime;
runTime?.Invoke(_globalData.runTimeStr);
updateTime?.Invoke(_globalData.runTimeStr);
// Debug.Log($"{_globalData.runTimeStr}");
}