136 lines
4.1 KiB
C#
136 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static UnityEditor.Experimental.GraphView.GraphView;
|
|
|
|
public class Panel3 : MonoBehaviour
|
|
{
|
|
private Button cancel;
|
|
private Button online;//目前在线离线状况弹窗按钮
|
|
private Button follow;//跟随查按钮
|
|
private Dropdown dropdown;
|
|
private int optionCount; // 用于存储传入的确定Dropdown选项数量的参数
|
|
private GameObject peopleposition;
|
|
private Camera godView;
|
|
public List<Camera> playerCameras = new List<Camera>(); // 存储每个角色的摄像机
|
|
private int currentCameraIndex = -1;
|
|
private bool isGodView = false; // 是否当前为上帝视角
|
|
private GameObject[] players;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
cancel=transform.Find("left/btn_enddrill").GetComponent<Button>();
|
|
cancel.onClick.AddListener(OnCancelBtn);
|
|
online=transform.Find("onlineBtn").GetComponent <Button>();
|
|
online.onClick.AddListener(OnClickOnlineBtn);
|
|
dropdown=transform.Find("left/Dropdown").GetComponent<Dropdown>();
|
|
follow = transform.Find("left/Follow").GetComponent<Button>();
|
|
follow.onClick.AddListener(FollowBtn);
|
|
peopleposition = GameObject.Find("peopleposition").gameObject;
|
|
peopleposition.SetActive(false);
|
|
godView=GameObject.Find("TopCamera").GetComponent<Camera>();
|
|
|
|
|
|
// 获取所有标签为 "Player" 的物体
|
|
GameObject[] players = GameObject.FindGameObjectsWithTag("People");
|
|
|
|
foreach (GameObject player in players)
|
|
{
|
|
Camera camera = player.GetComponentInChildren<Camera>();
|
|
if (camera != null)
|
|
{
|
|
playerCameras.Add(camera);
|
|
camera.enabled = true; // 初始化时禁用所有角色摄像机
|
|
}
|
|
}
|
|
currentCameraIndex = Panel2.instance.currentCameraIndex;
|
|
for(int i = 0; i < playerCameras.Count; i++)
|
|
{
|
|
if(i!=currentCameraIndex)
|
|
{
|
|
playerCameras[i].enabled = false;
|
|
}
|
|
}
|
|
}
|
|
// 切换到指定索引的摄像机
|
|
public void SwitchToCamera(int index)
|
|
{
|
|
if (index < 0 || index >= playerCameras.Count)
|
|
{
|
|
Debug.LogWarning("无效的摄像机索引:" + index);
|
|
return;
|
|
}
|
|
|
|
// 禁用上帝视角摄像机
|
|
godView.enabled = false;
|
|
|
|
// 禁用所有角色摄像机
|
|
foreach (var camera in playerCameras)
|
|
{
|
|
camera.enabled = false;
|
|
}
|
|
|
|
// 激活目标角色摄像机
|
|
currentCameraIndex = index;
|
|
playerCameras[index].enabled = true;
|
|
isGodView = false; // 标记为非上帝视角
|
|
}
|
|
// 切换到上帝视角
|
|
public void SwitchToGodView()
|
|
{
|
|
// 禁用所有角色摄像机
|
|
foreach (var camera in playerCameras)
|
|
{
|
|
camera.enabled=false;
|
|
}
|
|
|
|
// 激活上帝视角摄像机
|
|
godView.enabled = true;
|
|
isGodView = true;
|
|
currentCameraIndex = -1;
|
|
}
|
|
// 用于外部传入参数来设置Dropdown选项数量的方法
|
|
public void SetOptionCount(int count)
|
|
{
|
|
optionCount = count;
|
|
dropdown.ClearOptions();
|
|
// 创建一个临时的字符串列表用于添加选项内容
|
|
var options = new System.Collections.Generic.List<string>();
|
|
for (int i = 0; i < optionCount; i++)
|
|
{
|
|
options.Add("角色 " + (i + 1)); // 简单添加类似"角色 1"、"角色 2"这样的选项名称,可按需修改
|
|
}
|
|
dropdown.AddOptions(options);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
void OnCancelBtn()
|
|
{
|
|
peopleposition.gameObject.SetActive(true);
|
|
//返回上帝视角界面
|
|
SwitchToGodView();
|
|
// Camera.main.enabled = true;
|
|
Game.uiManager.ShowUI<Image>("Panel1_2");
|
|
Game.uiManager.CloseUI("Panel1_3");
|
|
}
|
|
void OnClickOnlineBtn()
|
|
{
|
|
//人员在线状态,弹出窗口
|
|
Game.uiManager.ShowUI<Image>("Panel");
|
|
}
|
|
void FollowBtn()
|
|
{
|
|
|
|
//转化角色视角
|
|
int selectedIndex = dropdown.value;
|
|
Debug.Log("进入角色" + (selectedIndex+1) + "视角");
|
|
SwitchToCamera(selectedIndex);
|
|
|
|
}
|
|
}
|