141 lines
3.9 KiB
C#
141 lines
3.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// BodyAndOrgans可见性控制演示脚本
|
|
/// 用于测试MainPanel中的自动模型显示/隐藏功能
|
|
/// </summary>
|
|
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<MainPanel>();
|
|
|
|
// 设置按钮事件
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示测试面板
|
|
/// </summary>
|
|
public void ShowTestPanel(GameObject panel)
|
|
{
|
|
if (panel != null)
|
|
{
|
|
panel.SetActive(true);
|
|
Debug.Log($"显示测试面板: {panel.name}");
|
|
UpdateStatusText();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏所有测试面板
|
|
/// </summary>
|
|
public void HideAllTestPanels()
|
|
{
|
|
if (TestPanel1 != null) TestPanel1.SetActive(false);
|
|
if (TestPanel2 != null) TestPanel2.SetActive(false);
|
|
|
|
Debug.Log("隐藏所有测试面板");
|
|
UpdateStatusText();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调试当前状态
|
|
/// </summary>
|
|
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<Canvas>();
|
|
Debug.Log($"Total Canvas count: {canvases.Length}");
|
|
|
|
foreach (var canvas in canvases)
|
|
{
|
|
Debug.Log($"Canvas: {canvas.name}, Order: {canvas.sortingOrder}, Active: {canvas.gameObject.activeInHierarchy}");
|
|
}
|
|
|
|
UpdateStatusText();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新状态文本
|
|
/// </summary>
|
|
private void UpdateStatusText()
|
|
{
|
|
if (StatusText == null) return;
|
|
|
|
string status = "BodyAndOrgans可见性测试\n";
|
|
|
|
if (mainPanel != null && mainPanel.BodyAndOrgans != null)
|
|
{
|
|
bool isVisible = mainPanel.BodyAndOrgans.activeInHierarchy;
|
|
status += $"模型状态: {(isVisible ? "显示" : "隐藏")}\n";
|
|
}
|
|
else
|
|
{
|
|
status += "模型状态: 未找到\n";
|
|
}
|
|
|
|
status += $"测试面板1: {(TestPanel1 != null && TestPanel1.activeInHierarchy ? "显示" : "隐藏")}\n";
|
|
status += $"测试面板2: {(TestPanel2 != null && TestPanel2.activeInHierarchy ? "显示" : "隐藏")}\n";
|
|
|
|
StatusText.text = status;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// 每秒更新一次状态显示
|
|
if (Time.frameCount % 60 == 0)
|
|
{
|
|
UpdateStatusText();
|
|
}
|
|
}
|
|
} |