fix: 片头动画改为用户触发而非自动播放
- OpeningFlowController: Start() 不再自动播放动画,新增 PlayOpeningFlow(Action onComplete) 公开方法 - PageController: OnFixationSelected() 先隐藏所有UI面板,调用 PlayOpeningFlow,动画结束后再显示 ExperimentPanel - 新增 HideAllPages() 方法用于片头动画期间清空UI - 所有按钮回调均保留 Debug.Log 输出
This commit is contained in:
+165
-15
@@ -3,7 +3,8 @@ using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// UI 中央调度器:引用所有子面板,绑定 StepManager 事件。
|
||||
/// 挂在 Canvas GameObject 上。使用原生 Text(非 TMP)。
|
||||
/// 按钮策略:同时绑定 Inspector 引用(旧 RightButtons)和 ExperimentPanel/Navbar 按钮(新 UI),
|
||||
/// 两者均可触发,互不冲突。
|
||||
/// </summary>
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
@@ -26,7 +27,7 @@ public class UIManager : MonoBehaviour
|
||||
[Header("=== 画中画视频 ===")]
|
||||
[SerializeField] private VideoController _videoController;
|
||||
|
||||
[Header("=== 右侧功能按钮 ===")]
|
||||
[Header("=== 仿真导航栏按钮(旧引用 + Navbar)===")]
|
||||
[SerializeField] private Button _btnFullScreen;
|
||||
[SerializeField] private Button _btnPrevious;
|
||||
[SerializeField] private Button _btnNext;
|
||||
@@ -56,15 +57,117 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("=== UIManager 初始化开始 ===");
|
||||
|
||||
if (_stepManager == null)
|
||||
{
|
||||
_stepManager = FindObjectOfType<StepManager>();
|
||||
if (_stepManager != null) Debug.Log("UIManager: _stepManager 自动查找成功");
|
||||
else Debug.LogError("UIManager: _stepManager 未找到!");
|
||||
}
|
||||
|
||||
if (_interactionSystem == null)
|
||||
{
|
||||
_interactionSystem = FindObjectOfType<InteractionSystem>();
|
||||
if (_interactionSystem != null) Debug.Log("UIManager: _interactionSystem 自动查找成功");
|
||||
}
|
||||
|
||||
BindEvents();
|
||||
BindButtons();
|
||||
BindButtons(); // 旧引用(RightButtons 等)
|
||||
BindNavbarButtons(); // 新 Navbar 按钮
|
||||
Debug.Log("=== UIManager 初始化完成 ===");
|
||||
}
|
||||
|
||||
#region Navbar 按钮绑定(始终执行,不依赖 Inspector 引用)
|
||||
|
||||
private void BindNavbarButtons()
|
||||
{
|
||||
Debug.Log("--- UIManager: 开始绑定 Navbar 按钮 ---");
|
||||
|
||||
var experimentPanel = GameObject.Find("ExperimentPanel");
|
||||
if (experimentPanel == null)
|
||||
{
|
||||
Debug.LogError("UIManager: ExperimentPanel 未找到!无法绑定 Navbar 按钮!");
|
||||
return;
|
||||
}
|
||||
|
||||
var navbar = experimentPanel.transform.Find("Navbar");
|
||||
if (navbar == null)
|
||||
{
|
||||
Debug.LogError("UIManager: ExperimentPanel/Navbar 未找到!无法绑定 Navbar 按钮!");
|
||||
return;
|
||||
}
|
||||
|
||||
// FullScreen
|
||||
var btnFS = navbar.Find("FullScreen");
|
||||
if (btnFS != null)
|
||||
{
|
||||
var btn = btnFS.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(ToggleFullScreen);
|
||||
Debug.Log("UIManager: Navbar/FullScreen 绑定成功 -> ToggleFullScreen");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/FullScreen 未找到");
|
||||
|
||||
// Previous
|
||||
var btnPrev = navbar.Find("Previous");
|
||||
if (btnPrev != null)
|
||||
{
|
||||
var btn = btnPrev.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(OnPreviousClicked);
|
||||
Debug.Log("UIManager: Navbar/Previous 绑定成功 -> OnPreviousClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/Previous 未找到");
|
||||
|
||||
// Next
|
||||
var btnNext = navbar.Find("Next");
|
||||
if (btnNext != null)
|
||||
{
|
||||
var btn = btnNext.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(OnNextClicked);
|
||||
Debug.Log("UIManager: Navbar/Next 绑定成功 -> OnNextClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/Next 未找到");
|
||||
|
||||
// PracticeMode
|
||||
var btnMode = navbar.Find("PracticeMode");
|
||||
if (btnMode != null)
|
||||
{
|
||||
var btn = btnMode.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(OnSwitchModeClicked);
|
||||
Debug.Log("UIManager: Navbar/PracticeMode 绑定成功 -> OnSwitchModeClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/PracticeMode 未找到");
|
||||
|
||||
// BtnBack(返回按钮)
|
||||
var btnBack = navbar.Find("BtnBack");
|
||||
if (btnBack != null)
|
||||
{
|
||||
var btn = btnBack.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(OnReturnClicked);
|
||||
Debug.Log("UIManager: Navbar/BtnBack 绑定成功 -> OnReturnClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/BtnBack 未找到");
|
||||
|
||||
Debug.Log("--- UIManager: Navbar 按钮绑定完成 ---");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件绑定
|
||||
|
||||
private void BindEvents()
|
||||
@@ -78,17 +181,54 @@ public class UIManager : MonoBehaviour
|
||||
_stepManager.OnExamPopup.AddListener(ShowExamPopup);
|
||||
_stepManager.OnExperimentComplete.AddListener(OnExperimentComplete);
|
||||
_stepManager.OnVideoToggle.AddListener(ToggleVideo);
|
||||
Debug.Log("UIManager: StepManager 事件绑定完成");
|
||||
}
|
||||
|
||||
private void BindButtons()
|
||||
{
|
||||
if (_btnFullScreen) _btnFullScreen.onClick.AddListener(ToggleFullScreen);
|
||||
if (_btnPrevious) _btnPrevious.onClick.AddListener(OnPreviousClicked);
|
||||
if (_btnNext) _btnNext.onClick.AddListener(OnNextClicked);
|
||||
if (_btnSwitchMode) _btnSwitchMode.onClick.AddListener(OnSwitchModeClicked);
|
||||
if (_btnReturn) _btnReturn.onClick.AddListener(OnReturnClicked);
|
||||
if (_btnLimbFixation) _btnLimbFixation.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.LimbFixation));
|
||||
if (_btnSplintFixation) _btnSplintFixation.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.SplintFixation));
|
||||
if (_btnFullScreen != null)
|
||||
{
|
||||
_btnFullScreen.onClick.AddListener(ToggleFullScreen);
|
||||
Debug.Log("UIManager: _btnFullScreen 绑定成功");
|
||||
}
|
||||
if (_btnPrevious != null)
|
||||
{
|
||||
_btnPrevious.onClick.AddListener(OnPreviousClicked);
|
||||
Debug.Log("UIManager: _btnPrevious 绑定成功");
|
||||
}
|
||||
if (_btnNext != null)
|
||||
{
|
||||
_btnNext.onClick.AddListener(OnNextClicked);
|
||||
Debug.Log("UIManager: _btnNext 绑定成功");
|
||||
}
|
||||
if (_btnSwitchMode != null)
|
||||
{
|
||||
_btnSwitchMode.onClick.AddListener(OnSwitchModeClicked);
|
||||
Debug.Log("UIManager: _btnSwitchMode 绑定成功");
|
||||
}
|
||||
if (_btnReturn != null)
|
||||
{
|
||||
_btnReturn.onClick.AddListener(OnReturnClicked);
|
||||
Debug.Log("UIManager: _btnReturn 绑定成功");
|
||||
}
|
||||
|
||||
if (_btnLimbFixation != null)
|
||||
{
|
||||
_btnLimbFixation.onClick.AddListener(() => {
|
||||
Debug.Log("UIManager: [BtnLimbFixation] 点击 -> 肢体固定");
|
||||
_stepManager?.SwitchFixation(FixationMethod.LimbFixation);
|
||||
});
|
||||
Debug.Log("UIManager: _btnLimbFixation 绑定成功");
|
||||
}
|
||||
|
||||
if (_btnSplintFixation != null)
|
||||
{
|
||||
_btnSplintFixation.onClick.AddListener(() => {
|
||||
Debug.Log("UIManager: [BtnSplintFixation] 点击 -> 夹板固定");
|
||||
_stepManager?.SwitchFixation(FixationMethod.SplintFixation);
|
||||
});
|
||||
Debug.Log("UIManager: _btnSplintFixation 绑定成功");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -97,6 +237,7 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void OnStepChanged(int index)
|
||||
{
|
||||
Debug.Log($"UIManager: [OnStepChanged] 步骤 = {index + 1}");
|
||||
UpdateProgressBar();
|
||||
UpdateNavigationButtons();
|
||||
}
|
||||
@@ -121,6 +262,7 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void ToggleVideo(string fileName, bool active)
|
||||
{
|
||||
Debug.Log($"UIManager: [ToggleVideo] file={fileName}, active={active}");
|
||||
if (_videoController == null) return;
|
||||
if (active && !string.IsNullOrEmpty(fileName))
|
||||
_videoController.PlayVideo(fileName);
|
||||
@@ -140,8 +282,8 @@ public class UIManager : MonoBehaviour
|
||||
private void UpdateNavigationButtons()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
if (_btnPrevious) _btnPrevious.interactable = _stepManager.CurrentStepIndex > 0;
|
||||
if (_btnNext)
|
||||
if (_btnPrevious != null) _btnPrevious.interactable = _stepManager.CurrentStepIndex > 0;
|
||||
if (_btnNext != null)
|
||||
{
|
||||
var label = _btnNext.GetComponentInChildren<Text>();
|
||||
bool isLast = _stepManager.CurrentStepIndex >= _stepManager.TotalSteps - 1;
|
||||
@@ -155,12 +297,14 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void ShowExamPopup(StepData step)
|
||||
{
|
||||
Debug.Log($"UIManager: [ShowExamPopup] 题目={step.ExamQuestionText}");
|
||||
if (_examPopup == null) return;
|
||||
_examPopup.Show(step, OnExamAnswer);
|
||||
}
|
||||
|
||||
private void OnExamAnswer(float proportion, string feedback)
|
||||
{
|
||||
Debug.Log($"UIManager: [OnExamAnswer] proportion={proportion}, feedback={feedback}");
|
||||
_stepManager?.OnStepInteractionComplete(proportion, feedback);
|
||||
_stepManager?.NextStep();
|
||||
}
|
||||
@@ -171,6 +315,7 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void OnExperimentComplete()
|
||||
{
|
||||
Debug.Log("UIManager: [OnExperimentComplete] 实验完成");
|
||||
var gm = GameManager.Instance;
|
||||
if (gm == null) return;
|
||||
if (gm.CurrentMode == ExperimentMode.Exam)
|
||||
@@ -186,15 +331,18 @@ public class UIManager : MonoBehaviour
|
||||
private void ToggleFullScreen()
|
||||
{
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
Debug.Log($"UIManager: [ToggleFullScreen] 全屏 = {Screen.fullScreen}");
|
||||
}
|
||||
|
||||
private void OnPreviousClicked()
|
||||
{
|
||||
Debug.Log("UIManager: [OnPreviousClicked] -> 上一步");
|
||||
_stepManager?.PreviousStep();
|
||||
}
|
||||
|
||||
private void OnNextClicked()
|
||||
{
|
||||
Debug.Log("UIManager: [OnNextClicked] -> 下一步");
|
||||
if (_stepManager != null && _stepManager.Mode == ExperimentMode.Exam)
|
||||
{
|
||||
var step = _stepManager.GetCurrentStep();
|
||||
@@ -207,18 +355,20 @@ public class UIManager : MonoBehaviour
|
||||
private void OnSwitchModeClicked()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
var newMode = _stepManager.Mode == ExperimentMode.Learn
|
||||
? ExperimentMode.Exam : ExperimentMode.Learn;
|
||||
var oldMode = _stepManager.Mode;
|
||||
var newMode = oldMode == ExperimentMode.Learn ? ExperimentMode.Exam : ExperimentMode.Learn;
|
||||
Debug.Log($"UIManager: [OnSwitchModeClicked] 切换 {oldMode} -> {newMode}");
|
||||
_stepManager.SwitchMode(newMode);
|
||||
}
|
||||
|
||||
private void OnReturnClicked()
|
||||
{
|
||||
Debug.Log("UIManager: [OnReturnClicked] -> 返回首页");
|
||||
var pageCtrl = FindObjectOfType<PageController>();
|
||||
if (pageCtrl != null)
|
||||
pageCtrl.ReturnToHome();
|
||||
else
|
||||
Debug.LogWarning("UIManager: 未找到 PageController,无法返回首页。");
|
||||
Debug.LogWarning("UIManager: 未找到 PageController。");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user