2024-12-20 10:10:19 +08:00
using System.Collections ;
using System.Collections.Generic ;
using Unity.VisualScripting ;
using UnityEngine ;
using UnityEngine.UI ;
2024-12-24 20:21:15 +08:00
using System.Threading.Tasks ;
2024-12-20 10:10:19 +08:00
public class Panel2 : MonoBehaviour
{
2024-12-25 11:01:30 +08:00
public static Panel2 instance ;
2024-12-20 10:10:19 +08:00
private Toggle toggle ; //<2F> <> ɫ<EFBFBD> <C9AB> <EFBFBD> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD>
private Button follow ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> 鰴ť
private Button end ; //<2F> <> <EFBFBD> <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>
private List < GameObject > nameImage ; // <20> 洢<EFBFBD> <E6B4A2> <EFBFBD> н<EFBFBD> ɫ<EFBFBD> <C9AB> ǩ<EFBFBD> <C7A9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
private GameObject peopleposition ;
2024-12-24 20:21:15 +08:00
public Camera godView ; // <20> ϵ<EFBFBD> <CFB5> ӽǵ<D3BD> λ<EFBFBD> <CEBB>
2024-12-25 11:01:30 +08:00
public List < Camera > playerCameras = new List < Camera > ( ) ; // <20> 洢ÿ<E6B4A2> <C3BF> <EFBFBD> <EFBFBD> ɫ<EFBFBD> <C9AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2024-12-24 20:21:15 +08:00
private bool isGodView = true ; // <20> Ƿ<EFBFBD> Ϊ<EFBFBD> ϵ<EFBFBD> <CFB5> ӽ<EFBFBD>
2024-12-25 11:01:30 +08:00
public int currentCameraIndex = - 1 ;
2024-12-20 10:10:19 +08:00
// Start is called before the first frame update
void Start ( )
{
2024-12-25 11:01:30 +08:00
instance = this ;
2024-12-24 20:21:15 +08:00
godView = GameObject . Find ( "TopCamera" ) . GetComponent < Camera > ( ) ;
toggle = transform . Find ( "right/under/Toggle" ) . GetComponent < Toggle > ( ) ;
2024-12-20 10:10:19 +08:00
toggle . onValueChanged . AddListener ( OnToggleValueChanged ) ;
toggle . isOn = true ;
dropdown = transform . Find ( "left/Dropdown" ) . GetComponent < Dropdown > ( ) ;
follow = transform . Find ( "left/Follow" ) . GetComponent < Button > ( ) ;
follow . onClick . AddListener ( FollowBtn ) ;
end = transform . Find ( "left/btn_enddrill" ) . GetComponent < Button > ( ) ;
end . onClick . AddListener ( EndBtn ) ;
2024-12-25 11:01:30 +08:00
2024-12-23 14:46:56 +08:00
peopleposition = GameObject . Find ( "peopleposition" ) . gameObject ;
2024-12-20 10:10:19 +08:00
//<2F> <> ȡ<EFBFBD> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е <EFBFBD> Button <20> <> <EFBFBD> <EFBFBD>
nameImage = new List < GameObject > ( ) ;
foreach ( Transform child in peopleposition . transform )
{
// <20> <> <EFBFBD> <EFBFBD> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е <EFBFBD> "bg"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
Transform bgTransform = child . Find ( "nameImage" ) ;
if ( bgTransform ! = null )
{
nameImage . Add ( bgTransform . gameObject ) ;
}
}
2024-12-25 11:01:30 +08:00
// <20> <> ȡ<EFBFBD> <C8A1> <EFBFBD> б <EFBFBD> ǩΪ "People" <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GameObject [ ] players = GameObject . FindGameObjectsWithTag ( "People" ) ;
// <20> <> <EFBFBD> <EFBFBD> ÿ<EFBFBD> <C3BF> Player<65> <72> <EFBFBD> ҵ<EFBFBD> <D2B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е <EFBFBD> <D0B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
foreach ( GameObject player in players )
{
// <20> <> Player <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> в<EFBFBD> <D0B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
Camera camera = player . GetComponentInChildren < Camera > ( ) ;
if ( camera ! = null )
{
playerCameras . Add ( camera ) ;
camera . enabled = false ; // <20> <> ʼ <EFBFBD> <CABC> ʱ<EFBFBD> <CAB1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
}
}
// Ĭ<> <C4AC> ִ<EFBFBD> <D6B4> һ <EFBFBD> <D2BB> <EFBFBD> л<EFBFBD>
OnToggleValueChanged ( toggle . isOn ) ;
2024-12-20 10:10:19 +08:00
}
2024-12-25 11:01:30 +08:00
// <20> л<EFBFBD> <D0BB> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
public void SwitchToCamera ( int index )
{
var index2 = 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> <D8B1> ϵ<EFBFBD> <CFB5> ӽ<EFBFBD> <D3BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
godView . enabled = false ;
isGodView = false ;
// <20> <> <EFBFBD> õ<EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڽ<EFBFBD> ɫ<EFBFBD> ӽǣ<D3BD>
if ( currentCameraIndex > = 0 )
{
playerCameras [ index2 ] . enabled = false ;
}
// <20> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
currentCameraIndex = index ;
playerCameras [ currentCameraIndex ] . enabled = true ;
}
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 ( )
{
}
// Toggle״̬<D7B4> 仯ʱ<E4BBAF> <CAB1> <EFBFBD> õķ<C3B5> <C4B7> <EFBFBD>
void OnToggleValueChanged ( bool isOn )
{
// <20> <> <EFBFBD> <EFBFBD> Toggle<6C> <65> ״̬<D7B4> <CCAC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "nameImage"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
foreach ( var bgObject in nameImage )
{
bgObject . SetActive ( isOn ) ; // <20> <> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
}
}
void FollowBtn ( )
{
//<2F> л<EFBFBD> <D0BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ģʽ ,<2C> <> ʾ <EFBFBD> <CABE> ɫ<EFBFBD> ӽ<EFBFBD>
//peopleposition.SetActive(false);
int selectedIndex = dropdown . value ;
Debug . Log ( "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɫ" + ( selectedIndex + 1 ) + "<22> ӽ<EFBFBD> " ) ;
2024-12-24 20:21:15 +08:00
2024-12-25 11:01:30 +08:00
SwitchToCamera ( selectedIndex ) ; //ת<> <D7AA> <EFBFBD> ӽ<EFBFBD>
2024-12-20 10:10:19 +08:00
Game . uiManager . CloseUI ( "Panel1_2" ) ;
Game . uiManager . ShowUI < Image > ( "Panel1_3" ) ;
}
2024-12-24 20:21:15 +08:00
2024-12-20 10:10:19 +08:00
void EndBtn ( )
{
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ϰ
Game . uiManager . ShowUI < Image > ( "PoPhost" ) ;
2024-12-23 14:46:56 +08:00
}
2024-12-20 10:10:19 +08:00
}