using UnityEngine;
using UnityEngine.UI;
///
/// BodyAndOrgans可见性控制演示脚本
/// 用于测试MainPanel中的自动模型显示/隐藏功能
///
public class BodyAndOrgansVisibilityDemo : MonoBehaviour
{
[Header("测试面板")]
public GameObject TestPanel1;
public GameObject TestPanel2;
[Header("控制按钮")]
public Button ShowPanel1Button;
public Button ShowPanel2Button;
public Button HideAllButton;
public Button DebugButton;
[Header("信息显示")]
public Text StatusText;
private MainPanel mainPanel;
void Start()
{
// 查找MainPanel
mainPanel = FindObjectOfType();
// 设置按钮事件
if (ShowPanel1Button != null)
ShowPanel1Button.onClick.AddListener(() => ShowTestPanel(TestPanel1));
if (ShowPanel2Button != null)
ShowPanel2Button.onClick.AddListener(() => ShowTestPanel(TestPanel2));
if (HideAllButton != null)
HideAllButton.onClick.AddListener(HideAllTestPanels);
if (DebugButton != null)
DebugButton.onClick.AddListener(DebugCurrentState);
UpdateStatusText();
}
///
/// 显示测试面板
///
public void ShowTestPanel(GameObject panel)
{
if (panel != null)
{
panel.SetActive(true);
Debug.Log($"显示测试面板: {panel.name}");
UpdateStatusText();
}
}
///
/// 隐藏所有测试面板
///
public void HideAllTestPanels()
{
if (TestPanel1 != null) TestPanel1.SetActive(false);
if (TestPanel2 != null) TestPanel2.SetActive(false);
Debug.Log("隐藏所有测试面板");
UpdateStatusText();
}
///
/// 调试当前状态
///
public void DebugCurrentState()
{
Debug.Log("=== BodyAndOrgans可见性调试信息 ===");
if (mainPanel != null)
{
Debug.Log($"MainPanel found: {mainPanel.name}");
if (mainPanel.BodyAndOrgans != null)
{
Debug.Log($"BodyAndOrgans active: {mainPanel.BodyAndOrgans.activeInHierarchy}");
}
else
{
Debug.Log("BodyAndOrgans not assigned!");
}
}
else
{
Debug.Log("MainPanel not found!");
}
// 显示所有Canvas信息
Canvas[] canvases = FindObjectsOfType