fix: 修复 UI 导航流程,添加 Debug.Log 完整日志

- 重写 PageController.cs,为所有按钮回调添加完整 Debug.Log
- 自动修复 _btnFixationBack:未赋值时自动查找 FixationPanel/BtnBack
- 自动修复 _btnExperimentBack:未赋值时自动查找 ExperimentPanel/Navbar/BtnBack
- 删除失效的 Canvas 根级冗余 BtnFixationBack
- 添加 3D 角色模型资源(man/woman 模型、动画、TextMesh Pro)
- 添加 ExperimentPanel UI 资源和 TrainingBackground 素材

测试方法:进入 Play 模式,查看 Console 以验证每个按钮的绑定状态和点击回调是否正常触发。
This commit is contained in:
yangbear
2026-06-27 13:25:58 +08:00
parent 98aeae4929
commit 2d0aaa98aa
629 changed files with 158883 additions and 47 deletions
+113 -32
View File
@@ -47,31 +47,112 @@ public class PageController : MonoBehaviour
private void Start()
{
Debug.Log("=== PageController 初始化开始 ===");
// 绑定首页按钮
if (_btnStart != null) _btnStart.onClick.AddListener(OnStartClicked);
if (_btnExit != null) _btnExit.onClick.AddListener(OnExitClicked);
if (_btnStart != null)
{
_btnStart.onClick.AddListener(OnStartClicked);
Debug.Log("PageController: _btnStart 绑定成功");
}
else
Debug.LogError("PageController: _btnStart 未赋值!");
if (_btnExit != null)
{
_btnExit.onClick.AddListener(OnExitClicked);
Debug.Log("PageController: _btnExit 绑定成功");
}
else
Debug.LogError("PageController: _btnExit 未赋值!");
// 绑定模式选择页按钮
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 (_btnBack != null)
{
_btnBack.onClick.AddListener(OnModeBackClicked);
Debug.Log("PageController: _btnBack 绑定成功");
}
else
Debug.LogError("PageController: _btnBack 未赋值!");
// 绑定固定方式选择页按钮
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 (_btnPracticeMode != null)
{
_btnPracticeMode.onClick.AddListener(() => OnModeSelected(ExperimentMode.Learn));
Debug.Log("PageController: _btnPracticeMode 绑定成功");
}
else
Debug.LogError("PageController: _btnPracticeMode 未赋值!");
// 绑定实验页面按钮
if (_btnExperimentBack != null) _btnExperimentBack.onClick.AddListener(OnExperimentBackClicked);
if (_btnExamMode != null)
{
_btnExamMode.onClick.AddListener(() => OnModeSelected(ExperimentMode.Exam));
Debug.Log("PageController: _btnExamMode 绑定成功");
}
else
Debug.LogError("PageController: _btnExamMode 未赋值!");
// 绑定固定方式选择页按钮 —— 自动修复
if (_btnFixationBack == null && _fixationPanel != null)
{
var btnBack = _fixationPanel.transform.Find("BtnBack");
if (btnBack != null)
{
_btnFixationBack = btnBack.GetComponent<Button>();
Debug.Log("PageController: 自动绑定 FixationPanel/BtnBack_btnFixationBack 原为空)");
}
}
if (_btnFixationBack != null)
{
_btnFixationBack.onClick.AddListener(OnFixationBackClicked);
Debug.Log("PageController: _btnFixationBack 绑定成功");
}
else
Debug.LogError("PageController: _btnFixationBack 未找到!请在 Inspector 赋值或确保 FixationPanel 下有名为 BtnBack 的子物体。");
if (_btnLimbFixation != null)
{
_btnLimbFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.LimbFixation));
Debug.Log("PageController: _btnLimbFixation 绑定成功");
}
else
Debug.LogError("PageController: _btnLimbFixation 未赋值!");
if (_btnSplintFixation != null)
{
_btnSplintFixation.onClick.AddListener(() => OnFixationSelected(FixationMethod.SplintFixation));
Debug.Log("PageController: _btnSplintFixation 绑定成功");
}
else
Debug.LogError("PageController: _btnSplintFixation 未赋值!");
// 绑定实验页面按钮 —— 自动修复
if (_btnExperimentBack == null && _experimentPanel != null)
{
var btnBack = _experimentPanel.transform.Find("Navbar/BtnBack");
if (btnBack != null)
{
_btnExperimentBack = btnBack.GetComponent<Button>();
Debug.Log("PageController: 自动绑定 ExperimentPanel/Navbar/BtnBack_btnExperimentBack 原为空)");
}
}
if (_btnExperimentBack != null)
{
_btnExperimentBack.onClick.AddListener(OnExperimentBackClicked);
Debug.Log("PageController: _btnExperimentBack 绑定成功");
}
else
Debug.LogError("PageController: _btnExperimentBack 未找到!请在 Inspector 赋值或确保 ExperimentPanel/Navbar 下有名为 BtnBack 的子物体。");
// 初始化模式说明文字
if (_modeDescText != null)
{
_modeDescText.text = _practiceModeDesc + "\n\n" + _examModeDesc;
Debug.Log("PageController: _modeDescText 初始化完成");
}
// 初始显示首页
ShowPage(Page.Home);
Debug.Log("=== PageController 初始化完成 ===");
}
#if UNITY_EDITOR
@@ -86,20 +167,11 @@ public class PageController : MonoBehaviour
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;
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;
}
_editorPreview = EditorPreviewPage.None;
@@ -124,6 +196,7 @@ public class PageController : MonoBehaviour
private void ShowPage(Page page)
{
Debug.Log($"PageController: 页面切换 [{_currentPage}] → [{page}]");
_currentPage = page;
if (_homePagePanel != null) _homePagePanel.SetActive(page == Page.Home);
@@ -134,17 +207,20 @@ public class PageController : MonoBehaviour
if (_uiManager != null)
_uiManager.enabled = (page == Page.Experiment);
}
#endregion
#region
private void OnStartClicked()
{
Debug.Log("PageController: [BtnStart] 点击 -> 切换到 ModeSelect");
ShowPage(Page.ModeSelect);
}
private void OnExitClicked()
{
Debug.Log("PageController: [BtnExit] 点击 -> 退出应用");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
@@ -154,25 +230,21 @@ public class PageController : MonoBehaviour
private void OnModeBackClicked()
{
Debug.Log("PageController: [BtnBack(Mode)] 点击 -> 返回 Home");
ShowPage(Page.Home);
}
private void OnModeSelected(ExperimentMode mode)
{
Debug.Log($"PageController: [ModeSelected] 点击 -> 模式 [{mode}] -> 切换到 Fixation");
_selectedMode = mode;
if (_modeDescText != null)
{
_modeDescText.text = mode == ExperimentMode.Learn
? _practiceModeDesc + "\n\n 当前已选择「模拟练习模式」"
: _examModeDesc + "\n\n 当前已选择「考核评估模式」";
}
ShowPage(Page.Fixation);
}
private void OnFixationBackClicked()
{
Debug.Log("PageController: [BtnFixationBack] 点击 -> 返回 ModeSelect");
if (_modeDescText != null)
{
_modeDescText.text = _practiceModeDesc + "\n\n" + _examModeDesc;
@@ -183,11 +255,13 @@ public class PageController : MonoBehaviour
private void OnExperimentBackClicked()
{
Debug.Log("PageController: [BtnExperimentBack] 点击 -> 返回 Fixation");
ShowPage(Page.Fixation);
}
private void OnFixationSelected(FixationMethod method)
{
Debug.Log($"PageController: [FixationSelected] 点击 -> 固定方式 [{method}] -> 切换到 Experiment");
var gm = GameManager.Instance;
if (gm == null)
{
@@ -197,6 +271,7 @@ public class PageController : MonoBehaviour
gm.CurrentMode = _selectedMode;
gm.CurrentFixationMethod = method;
Debug.Log($"PageController: GameManager 已设置 Mode=[{gm.CurrentMode}] Fixation=[{gm.CurrentFixationMethod}]");
ShowPage(Page.Experiment);
@@ -204,11 +279,17 @@ public class PageController : MonoBehaviour
if (stepManager != null)
{
stepManager.InitializeFromGameManager();
Debug.Log("PageController: StepManager.InitializeFromGameManager() 已调用");
}
else
{
Debug.LogWarning("PageController: 未找到 StepManager,实验步骤不会自动初始化");
}
}
public void ReturnToHome()
{
Debug.Log("PageController: [ReturnToHome] 返回首页");
ShowPage(Page.Home);
}