83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
// 进入实验室的脚本
|
||
public class EnterLab : MonoBehaviour
|
||
{
|
||
public Transform targetPosition; // 目标位置
|
||
public Transform targetRotation; // 目标旋转(或直接指定一个 Quaternion)
|
||
public GameObject targetObject; // 目标对象(如果有)
|
||
public Camera camera; // 相机
|
||
public GameObject labUI; // 实验室UI
|
||
public GameObject systemUI; // 系统UI
|
||
public GameObject labCeiling; // 实验室天花板
|
||
public List<GameObject> hiddenObjectParents; // 实验室物体
|
||
public float cameraSize = 60f;
|
||
private float moveSpeed = 6.0f; // 移动速度
|
||
private float rotationSpeed = 3.0f; // 旋转速度
|
||
|
||
private bool isMoving = false;
|
||
public void OnMouseDown()
|
||
{
|
||
if (CameraMove.isStaticMove)
|
||
{
|
||
return;
|
||
}
|
||
|
||
print("点击了相机");
|
||
|
||
labCeiling.SetActive(true);
|
||
systemUI.SetActive(false);
|
||
|
||
camera.orthographicSize = cameraSize;
|
||
// 隐藏两边UI
|
||
foreach (GameObject obj in hiddenObjectParents)
|
||
{
|
||
foreach (Transform child in obj.transform)
|
||
{
|
||
child.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
MoveToTarget();
|
||
|
||
}
|
||
|
||
public void MoveToTarget()
|
||
{
|
||
isMoving = true;
|
||
CameraMove.isStaticMove = true;
|
||
camera.orthographic = false;
|
||
camera.fieldOfView = cameraSize;
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
|
||
if (isMoving)
|
||
{
|
||
// 平滑移动
|
||
camera.transform.position = Vector3.Lerp(camera.transform.position, targetPosition.position, moveSpeed * Time.deltaTime);
|
||
|
||
// 平滑旋转
|
||
camera.transform.rotation = Quaternion.Slerp(camera.transform.rotation, targetRotation.rotation, rotationSpeed * Time.deltaTime);
|
||
|
||
// 检查是否接近目标位置和旋转
|
||
if (Vector3.Distance(camera.transform.position, targetPosition.position) < 0.1f &&
|
||
Quaternion.Angle(camera.transform.rotation, targetRotation.rotation) < 0.1f)
|
||
{
|
||
camera.transform.position = targetPosition.position;
|
||
camera.transform.rotation = targetRotation.rotation;
|
||
isMoving = false;
|
||
CameraMove.isStaticMove = false;
|
||
labUI.SetActive(true);
|
||
if (targetObject!= null)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|