ShanxiKnowledgeBase/SXElectricalInspection/Assets/GuYuan/KDLCamera/CameraManager.cs

89 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Threading.Tasks;
using Unity.VisualScripting;
public class CameraManager : MonoBehaviour
{
[SerializeField] Button Btn;
[SerializeField] Transform trans;
[SerializeField] Vector3 tempPos;
[SerializeField] Transform Player;
Vector3 RotePos;
public bool isGang = false;
FirstPersonController f;
int sum = 1;
public string tips;
public int id;
public int score;
//TextMeshProUGUI text;
private async void Start()
{
await Task.Delay(100);
BtnOnClick(UIManager.Instance.bottomCotroller.BirdEyeView);
UIManager.Instance.toolsItemManager.SwitchAllToolItems();
//f = Player.transform.GetComponent<FirstPersonController>();
}
/// <summary>
/// µ÷Óø©î«¸³Öµ
/// </summary>
/// <param name="to"></param>
public void BtnOnClick(Toggle to)
{
to.gameObject.SetActive(true);
to.onValueChanged.AddListener((isOn) =>
{
GetComponent<Fraction>().CompletedorNot = true;
//if (sum % 2 != 0)
//{
// OverLook();
//}
//else
//{
// ReturnLook();
//}
//sum++;
if (isOn)
{
OverLook();
}
else
{
ReturnLook();
}
});
}
void OverLook()
{
f.cameraCanMove = false;
f.rb.useGravity = false;
f.enabled = false;
f.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
f.yaw = 0;
f.pitch = 0;
tempPos = Player.transform.localPosition;
RotePos = Player.transform.localEulerAngles;
Player.transform.localPosition = trans.localPosition;
Player.transform.localEulerAngles = trans.localEulerAngles;
f.playerCamera.transform.localEulerAngles = Vector3.zero;
//f.AddComponent<Rigidbody>();
}
void ReturnLook()
{
Player.transform.localPosition = tempPos;
Player.transform.localEulerAngles = RotePos;
f.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
//f.playerCamera.transform.localEulerAngles = Vector3.zero;
f.rb.useGravity = true;
f.enabled = true;
f.cameraCanMove = true;
}
}