Fix duplicate voice playback on Ping completion and add EndPanel integration
This commit is contained in:
@@ -13,16 +13,46 @@ public class PingClickHandler : MonoBehaviour
|
||||
// 实例变量,记录自己被启用(或重新闪烁)的那一帧
|
||||
private int _enableFrame = -1;
|
||||
|
||||
// 添加一个全局静态标志位,记录“语音是否已经被播放过了”,防止重复播放
|
||||
private static bool _hasPlayedFinishVoice = false;
|
||||
|
||||
public bool CanBeClicked() { return _isBlinking; }
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_enableFrame = Time.frameCount;
|
||||
|
||||
// 每次重新启用时(如果是第一轮的第一步),重置语音播放标志位
|
||||
// 通过判断是否是第一轮的第一个 ping,或者直接在第一轮就重置
|
||||
if (name == "ping.004" && !_modelShown)
|
||||
{
|
||||
_hasPlayedFinishVoice = false;
|
||||
}
|
||||
|
||||
_modelRenderer = GetComponent<MeshRenderer>();
|
||||
if (_modelRenderer == null) _modelRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
||||
|
||||
var colliders = GetComponents<Collider>();
|
||||
foreach (var c in colliders)
|
||||
{
|
||||
if (c is BoxCollider || c is CapsuleCollider)
|
||||
{
|
||||
Destroy(c);
|
||||
}
|
||||
}
|
||||
|
||||
var sphere = GetComponent<SphereCollider>();
|
||||
if (sphere == null) sphere = gameObject.AddComponent<SphereCollider>();
|
||||
|
||||
float maxScale = Mathf.Max(Mathf.Abs(transform.lossyScale.x), Mathf.Abs(transform.lossyScale.y), Mathf.Abs(transform.lossyScale.z));
|
||||
if (maxScale < 0.001f) maxScale = 1f;
|
||||
|
||||
sphere.radius = 0.15f / maxScale;
|
||||
sphere.center = Vector3.zero;
|
||||
sphere.isTrigger = false;
|
||||
sphere.enabled = true;
|
||||
|
||||
CreateOutlineMesh();
|
||||
_modelShown = false;
|
||||
_isBlinking = true;
|
||||
@@ -59,22 +89,16 @@ public class PingClickHandler : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 只检测正在闪烁的 ping
|
||||
if (!_isBlinking) return;
|
||||
if (!Input.GetMouseButtonDown(0)) return;
|
||||
|
||||
// 防御 1:防止刚被激活的同一帧内立刻触发(比如点击鞋子的一瞬间 ping.004 被激活,此时鼠标左键按下状态依然为 true)
|
||||
if (Time.frameCount == _enableFrame) return;
|
||||
|
||||
// 防御 2:防止同一帧内有多个 ping 同时触发(执行顺序导致的状态延迟问题)
|
||||
if (Time.frameCount == _lastClickedFrame) return;
|
||||
|
||||
// 如果点在 UI 上,不处理
|
||||
if (UnityEngine.EventSystems.EventSystem.current != null &&
|
||||
UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
|
||||
return;
|
||||
|
||||
// 找到当前渲染画面的相机
|
||||
Camera activeCamera = null;
|
||||
foreach (var c in Camera.allCameras)
|
||||
{
|
||||
@@ -85,14 +109,12 @@ public class PingClickHandler : MonoBehaviour
|
||||
}
|
||||
if (activeCamera == null) return;
|
||||
|
||||
// 计算自己到鼠标的屏幕距离
|
||||
Vector3 screenPos = activeCamera.WorldToScreenPoint(transform.position);
|
||||
if (screenPos.z < 0) return; // 在相机背后
|
||||
if (screenPos.z < 0) return;
|
||||
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
float myDist = Vector2.Distance(mousePos, new Vector2(screenPos.x, screenPos.y));
|
||||
|
||||
// 检查是否有其他正在闪烁的 ping 比我更近
|
||||
var allHandlers = FindObjectsOfType<PingClickHandler>();
|
||||
foreach (var h in allHandlers)
|
||||
{
|
||||
@@ -104,14 +126,13 @@ public class PingClickHandler : MonoBehaviour
|
||||
if (otherScreen.z < 0) continue;
|
||||
|
||||
float otherDist = Vector2.Distance(mousePos, new Vector2(otherScreen.x, otherScreen.y));
|
||||
if (otherDist < myDist) return; // 别人比我更近,让别人处理
|
||||
if (otherDist < myDist) return;
|
||||
}
|
||||
|
||||
// 我是离鼠标最近的闪烁中的 ping!
|
||||
if (myDist < 120f) // 稍微放宽一点阈值,120像素内都算点中
|
||||
if (myDist < 120f)
|
||||
{
|
||||
Debug.Log($"[PingClick] 屏幕坐标命中: {name} (距离={myDist:F1}px)");
|
||||
_lastClickedFrame = Time.frameCount; // 锁定当前帧,其他 ping 不准再触发
|
||||
_lastClickedFrame = Time.frameCount;
|
||||
_isBlinking = false;
|
||||
PerformClick();
|
||||
}
|
||||
@@ -166,23 +187,29 @@ public class PingClickHandler : MonoBehaviour
|
||||
if (p.gameObject.activeInHierarchy && (p._isBlinking || p._modelShown))
|
||||
remaining++;
|
||||
}
|
||||
// 自己刚刚 HideSelf 了,如果没有其他活跃的 ping 了
|
||||
|
||||
if (remaining <= 1)
|
||||
{
|
||||
Debug.Log("[PingClick] 所有的 ping 都已经绑成 chanrao 了!播放完成语音。");
|
||||
var am = FindObjectOfType<AudioManager>();
|
||||
if (am != null)
|
||||
// 彻底修复:使用静态标志位锁定播放动作,这一轮绝不会播两次
|
||||
if (!_hasPlayedFinishVoice)
|
||||
{
|
||||
_hasPlayedFinishVoice = true;
|
||||
Debug.Log("[PingClick] 所有的 ping 都已经绑成 chanrao 了!播放完成语音。");
|
||||
var am = FindObjectOfType<AudioManager>();
|
||||
if (am != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var finishClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/伤员一切正常,包扎完毕.mp3");
|
||||
if (finishClip != null) am.PlayVoice(finishClip);
|
||||
var finishClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/伤员一切正常,包扎完毕.mp3");
|
||||
if (finishClip != null) am.PlayVoice(finishClip);
|
||||
#endif
|
||||
}
|
||||
|
||||
var uiMgr = FindObjectOfType<UIManager>();
|
||||
if (uiMgr != null)
|
||||
{
|
||||
uiMgr.HideVideo();
|
||||
}
|
||||
|
||||
var uiMgr = FindObjectOfType<UIManager>();
|
||||
if (uiMgr != null)
|
||||
{
|
||||
uiMgr.HideVideo();
|
||||
uiMgr.ShowEndPanel(); // 调用显示结束面板
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +225,7 @@ public class PingClickHandler : MonoBehaviour
|
||||
}
|
||||
|
||||
_isBlinking = true;
|
||||
_enableFrame = Time.frameCount; // 防止重置瞬间被点中
|
||||
_enableFrame = Time.frameCount;
|
||||
|
||||
if (_outlineMesh != null)
|
||||
{
|
||||
@@ -221,7 +248,11 @@ public class PingClickHandler : MonoBehaviour
|
||||
ShowSelf();
|
||||
_modelShown = true;
|
||||
_isBlinking = true;
|
||||
_enableFrame = Time.frameCount; // 防止重置瞬间被点中
|
||||
_enableFrame = Time.frameCount;
|
||||
|
||||
// 撤销的时候,把语音锁打开,以便能够重新播放
|
||||
_hasPlayedFinishVoice = false;
|
||||
|
||||
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(BlinkOutline());
|
||||
@@ -254,7 +285,10 @@ public class PingClickHandler : MonoBehaviour
|
||||
{
|
||||
_modelShown = false;
|
||||
_isBlinking = true;
|
||||
_enableFrame = Time.frameCount; // 防止重置瞬间被点中
|
||||
_enableFrame = Time.frameCount;
|
||||
|
||||
_hasPlayedFinishVoice = false;
|
||||
|
||||
if (_modelRenderer != null) _modelRenderer.enabled = false;
|
||||
foreach (var r in GetComponentsInChildren<Renderer>(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; }
|
||||
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
||||
|
||||
+84
-199
@@ -1,11 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// UI 中央调度器:引用所有子面板,绑定 StepManager 事件。
|
||||
/// 按钮策略:同时绑定 Inspector 引用(旧 RightButtons)和 ExperimentPanel/Navbar 按钮(新 UI),
|
||||
/// 两者均可触发,互不冲突。
|
||||
/// </summary>
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[Header("管理器引用")]
|
||||
@@ -27,7 +22,7 @@ public class UIManager : MonoBehaviour
|
||||
[Header("=== 画中画视频 ===")]
|
||||
[SerializeField] private GameObject _videoPanel;
|
||||
|
||||
[Header("=== 仿真导航栏按钮(旧引用 + Navbar)===")]
|
||||
[Header("=== 仿真导航栏按钮 ===")]
|
||||
[SerializeField] private Button _btnFullScreen;
|
||||
[SerializeField] private Button _btnPrevious;
|
||||
[SerializeField] private Button _btnNext;
|
||||
@@ -41,185 +36,100 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
[Header("=== 弹窗 ===")]
|
||||
[SerializeField] private ExamPopup _examPopup;
|
||||
[SerializeField] private ScoreDisplay _scoreDisplay;
|
||||
|
||||
[Header("=== 底部图标 ===")]
|
||||
[SerializeField] private Button _btnCPR;
|
||||
[SerializeField] private Button _btnFracture;
|
||||
[SerializeField] private Button _btnSprain;
|
||||
[SerializeField] private Button _btnBleeding;
|
||||
[SerializeField] private Button _btnTransport;
|
||||
|
||||
[Header("=== 固定方式选择(仅骨折固定) ===")]
|
||||
[SerializeField] private GameObject _fixationPanel;
|
||||
[SerializeField] private Button _btnLimbFixation;
|
||||
[SerializeField] private Button _btnSplintFixation;
|
||||
[SerializeField] private GameObject _endPanel;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("=== UIManager 初始化开始 ===");
|
||||
|
||||
// 确保视频最开始是隐藏的
|
||||
HideVideo();
|
||||
if (_endPanel != null) _endPanel.SetActive(false);
|
||||
|
||||
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(); // 旧引用(RightButtons 等)
|
||||
BindNavbarButtons(); // 新 Navbar 按钮
|
||||
BindButtons();
|
||||
BindNavbarButtons();
|
||||
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;
|
||||
}
|
||||
|
||||
if (experimentPanel == null) return;
|
||||
var navbar = experimentPanel.transform.Find("Navbar");
|
||||
if (navbar == null)
|
||||
{
|
||||
Debug.LogError("UIManager: ExperimentPanel/Navbar 未找到!无法绑定 Navbar 按钮!");
|
||||
return;
|
||||
}
|
||||
if (navbar == null) return;
|
||||
|
||||
// FullScreen
|
||||
var btnFS = navbar.Find("FullScreen");
|
||||
if (btnFS != null)
|
||||
{
|
||||
var btn = btnFS.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.RemoveListener(ToggleFullScreen); btn.onClick.AddListener(ToggleFullScreen);
|
||||
Debug.Log("UIManager: Navbar/FullScreen 绑定成功 -> ToggleFullScreen");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/FullScreen 未找到");
|
||||
if (btnFS != null) { var btn = btnFS.GetComponent<Button>(); if (btn != null) { btn.onClick.RemoveListener(ToggleFullScreen); btn.onClick.AddListener(ToggleFullScreen); } }
|
||||
|
||||
// Previous
|
||||
var btnPrev = navbar.Find("Previous");
|
||||
if (btnPrev != null)
|
||||
{
|
||||
var btn = btnPrev.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.RemoveListener(OnPreviousClicked); btn.onClick.AddListener(OnPreviousClicked);
|
||||
Debug.Log("UIManager: Navbar/Previous 绑定成功 -> OnPreviousClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/Previous 未找到");
|
||||
if (btnPrev != null) { var btn = btnPrev.GetComponent<Button>(); if (btn != null) { btn.onClick.RemoveListener(OnPreviousClicked); btn.onClick.AddListener(OnPreviousClicked); } }
|
||||
|
||||
// Next
|
||||
var btnNext = navbar.Find("Next");
|
||||
if (btnNext != null)
|
||||
{
|
||||
var btn = btnNext.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.RemoveListener(OnNextClicked); btn.onClick.AddListener(OnNextClicked);
|
||||
Debug.Log("UIManager: Navbar/Next 绑定成功 -> OnNextClicked");
|
||||
}
|
||||
}
|
||||
else Debug.LogWarning("UIManager: Navbar/Next 未找到");
|
||||
if (btnNext != null) { var btn = btnNext.GetComponent<Button>(); if (btn != null) { btn.onClick.RemoveListener(OnNextClicked); btn.onClick.AddListener(OnNextClicked); } }
|
||||
|
||||
// PracticeMode
|
||||
var btnMode = navbar.Find("PracticeMode");
|
||||
if (btnMode != null)
|
||||
{
|
||||
var btn = btnMode.GetComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.RemoveListener(OnSwitchModeClicked); 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.RemoveListener(OnReturnClicked); 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()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
|
||||
_stepManager.OnStepChanged.AddListener(OnStepChanged);
|
||||
_stepManager.OnTipChanged.AddListener(UpdateTip);
|
||||
_stepManager.OnDialogueChanged.AddListener(UpdateDialogue);
|
||||
_stepManager.OnDetailedContent.AddListener(UpdateDetailContent);
|
||||
_stepManager.OnExamPopup.AddListener(ShowExamPopup);
|
||||
_stepManager.OnExperimentComplete.AddListener(OnExperimentComplete);
|
||||
_stepManager.OnVideoToggle.AddListener(ToggleVideo);
|
||||
Debug.Log("UIManager: StepManager 事件绑定完成");
|
||||
var btnReturn = navbar.Find("BtnBack");
|
||||
if (btnReturn != null) { var btn = btnReturn.GetComponent<Button>(); if (btn != null) { btn.onClick.RemoveListener(OnReturnClicked); btn.onClick.AddListener(OnReturnClicked); } }
|
||||
}
|
||||
|
||||
private void BindButtons()
|
||||
{
|
||||
if (_btnFullScreen != null) { _btnFullScreen.onClick.RemoveListener(ToggleFullScreen); _btnFullScreen.onClick.AddListener(ToggleFullScreen); Debug.Log("UIManager: _btnFullScreen 绑定成功"); }
|
||||
if (_btnPrevious != null) { _btnPrevious.onClick.RemoveListener(OnPreviousClicked); _btnPrevious.onClick.AddListener(OnPreviousClicked); Debug.Log("UIManager: _btnPrevious 绑定成功"); }
|
||||
if (_btnNext != null) { _btnNext.onClick.RemoveListener(OnNextClicked); _btnNext.onClick.AddListener(OnNextClicked); Debug.Log("UIManager: _btnNext 绑定成功"); }
|
||||
if (_btnSwitchMode != null) { _btnSwitchMode.onClick.RemoveListener(OnSwitchModeClicked); _btnSwitchMode.onClick.AddListener(OnSwitchModeClicked); Debug.Log("UIManager: _btnSwitchMode 绑定成功"); }
|
||||
if (_btnReturn != null) { _btnReturn.onClick.RemoveListener(OnReturnClicked); _btnReturn.onClick.AddListener(OnReturnClicked); Debug.Log("UIManager: _btnReturn 绑定成功"); }
|
||||
|
||||
// 注意: _btnLimbFixation/_btnSplintFixation 不再在这里绑定 SwitchFixation,
|
||||
// 固定方式选择由 PageController 的 OnFixationSelected 统一处理,避免双重触发污染 StepManager 状态。
|
||||
if (_btnFullScreen != null) { _btnFullScreen.onClick.RemoveListener(ToggleFullScreen); _btnFullScreen.onClick.AddListener(ToggleFullScreen); }
|
||||
if (_btnPrevious != null) { _btnPrevious.onClick.RemoveListener(OnPreviousClicked); _btnPrevious.onClick.AddListener(OnPreviousClicked); }
|
||||
if (_btnNext != null) { _btnNext.onClick.RemoveListener(OnNextClicked); _btnNext.onClick.AddListener(OnNextClicked); }
|
||||
if (_btnSwitchMode != null) { _btnSwitchMode.onClick.RemoveListener(OnSwitchModeClicked); _btnSwitchMode.onClick.AddListener(OnSwitchModeClicked); }
|
||||
if (_btnReturn != null) { _btnReturn.onClick.RemoveListener(OnReturnClicked); _btnReturn.onClick.AddListener(OnReturnClicked); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI 更新回调
|
||||
|
||||
private void OnStepChanged(int index)
|
||||
private void BindEvents()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
_stepManager.OnStepChanged.AddListener(OnStepChanged);
|
||||
_stepManager.OnTipChanged.AddListener(UpdateTipContent);
|
||||
_stepManager.OnDialogueChanged.AddListener(UpdateDialogueContent);
|
||||
_stepManager.OnDetailedContent.AddListener(UpdateDetailContent);
|
||||
_stepManager.OnVideoToggle.AddListener(ToggleVideo);
|
||||
_stepManager.OnExamPopup.AddListener(ShowExamPopup);
|
||||
_stepManager.OnExperimentComplete.AddListener(OnExperimentComplete);
|
||||
_stepManager.OnModeUIUpdate.AddListener(UpdateModeUI);
|
||||
}
|
||||
|
||||
private void UpdateModeUI(bool isExamMode)
|
||||
{
|
||||
if (_btnSwitchModeLabel != null)
|
||||
_btnSwitchModeLabel.text = isExamMode ? "切换到:练习模式" : "切换到:考核模式";
|
||||
}
|
||||
|
||||
private void OnStepChanged(int stepIndex)
|
||||
{
|
||||
Debug.Log($"UIManager: [OnStepChanged] 步骤 = {index + 1}");
|
||||
UpdateProgressBar();
|
||||
UpdateNavigationButtons();
|
||||
}
|
||||
|
||||
private void UpdateTip(string text)
|
||||
private void UpdateTipContent(string text)
|
||||
{
|
||||
if (_tipPanel != null) _tipPanel.SetActive(!string.IsNullOrEmpty(text));
|
||||
if (_tipText != null) _tipText.text = text;
|
||||
}
|
||||
|
||||
private void UpdateDialogue(string text)
|
||||
private void UpdateDialogueContent(string text)
|
||||
{
|
||||
if (_dialogueBubble != null) _dialogueBubble.SetActive(!string.IsNullOrEmpty(text));
|
||||
if (_dialogueText != null) _dialogueText.text = text;
|
||||
if (_dialogueBubble == null)
|
||||
{
|
||||
var t = GameObject.Find("Canvas")?.transform.Find("DialogueBubble");
|
||||
if (t != null) _dialogueBubble = t.gameObject;
|
||||
}
|
||||
|
||||
if (_dialogueBubble != null)
|
||||
{
|
||||
_dialogueBubble.SetActive(!string.IsNullOrEmpty(text));
|
||||
var txt = _dialogueBubble.GetComponentInChildren<Text>();
|
||||
if (txt != null) txt.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDetailContent(string text)
|
||||
@@ -230,11 +140,8 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void ToggleVideo(string fileName, bool active)
|
||||
{
|
||||
Debug.Log($"UIManager: [ToggleVideo] file={fileName}, active={active}");
|
||||
if (active && !string.IsNullOrEmpty(fileName))
|
||||
ShowVideo(fileName);
|
||||
else
|
||||
HideVideo();
|
||||
if (active && !string.IsNullOrEmpty(fileName)) ShowVideo(fileName);
|
||||
else HideVideo();
|
||||
}
|
||||
|
||||
public void ShowVideo(string fileName)
|
||||
@@ -243,16 +150,7 @@ public class UIManager : MonoBehaviour
|
||||
{
|
||||
_videoPanel.SetActive(true);
|
||||
var vp = _videoPanel.GetComponentInChildren<UnityEngine.Video.VideoPlayer>(true);
|
||||
if (vp != null)
|
||||
{
|
||||
vp.isLooping = true;
|
||||
// 不再通过代码强制覆盖路径,直接播放组件上预先配置好的视频
|
||||
vp.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("UIManager: 在 _videoPanel 中没有找到 VideoPlayer 组件!");
|
||||
}
|
||||
if (vp != null) vp.Play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +164,28 @@ public class UIManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowEndPanel()
|
||||
{
|
||||
if (_endPanel == null)
|
||||
{
|
||||
var t = GameObject.Find("Canvas")?.transform.Find("EndPanel");
|
||||
if (t != null) _endPanel = t.gameObject;
|
||||
}
|
||||
|
||||
if (_endPanel != null)
|
||||
{
|
||||
_endPanel.SetActive(true);
|
||||
|
||||
// 绑定返回首页按钮
|
||||
var btnRet = _endPanel.transform.Find("BtnReturn")?.GetComponent<Button>();
|
||||
if (btnRet != null)
|
||||
{
|
||||
btnRet.onClick.RemoveAllListeners();
|
||||
btnRet.onClick.AddListener(OnReturnClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateProgressBar()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
@@ -278,7 +198,6 @@ public class UIManager : MonoBehaviour
|
||||
private void UpdateNavigationButtons()
|
||||
{
|
||||
if (_stepManager == null) return;
|
||||
|
||||
if (_btnPrevious != null) _btnPrevious.interactable = true;
|
||||
if (_btnNext != null)
|
||||
{
|
||||
@@ -287,57 +206,28 @@ public class UIManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 考核弹窗
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 实验完成
|
||||
|
||||
private void OnExperimentComplete()
|
||||
{
|
||||
Debug.Log("UIManager: [OnExperimentComplete] 实验完成");
|
||||
var gm = GameManager.Instance;
|
||||
if (gm == null) return;
|
||||
if (gm.CurrentMode == ExperimentMode.Exam)
|
||||
_scoreDisplay?.ShowExamScore();
|
||||
else
|
||||
_scoreDisplay?.ShowNotesOnly();
|
||||
ShowEndPanel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 按钮回调
|
||||
|
||||
private void ToggleFullScreen()
|
||||
{
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
Debug.Log($"UIManager: [ToggleFullScreen] 全屏 = {Screen.fullScreen}");
|
||||
}
|
||||
private void ToggleFullScreen() { Screen.fullScreen = !Screen.fullScreen; }
|
||||
|
||||
private void OnNextClicked()
|
||||
{
|
||||
Debug.LogError("====== UIManager: 点击了【下一步】按钮! ======");
|
||||
if (_stepManager == null)
|
||||
{
|
||||
_stepManager = FindObjectOfType<StepManager>();
|
||||
Debug.LogError($"====== UIManager: 重新寻找 StepManager 结果: {_stepManager != null} ======");
|
||||
}
|
||||
if (_stepManager == null) _stepManager = FindObjectOfType<StepManager>();
|
||||
|
||||
if (_stepManager != null && _stepManager.Mode == ExperimentMode.Exam)
|
||||
{
|
||||
@@ -350,7 +240,6 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void OnPreviousClicked()
|
||||
{
|
||||
Debug.LogError("====== UIManager: 点击了【上一步】按钮! ======");
|
||||
if (_stepManager == null) _stepManager = FindObjectOfType<StepManager>();
|
||||
_stepManager?.PreviousStep();
|
||||
}
|
||||
@@ -360,19 +249,15 @@ public class UIManager : MonoBehaviour
|
||||
if (_stepManager == null) return;
|
||||
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] -> 返回首页");
|
||||
// 先隐藏面板
|
||||
if (_endPanel != null) _endPanel.SetActive(false);
|
||||
|
||||
var pageCtrl = FindObjectOfType<PageController>();
|
||||
if (pageCtrl != null)
|
||||
pageCtrl.ReturnToHome();
|
||||
else
|
||||
Debug.LogWarning("UIManager: 未找到 PageController。");
|
||||
if (pageCtrl != null) pageCtrl.ReturnToHome();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user