From 76d78f7ae3d1db6566487e84c3aa95c367e504ff Mon Sep 17 00:00:00 2001 From: taosuqi <2274240467@qq.com> Date: Tue, 8 Apr 2025 09:11:04 +0800 Subject: [PATCH] =?UTF-8?q?4.8=E4=B8=8A=E5=8D=88=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/UIPanel/UI_ContentPanel.prefab | 8 +- .../Resources/UI/UIPanel/UI_ExamPanel.prefab | 24 +++--- .../UI/UIPanel/UI_TipsForPracticePanel.prefab | 6 +- Assets/Scripts/Project/ProjectBase/Const.cs | 7 +- Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs | 82 ++++++++++++++----- 5 files changed, 84 insertions(+), 43 deletions(-) diff --git a/Assets/Resources/UI/UIPanel/UI_ContentPanel.prefab b/Assets/Resources/UI/UIPanel/UI_ContentPanel.prefab index cb41356..2783398 100644 --- a/Assets/Resources/UI/UIPanel/UI_ContentPanel.prefab +++ b/Assets/Resources/UI/UIPanel/UI_ContentPanel.prefab @@ -831,7 +831,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0.0002783385} + m_AnchoredPosition: {x: 0, y: 0.00022947599} m_SizeDelta: {x: 0, y: 300} m_Pivot: {x: 0, y: 1} --- !u!1 &5648230691007625910 @@ -1162,10 +1162,10 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: 54654654654654654465 + m_text: "\u76F8\u5173\u4ECB\u7ECD" m_isRightToLeft: 0 - m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontAsset: {fileID: 11400000, guid: 1c4004df1d65ff944b6e23e3af757df7, type: 2} + m_sharedMaterial: {fileID: 1751944718996602668, guid: 1c4004df1d65ff944b6e23e3af757df7, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] diff --git a/Assets/Resources/UI/UIPanel/UI_ExamPanel.prefab b/Assets/Resources/UI/UIPanel/UI_ExamPanel.prefab index 2e69b36..9aadcee 100644 --- a/Assets/Resources/UI/UIPanel/UI_ExamPanel.prefab +++ b/Assets/Resources/UI/UIPanel/UI_ExamPanel.prefab @@ -386,9 +386,9 @@ RectTransform: m_Father: {fileID: 5924775712395334843} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 766, y: -412} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 1332, y: 80} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &6001528603228556391 @@ -1582,9 +1582,9 @@ RectTransform: m_Father: {fileID: 5924775712395334843} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 766, y: -300} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 1332, y: 80} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &6086586699102765214 @@ -1670,9 +1670,9 @@ RectTransform: m_Father: {fileID: 5924775712395334843} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 766, y: -524} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 1332, y: 80} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &5653636613290556819 @@ -1758,9 +1758,9 @@ RectTransform: m_Father: {fileID: 5924775712395334843} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 766, y: -636} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 1332, y: 80} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1429247267648985812 diff --git a/Assets/Resources/UI/UIPanel/UI_TipsForPracticePanel.prefab b/Assets/Resources/UI/UIPanel/UI_TipsForPracticePanel.prefab index 9e1fa00..32ae754 100644 --- a/Assets/Resources/UI/UIPanel/UI_TipsForPracticePanel.prefab +++ b/Assets/Resources/UI/UIPanel/UI_TipsForPracticePanel.prefab @@ -658,9 +658,9 @@ RectTransform: m_Father: {fileID: 5924775712395334843} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 804, y: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 1608, y: 940} m_Pivot: {x: 0.5, y: 1} --- !u!222 &6109062945893642881 diff --git a/Assets/Scripts/Project/ProjectBase/Const.cs b/Assets/Scripts/Project/ProjectBase/Const.cs index b4bc508..ed493e0 100644 --- a/Assets/Scripts/Project/ProjectBase/Const.cs +++ b/Assets/Scripts/Project/ProjectBase/Const.cs @@ -16,9 +16,6 @@ public class Const } - - - [Serializable] public class ChooseItem { @@ -60,6 +57,10 @@ public class ChooseItem /// 答案 /// public string answer; + /// + /// 当前选择的 + /// + public string CurrentOptions; } diff --git a/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs b/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs index fd21ece..022d14d 100644 --- a/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs @@ -27,6 +27,7 @@ public class UI_ExamPanel : BasePanel public TextMeshProUGUI TopicType_Text; public TextMeshProUGUI[] topicLabel;//Ŀѡ + private List questionToggles = new List(); // ̬ɵĿToggleб private int curIndex; protected override void Awake() { @@ -37,37 +38,76 @@ public class UI_ExamPanel : BasePanel { var item = Instantiate(UI_Topicitem, Rigcontent); item.Init(tmxh.topiceNumber); - var ToogleText = item.GetControl("Label"); Toggle toggle = item.GetControl("Toggle"); - int currentIndex = int.Parse(tmxh.topiceNumber) - 1; + toggle.group = ToggleGroup; + questionToggles.Add(toggle); + + int currentIndex = index; toggle.onValueChanged.RemoveAllListeners(); toggle.onValueChanged.AddListener((ison) => { if (ison) { + Debug.Log($"Toggleѡ:{currentIndex}"); fun(currentIndex); - } + } }); - // ǵһToggleΪѡ״̬ - Debug.Log(toggle.name); - if (index == 0) - { - toggle.isOn = true; - } - index++; // + + if (index == 0) toggle.isOn = true; + index++; + ToggleGroup.allowSwitchOff = false; + UpdateQuestionUI(); } - // ȷ ToggleGroup ״̬ȷ - ToggleGroup.allowSwitchOff = false; - ToggleGroup.SetAllTogglesOff(); - //if (Rigcontent.childCount > 0) - //{ - // Rigcontent.GetChild(0).GetComponent().isOn = true; - //} - //StartCoroutine(SetFirstToggleNextFrame()); - + //// ȷ ToggleGroup ״̬ȷ + //ToggleGroup.allowSwitchOff = false; + //ToggleGroup.SetAllTogglesOff(); + //UpdateQuestionUI(); } + // ĿUI + private void UpdateQuestionUI() + { + if (curIndex < 0 || curIndex >= Root.choose.Count) return; + + var currentQuestion = Root.choose[curIndex]; + + // Ŀ + bool isJudgment = currentQuestion.topicetype == "1"; + topicetype.text = isJudgment ? "[ж]" : "[ѡ]"; + TopicType_Text.text = isJudgment ? "ж" : "ѡ"; + + // ʾ/ѡ + toggles[2].gameObject.SetActive(!isJudgment); + toggles[3].gameObject.SetActive(!isJudgment); + + // Ŀıѡ + topicText.text = currentQuestion.topiceName; + topicLabel[0].text = currentQuestion.chooseA; + topicLabel[1].text = currentQuestion.chooseB; + topicLabel[2].text = currentQuestion.chooseC; + topicLabel[3].text = currentQuestion.ChooseD; + + // °ť״̬ + PreviousQuestion_Btn.gameObject.SetActive(curIndex > 0); + NextQuestion_Btn.gameObject.SetActive(curIndex < Root.choose.Count - 1); + + // ѡеǰĿToggle + if (questionToggles.Count > curIndex) + { + questionToggles[curIndex].isOn = true; + } + } + + private void SwitchQuestion(int offset) + { + int newIndex = curIndex + offset; + if (newIndex < 0 || newIndex >= questionToggles.Count) return; + + curIndex = newIndex; + questionToggles[curIndex].isOn = true; + UpdateQuestionUI(); + } private void fun(int index_) { Debug.Log(index_); @@ -145,10 +185,10 @@ public class UI_ExamPanel : BasePanel break; case "PreviousQuestion_Btn": - + SwitchQuestion(-1); break; case "NextQuestion_Btn": - + SwitchQuestion(1); break; } }