fix: 清理AI遗留代码,修复场景配置
- 删除三套旧菜单系统 (MainMenu.cs, MainMenuUI.cs, ModeSelectionUI.cs) - Ground 添加 BoxCollider 并设置 tag 为 Ground - UIManager.OnReturnClicked 改为通过 PageController 返回首页 - PageController 增加 ReturnToHome 方法,管理 BtnFixationBack 可见性 - 清理废弃场景 Experiment.unity / ModeSelection.unity 及历史截图
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
/// <summary>
|
||||
/// 主菜单:实验类型选择 + 模式选择 + 固定方式选择。
|
||||
/// 挂在主菜单场景的 Canvas 上。
|
||||
/// </summary>
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
[Header("主标题")]
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[Header("实验选择按钮 - 底部图标")]
|
||||
[SerializeField] private Button _btnCPR;
|
||||
[SerializeField] private Button _btnFracture;
|
||||
[SerializeField] private Button _btnSprain;
|
||||
[SerializeField] private Button _btnBleeding;
|
||||
[SerializeField] private Button _btnTransport;
|
||||
|
||||
[Header("模式选择")]
|
||||
[SerializeField] private TMP_Text _tipText;
|
||||
[SerializeField] private Button _btnLearnMode;
|
||||
[SerializeField] private Button _btnExamMode;
|
||||
[SerializeField] private TMP_Text _selectedModeLabel;
|
||||
|
||||
[Header("固定方式选择(仅骨折固定)")]
|
||||
[SerializeField] private GameObject _fixationPanel;
|
||||
[SerializeField] private Button _btnLimbFixation;
|
||||
[SerializeField] private Button _btnSplintFixation;
|
||||
[SerializeField] private TMP_Text _selectedFixationLabel;
|
||||
|
||||
[Header("开始按钮")]
|
||||
[SerializeField] private Button _btnStart;
|
||||
|
||||
[Header("提示")]
|
||||
[SerializeField] private TMP_Text _selectionTip;
|
||||
|
||||
// 当前选择
|
||||
private ExperimentType _selectedType = ExperimentType.FractureFixation;
|
||||
private ExperimentMode _selectedMode = ExperimentMode.Learn;
|
||||
private FixationMethod _selectedFixation = FixationMethod.LimbFixation;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
BindExperimentButtons();
|
||||
_btnLearnMode?.onClick.AddListener(() => SelectMode(ExperimentMode.Learn));
|
||||
_btnExamMode?.onClick.AddListener(() => SelectMode(ExperimentMode.Exam));
|
||||
_btnLimbFixation?.onClick.AddListener(() => SelectFixation(FixationMethod.LimbFixation));
|
||||
_btnSplintFixation?.onClick.AddListener(() => SelectFixation(FixationMethod.SplintFixation));
|
||||
_btnStart?.onClick.AddListener(StartExperiment);
|
||||
|
||||
// 默认选中骨折固定
|
||||
SelectExperiment(ExperimentType.FractureFixation);
|
||||
SelectMode(ExperimentMode.Learn);
|
||||
SelectFixation(FixationMethod.LimbFixation);
|
||||
}
|
||||
|
||||
private void BindExperimentButtons()
|
||||
{
|
||||
_btnCPR?.onClick.AddListener(() => SelectExperiment(ExperimentType.CPR));
|
||||
_btnFracture?.onClick.AddListener(() => SelectExperiment(ExperimentType.FractureFixation));
|
||||
_btnSprain?.onClick.AddListener(() => SelectExperiment(ExperimentType.SprainBandaging));
|
||||
_btnBleeding?.onClick.AddListener(() => SelectExperiment(ExperimentType.BleedingBandaging));
|
||||
_btnTransport?.onClick.AddListener(() => SelectExperiment(ExperimentType.CasualtyTransport));
|
||||
}
|
||||
|
||||
private void SelectExperiment(ExperimentType type)
|
||||
{
|
||||
_selectedType = type;
|
||||
// 骨折固定显示固定方式面板
|
||||
bool isFracture = type == ExperimentType.FractureFixation;
|
||||
if (_fixationPanel != null) _fixationPanel.SetActive(isFracture);
|
||||
if (_selectionTip != null)
|
||||
_selectionTip.text = isFracture ? "Tip:请选择固定方式" : "";
|
||||
UpdateStartButton();
|
||||
}
|
||||
|
||||
private void SelectMode(ExperimentMode mode)
|
||||
{
|
||||
_selectedMode = mode;
|
||||
if (_selectedModeLabel != null)
|
||||
_selectedModeLabel.text = mode == ExperimentMode.Learn ? "学习模式" : "考核模式";
|
||||
UpdateStartButton();
|
||||
}
|
||||
|
||||
private void SelectFixation(FixationMethod fixation)
|
||||
{
|
||||
_selectedFixation = fixation;
|
||||
if (_selectedFixationLabel != null)
|
||||
_selectedFixationLabel.text = fixation == FixationMethod.LimbFixation ? "肢体固定" : "夹板固定";
|
||||
UpdateStartButton();
|
||||
}
|
||||
|
||||
private void UpdateStartButton()
|
||||
{
|
||||
if (_btnStart == null) return;
|
||||
_btnStart.interactable = true;
|
||||
}
|
||||
|
||||
private void StartExperiment()
|
||||
{
|
||||
var gm = GameManager.Instance;
|
||||
if (gm == null)
|
||||
{
|
||||
Debug.LogError("MainMenu: GameManager.Instance 为空!请确保场景中有 GameManager。");
|
||||
return;
|
||||
}
|
||||
|
||||
gm.CurrentExperimentType = _selectedType;
|
||||
gm.CurrentMode = _selectedMode;
|
||||
gm.CurrentFixationMethod = _selectedFixation;
|
||||
|
||||
// 加载实验场景(所有实验共用一个场景,StepManager 根据配置区分)
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene("Experiment");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57051b77bff694c5aaf5db8bc804cedd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,38 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Main menu UI — assign all fields in Inspector.
|
||||
/// </summary>
|
||||
public class MainMenuUI : MonoBehaviour
|
||||
{
|
||||
[Header("Text")]
|
||||
public Text titleText;
|
||||
public Text versionText;
|
||||
|
||||
[Header("Buttons")]
|
||||
public Button cprButton;
|
||||
public Button fractureButton;
|
||||
public Button sprainButton;
|
||||
public Button bleedingButton;
|
||||
public Button transportButton;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (titleText != null) titleText.text = "运动伤害现场急救处理虚拟仿真实验";
|
||||
if (versionText != null) versionText.text = $"v{Application.version}";
|
||||
|
||||
if (cprButton != null) cprButton.onClick.AddListener(() => OnSelect("CPR"));
|
||||
if (fractureButton != null) fractureButton.onClick.AddListener(() => OnSelect("FractureFixation"));
|
||||
if (sprainButton != null) sprainButton.onClick.AddListener(() => OnSelect("SprainBandage"));
|
||||
if (bleedingButton != null) bleedingButton.onClick.AddListener(() => OnSelect("BleedingBandage"));
|
||||
if (transportButton != null) transportButton.onClick.AddListener(() => OnSelect("CasualtyTransport"));
|
||||
}
|
||||
|
||||
private void OnSelect(string experimentId)
|
||||
{
|
||||
PlayerPrefs.SetString("SelectedExperiment", experimentId);
|
||||
SceneManager.LoadScene("ModeSelection");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fca7ea321dc34ab19b4bea56e90e8a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,72 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ModeSelectionUI : MonoBehaviour
|
||||
{
|
||||
[Header("Tip")]
|
||||
public Text tipText;
|
||||
|
||||
[Header("Fixation Mode")]
|
||||
public Button limbFixationButton;
|
||||
public Button splintFixationButton;
|
||||
public GameObject limbFixationCheck;
|
||||
public GameObject splintFixationCheck;
|
||||
|
||||
[Header("Run Mode")]
|
||||
public Button learnModeButton;
|
||||
public Button examModeButton;
|
||||
public GameObject learnModeCheck;
|
||||
public GameObject examModeCheck;
|
||||
|
||||
[Header("Actions")]
|
||||
public Button startButton;
|
||||
public Button backButton;
|
||||
|
||||
private FixationMethod selectedFixation = FixationMethod.LimbFixation;
|
||||
private ExperimentMode selectedRunMode = ExperimentMode.Learn;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
tipText.text = "Tip:请选择实验模式";
|
||||
|
||||
limbFixationButton.onClick.AddListener(() => SelectFixation(FixationMethod.LimbFixation));
|
||||
splintFixationButton.onClick.AddListener(() => SelectFixation(FixationMethod.SplintFixation));
|
||||
learnModeButton.onClick.AddListener(() => SelectRunMode(ExperimentMode.Learn));
|
||||
examModeButton.onClick.AddListener(() => SelectRunMode(ExperimentMode.Exam));
|
||||
startButton.onClick.AddListener(OnStart);
|
||||
backButton.onClick.AddListener(() => SceneManager.LoadScene("main"));
|
||||
|
||||
UpdateSelectionVisuals();
|
||||
}
|
||||
|
||||
private void SelectFixation(FixationMethod mode)
|
||||
{
|
||||
selectedFixation = mode;
|
||||
UpdateSelectionVisuals();
|
||||
}
|
||||
|
||||
private void SelectRunMode(ExperimentMode mode)
|
||||
{
|
||||
selectedRunMode = mode;
|
||||
UpdateSelectionVisuals();
|
||||
}
|
||||
|
||||
private void UpdateSelectionVisuals()
|
||||
{
|
||||
limbFixationCheck.SetActive(selectedFixation == FixationMethod.LimbFixation);
|
||||
splintFixationCheck.SetActive(selectedFixation == FixationMethod.SplintFixation);
|
||||
learnModeCheck.SetActive(selectedRunMode == ExperimentMode.Learn);
|
||||
examModeCheck.SetActive(selectedRunMode == ExperimentMode.Exam);
|
||||
}
|
||||
|
||||
private void OnStart()
|
||||
{
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.CurrentFixationMethod = selectedFixation;
|
||||
GameManager.Instance.CurrentMode = selectedRunMode;
|
||||
}
|
||||
SceneManager.LoadScene("Experiment");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2106746edd5ca43288aff94f664b16ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -126,18 +126,18 @@ 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 (_uiManager != null)
|
||||
_uiManager.enabled = (page == Page.Experiment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 按钮回调
|
||||
@@ -206,5 +206,11 @@ public class PageController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnToHome()
|
||||
{
|
||||
ShowPage(Page.Home);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -214,7 +214,11 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
private void OnReturnClicked()
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene("main");
|
||||
var pageCtrl = FindObjectOfType<PageController>();
|
||||
if (pageCtrl != null)
|
||||
pageCtrl.ReturnToHome();
|
||||
else
|
||||
Debug.LogWarning("UIManager: 未找到 PageController,无法返回首页。");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user