_xiaofang/xiaofang/Assets/Script/Scheduled_03/Panel.cs

159 lines
3.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Panel : MonoBehaviour
{
public Button choseJuBenSettingBtn;
public Button emergencySettingBtn;
public Button peoplePublishBtn;
public Button materialReserveBtn;
public Button dateSelectionBtn;
public Button setName;//设置人员
public Button setDuty;//设置职责
public Button setScene;//设置场景
public string name, duty, scene;
public Button sureBtn;//确认信息按钮
public GraphicRaycaster raycaster; // 画布上的射线投射器
public EventSystem eventSystem; // 事件系统
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetData();
}
public void SetName()
{
}
public void SetDuty()
{
}
public void SetScene()
{
}
//处理点击选择剧本按钮
public void ClickChoseJuBenSettingBtn()
{
}
//处理点击应急人员配置按钮
public void ClickEmergencySettingBtn()
{
}
//处理点击疏散人群公布按钮
public void ClickPeoplePublishBtn()
{
}
//处理点击应急物资储备按钮
public void ClickMaterialReserveBtn()
{
}
//处理点击选择演练日期按钮
public void ClickDateSelectionBtn()
{
}
//处理点击确认按钮
public void ClickSureBtn()
{
SceneManager.LoadScene("Schedule_a_walkthrough");
}
public void GetData()
{
// 当鼠标左键按下时进行检测
if (Input.GetMouseButtonDown(0))
{
// 确保 raycaster 和 eventSystem 不为空
if (raycaster == null || eventSystem == null)
{
Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。");
return;
}
// 创建 PointerEventData 来记录点击事件的数据
PointerEventData pointerData = new PointerEventData(eventSystem);
pointerData.position = Input.mousePosition;
// 用于存储射线检测的结果
List<RaycastResult> results = new List<RaycastResult>();
// 射线检测 UI
raycaster.Raycast(pointerData, results);
// 遍历射线检测的结果
foreach (RaycastResult result in results)
{
// 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>();
if (clickedButton != null)
{
Text buttonText = clickedButton.GetComponentInChildren<Text>();
if (buttonText != null && buttonText.tag == Tags.people)
{
name = buttonText.text;
Debug.Log(name);
}
else if (buttonText != null && buttonText.tag == Tags.scene)
{
scene = buttonText.text;
Debug.Log(scene);
}
else if (buttonText != null && buttonText.tag == Tags.duty)
{
duty = buttonText.text;
Debug.Log(duty);
}
}
}
}
}
}