2026-06-24 05:24:09 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 管理首页 -> 模式选择页 -> 固定方式选择页 -> 实验界面 的切换。
|
|
|
|
|
|
/// 挂在 Canvas 上,与 UIManager 协同工作。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class PageController : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("=== 三个主页面 ===")]
|
|
|
|
|
|
[SerializeField] private GameObject _homePagePanel;
|
|
|
|
|
|
[SerializeField] private GameObject _modeSelectPanel;
|
|
|
|
|
|
[SerializeField] private GameObject _fixationPanel;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("=== 实验内 UI(由 UIManager 管理)===")]
|
|
|
|
|
|
[SerializeField] private UIManager _uiManager;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("=== 首页控件 ===")]
|
|
|
|
|
|
[SerializeField] private Button _btnStart;
|
|
|
|
|
|
[SerializeField] private Button _btnExit;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("=== 模式选择页控件 ===")]
|
|
|
|
|
|
[SerializeField] private Button _btnBack;
|
|
|
|
|
|
[SerializeField] private Button _btnPracticeMode;
|
|
|
|
|
|
[SerializeField] private Button _btnExamMode;
|
|
|
|
|
|
[SerializeField] private Text _modeDescText;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("=== 固定方式选择页控件 ===")]
|
|
|
|
|
|
[SerializeField] private Button _btnFixationBack;
|
|
|
|
|
|
[SerializeField] private Button _btnLimbFixation;
|
|
|
|
|
|
[SerializeField] private Button _btnSplintFixation;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("=== 模式说明文案 ===")]
|
|
|
|
|
|
[SerializeField] [TextArea(2, 4)] private string _practiceModeDesc =
|
|
|
|
|
|
"● 模拟练习模式:不限时长,可反复练习。系统不评分,帮助您熟悉实验流程和操作步骤。";
|
|
|
|
|
|
[SerializeField] [TextArea(2, 4)] private string _examModeDesc =
|
|
|
|
|
|
"● 考核评估模式:限定时间,完成后系统自动评分,并提供详细反馈报告。";
|
|
|
|
|
|
|
2026-06-24 06:05:55 +08:00
|
|
|
|
[Header("=== 编辑器预览(仅 Editor 模式有效)===")]
|
|
|
|
|
|
[SerializeField] private EditorPreviewPage _editorPreview = EditorPreviewPage.None;
|
|
|
|
|
|
|
|
|
|
|
|
// Page 枚举改为 public,Inspector 中可通过 _editorPreview 切换
|
|
|
|
|
|
public enum Page { Home, ModeSelect, Fixation, Experiment }
|
|
|
|
|
|
public enum EditorPreviewPage { None, Home, ModeSelect, Fixation, Experiment }
|
|
|
|
|
|
|
2026-06-24 05:24:09 +08:00
|
|
|
|
private Page _currentPage = Page.Home;
|
|
|
|
|
|
private ExperimentMode _selectedMode = ExperimentMode.Learn;
|
|
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 绑定首页按钮
|
|
|
|
|
|
if (_btnStart != null) _btnStart.onClick.AddListener(OnStartClicked);
|
|
|
|
|
|
if (_btnExit != null) _btnExit.onClick.AddListener(OnExitClicked);
|
|
|
|
|
|
|
|
|
|
|
|
// 绑定模式选择页按钮
|
|
|
|
|
|
if (_btnBack != null) _btnBack.onClick.AddListener(OnModeBackClicked);
|
|
|
|
|
|
if (_btnPracticeMode != null) _btnPracticeMode.onClick.AddListener(() => OnModeSelected(ExperimentMode.Learn));
|
|
|
|
|
|
if (_btnExamMode != null) _btnExamMode.onClick.AddListener(() => OnModeSelected(ExperimentMode.Exam));
|
|
|
|
|
|
|
|
|
|
|
|
// 绑定固定方式选择页按钮
|
|
|
|
|
|
if (_btnFixationBack != null) _btnFixationBack.onClick.AddListener(OnFixationBackClicked);
|
|
|
|
|
|
if (_btnLimbFixation != null) _btnLimbFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.LimbFixation));
|
|
|
|
|
|
if (_btnSplintFixation != null) _btnSplintFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.SplintFixation));
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化模式说明文字
|
|
|
|
|
|
if (_modeDescText != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_modeDescText.text = _practiceModeDesc + "\n\n" + _examModeDesc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始显示首页
|
|
|
|
|
|
ShowPage(Page.Home);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-24 06:05:55 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 在 Inspector 中修改 _editorPreview 下拉框时,立即切换 Scene View 中显示的页面,
|
|
|
|
|
|
/// 方便编辑不同页面的 UI 布局。仅在非运行状态下生效。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnValidate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Application.isPlaying) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟一帧执行,避免在序列化过程中修改场景导致警告
|
|
|
|
|
|
UnityEditor.EditorApplication.delayCall += () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this == null) return;
|
|
|
|
|
|
if (Application.isPlaying) return;
|
|
|
|
|
|
|
|
|
|
|
|
switch (_editorPreview)
|
|
|
|
|
|
{
|
|
|
|
|
|
case EditorPreviewPage.None:
|
|
|
|
|
|
// 不做任何切换,保留当前状态
|
|
|
|
|
|
break;
|
|
|
|
|
|
case EditorPreviewPage.Home:
|
|
|
|
|
|
ShowPageEditMode(Page.Home);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case EditorPreviewPage.ModeSelect:
|
|
|
|
|
|
ShowPageEditMode(Page.ModeSelect);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case EditorPreviewPage.Fixation:
|
|
|
|
|
|
ShowPageEditMode(Page.Fixation);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case EditorPreviewPage.Experiment:
|
|
|
|
|
|
ShowPageEditMode(Page.Experiment);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 切换完成后重置为 None,避免与后续操作冲突
|
|
|
|
|
|
_editorPreview = EditorPreviewPage.None;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowPageEditMode(Page 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 (_uiManager != null)
|
|
|
|
|
|
_uiManager.enabled = (page == Page.Experiment);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"PageController(编辑器预览): 切换到 [{page}]");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2026-06-24 05:24:09 +08:00
|
|
|
|
#region 页面切换
|
|
|
|
|
|
|
2026-06-25 04:37:45 +08:00
|
|
|
|
private void ShowPage(Page page)
|
2026-06-24 05:24:09 +08:00
|
|
|
|
{
|
|
|
|
|
|
_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);
|
2026-06-25 04:37:45 +08:00
|
|
|
|
if (_btnFixationBack != null) _btnFixationBack.gameObject.SetActive(page == Page.Fixation);
|
2026-06-24 05:24:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (_uiManager != null)
|
|
|
|
|
|
_uiManager.enabled = (page == Page.Experiment);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 按钮回调
|
|
|
|
|
|
|
|
|
|
|
|
private void OnStartClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowPage(Page.ModeSelect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnExitClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
|
|
|
|
#else
|
|
|
|
|
|
Application.Quit();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnModeBackClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowPage(Page.Home);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnModeSelected(ExperimentMode mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
_selectedMode = mode;
|
|
|
|
|
|
|
|
|
|
|
|
if (_modeDescText != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_modeDescText.text = mode == ExperimentMode.Learn
|
|
|
|
|
|
? _practiceModeDesc + "\n\n✓ 当前已选择「模拟练习模式」"
|
|
|
|
|
|
: _examModeDesc + "\n\n✓ 当前已选择「考核评估模式」";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowPage(Page.Fixation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnFixationBackClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_modeDescText != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_modeDescText.text = _practiceModeDesc + "\n\n" + _examModeDesc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowPage(Page.ModeSelect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnFixationSelected(FixationMethod method)
|
|
|
|
|
|
{
|
|
|
|
|
|
var gm = GameManager.Instance;
|
|
|
|
|
|
if (gm == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("PageController: GameManager.Instance 为空!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gm.CurrentMode = _selectedMode;
|
|
|
|
|
|
gm.CurrentFixationMethod = method;
|
|
|
|
|
|
|
|
|
|
|
|
ShowPage(Page.Experiment);
|
|
|
|
|
|
|
|
|
|
|
|
var stepManager = FindObjectOfType<StepManager>();
|
|
|
|
|
|
if (stepManager != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
stepManager.InitializeFromGameManager();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-25 04:37:45 +08:00
|
|
|
|
public void ReturnToHome()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowPage(Page.Home);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-24 05:24:09 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|