fix: 修复ExperimentPanel按钮无响应问题,新增OnExperimentBackClicked回调,清理遗留的BtnFixationBack显隐逻辑

This commit is contained in:
yangbear
2026-06-25 04:55:41 +08:00
parent b775d9f179
commit b999148a0e
2 changed files with 438 additions and 26 deletions
+19 -19
View File
@@ -1,10 +1,6 @@
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 管理首页 -> 模式选择页 -> 固定方式选择页 -> 实验界面 的切换。
/// 挂在 Canvas 上,与 UIManager 协同工作。
/// </summary>
public class PageController : MonoBehaviour
{
[Header("=== 三个主页面 ===")]
@@ -12,6 +8,10 @@ public class PageController : MonoBehaviour
[SerializeField] private GameObject _modeSelectPanel;
[SerializeField] private GameObject _fixationPanel;
[Header("=== 实验页面 ===")]
[SerializeField] private GameObject _experimentPanel;
[SerializeField] private Button _btnExperimentBack;
[Header("=== 实验内 UI(由 UIManager 管理)===")]
[SerializeField] private UIManager _uiManager;
@@ -32,14 +32,13 @@ public class PageController : MonoBehaviour
[Header("=== 模式说明文案 ===")]
[SerializeField] [TextArea(2, 4)] private string _practiceModeDesc =
"模拟练习模式:不限时长,可反复练习。系统不评分,帮助您熟悉实验流程和操作步骤。";
"模拟练习模式:不限时长,可反复练习。系统不评分,帮助您熟悉实验流程和操作步骤。";
[SerializeField] [TextArea(2, 4)] private string _examModeDesc =
"考核评估模式:限定时间,完成后系统自动评分,并提供详细反馈报告。";
"考核评估模式:限定时间,完成后系统自动评分,并提供详细反馈报告。";
[Header("=== 编辑器预览(仅 Editor 模式有效)===")]
[SerializeField] private EditorPreviewPage _editorPreview = EditorPreviewPage.None;
// Page 枚举改为 publicInspector 中可通过 _editorPreview 切换
public enum Page { Home, ModeSelect, Fixation, Experiment }
public enum EditorPreviewPage { None, Home, ModeSelect, Fixation, Experiment }
@@ -62,6 +61,9 @@ public class PageController : MonoBehaviour
if (_btnLimbFixation != null) _btnLimbFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.LimbFixation));
if (_btnSplintFixation != null) _btnSplintFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.SplintFixation));
// 绑定实验页面按钮
if (_btnExperimentBack != null) _btnExperimentBack.onClick.AddListener(OnExperimentBackClicked);
// 初始化模式说明文字
if (_modeDescText != null)
{
@@ -73,15 +75,10 @@ public class PageController : MonoBehaviour
}
#if UNITY_EDITOR
/// <summary>
/// 在 Inspector 中修改 _editorPreview 下拉框时,立即切换 Scene View 中显示的页面,
/// 方便编辑不同页面的 UI 布局。仅在非运行状态下生效。
/// </summary>
private void OnValidate()
{
if (Application.isPlaying) return;
// 延迟一帧执行,避免在序列化过程中修改场景导致警告
UnityEditor.EditorApplication.delayCall += () =>
{
if (this == null) return;
@@ -90,7 +87,6 @@ public class PageController : MonoBehaviour
switch (_editorPreview)
{
case EditorPreviewPage.None:
// 不做任何切换,保留当前状态
break;
case EditorPreviewPage.Home:
ShowPageEditMode(Page.Home);
@@ -106,7 +102,6 @@ public class PageController : MonoBehaviour
break;
}
// 切换完成后重置为 None,避免与后续操作冲突
_editorPreview = EditorPreviewPage.None;
};
}
@@ -116,6 +111,7 @@ public class PageController : MonoBehaviour
if (_homePagePanel != null) _homePagePanel.SetActive(page == Page.Home);
if (_modeSelectPanel != null) _modeSelectPanel.SetActive(page == Page.ModeSelect);
if (_fixationPanel != null) _fixationPanel.SetActive(page == Page.Fixation);
if (_experimentPanel != null) _experimentPanel.SetActive(page == Page.Experiment);
if (_uiManager != null)
_uiManager.enabled = (page == Page.Experiment);
@@ -126,14 +122,14 @@ public class PageController : MonoBehaviour
#region
private void ShowPage(Page page)
private void ShowPage(Page page)
{
_currentPage = page;
if (_homePagePanel != null) _homePagePanel.SetActive(page == Page.Home);
if (_modeSelectPanel != null) _modeSelectPanel.SetActive(page == Page.ModeSelect);
if (_fixationPanel != null) _fixationPanel.SetActive(page == Page.Fixation);
if (_btnFixationBack != null) _btnFixationBack.gameObject.SetActive(page == Page.Fixation);
if (_experimentPanel != null) _experimentPanel.SetActive(page == Page.Experiment);
if (_uiManager != null)
_uiManager.enabled = (page == Page.Experiment);
@@ -168,8 +164,8 @@ public class PageController : MonoBehaviour
if (_modeDescText != null)
{
_modeDescText.text = mode == ExperimentMode.Learn
? _practiceModeDesc + "\n\n 当前已选择「模拟练习模式」"
: _examModeDesc + "\n\n 当前已选择「考核评估模式」";
? _practiceModeDesc + "\n\n 当前已选择「模拟练习模式」"
: _examModeDesc + "\n\n 当前已选择「考核评估模式」";
}
ShowPage(Page.Fixation);
@@ -185,6 +181,11 @@ public class PageController : MonoBehaviour
ShowPage(Page.ModeSelect);
}
private void OnExperimentBackClicked()
{
ShowPage(Page.Fixation);
}
private void OnFixationSelected(FixationMethod method)
{
var gm = GameManager.Instance;
@@ -211,6 +212,5 @@ public class PageController : MonoBehaviour
ShowPage(Page.Home);
}
#endregion
}