_xiaofang/xiaofang/Assets/Res/gsj/scripts/Panel3.cs

136 lines
4.1 KiB
C#
Raw Normal View History

2024-12-20 10:10:19 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Panel3 : MonoBehaviour
{
private Button cancel;
private Button online;//Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť
private Button follow;//<2F><><EFBFBD><EFBFBD><EFBFBD>鰴ť
private Dropdown dropdown;
private int optionCount; // <20><><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>Dropdownѡ<6E><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
2024-12-23 14:46:56 +08:00
private GameObject peopleposition;
2024-12-25 11:01:30 +08:00
private Camera godView;
public List<Camera> playerCameras = new List<Camera>(); // <20>洢ÿ<E6B4A2><C3BF><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private int currentCameraIndex = -1;
private bool isGodView = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD>ǰΪ<C7B0>ϵ<EFBFBD><CFB5>ӽ<EFBFBD>
private GameObject[] players;
2024-12-20 10:10:19 +08:00
// 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);
2024-12-23 14:46:56 +08:00
peopleposition = GameObject.Find("peopleposition").gameObject;
2024-12-24 20:21:15 +08:00
peopleposition.SetActive(false);
2024-12-25 11:01:30 +08:00
godView=GameObject.Find("TopCamera").GetComponent<Camera>();
2024-12-24 20:21:15 +08:00
2024-12-25 11:01:30 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>б<EFBFBD>ǩΪ "Player" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GameObject[] players = GameObject.FindGameObjectsWithTag("People");
foreach (GameObject player in players)
{
Camera camera = player.GetComponentInChildren<Camera>();
if (camera != null)
{
playerCameras.Add(camera);
camera.enabled = true; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
currentCameraIndex = Panel2.instance.currentCameraIndex;
2024-12-25 23:37:40 +08:00
dropdown.value= currentCameraIndex;
2024-12-25 11:01:30 +08:00
for(int i = 0; i < playerCameras.Count; i++)
{
if(i!=currentCameraIndex)
{
playerCameras[i].enabled = false;
}
}
}
// <20>л<EFBFBD><D0BB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SwitchToCamera(int index)
{
if (index < 0 || index >= playerCameras.Count)
{
Debug.LogWarning("<22><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + index);
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
godView.enabled = false;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (var camera in playerCameras)
{
camera.enabled = false;
}
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
currentCameraIndex = index;
playerCameras[index].enabled = true;
isGodView = false; // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ϵ<EFBFBD><CFB5>ӽ<EFBFBD>
}
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ӽ<EFBFBD>
public void SwitchToGodView()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (var camera in playerCameras)
{
camera.enabled=false;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
godView.enabled = true;
isGodView = true;
currentCameraIndex = -1;
2024-12-20 10:10:19 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dropdownѡ<6E><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
public void SetOptionCount(int count)
{
optionCount = count;
dropdown.ClearOptions();
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var options = new System.Collections.Generic.List<string>();
for (int i = 0; i < optionCount; i++)
{
options.Add("<22><>ɫ " + (i + 1)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><>ɫ 1"<22><>"<22><>ɫ 2"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>ɰ<EFBFBD><C9B0><EFBFBD><EFBFBD>޸<EFBFBD>
}
dropdown.AddOptions(options);
}
// Update is called once per frame
void Update()
{
}
void OnCancelBtn()
{
2024-12-23 14:46:56 +08:00
peopleposition.gameObject.SetActive(true);
2024-12-20 10:10:19 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ӽǽ<D3BD><C7BD><EFBFBD>
2024-12-25 11:01:30 +08:00
SwitchToGodView();
// Camera.main.enabled = true;
2024-12-20 10:10:19 +08:00
Game.uiManager.ShowUI<Image>("Panel1_2");
Game.uiManager.CloseUI("Panel1_3");
}
void OnClickOnlineBtn()
{
//<2F><>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>״̬,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Game.uiManager.ShowUI<Image>("Panel");
}
void FollowBtn()
{
2024-12-25 11:01:30 +08:00
2024-12-20 10:10:19 +08:00
//ת<><D7AA><EFBFBD><EFBFBD>ɫ<EFBFBD>ӽ<EFBFBD>
int selectedIndex = dropdown.value;
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ" + (selectedIndex+1) + "<22>ӽ<EFBFBD>");
2024-12-25 11:01:30 +08:00
SwitchToCamera(selectedIndex);
2024-12-20 10:10:19 +08:00
}
}