2024-06-12 15:01:54 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
public class CameraController : MonoBehaviour
|
|
|
|
|
|
|
|
{
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
public float rayLength = 15f;
|
|
|
|
private RaycastHit hitInfo;
|
|
|
|
private Vector3 hitPoint;
|
|
|
|
private Ray ray;
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
Vector2 mousePosition = Mouse.current.position.ReadValue();
|
|
|
|
ray = Camera.main.ScreenPointToRay(new Vector3(mousePosition.x, mousePosition.y,
|
|
|
|
Camera.main.transform.position.z));
|
|
|
|
hitPoint = ray.origin + ray.direction * rayLength;
|
|
|
|
UnityEditor.SceneView.RepaintAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDrawGizmos()
|
|
|
|
{
|
|
|
|
Gizmos.color = Color.green;
|
|
|
|
Gizmos.DrawLine(ray.origin, hitPoint);
|
|
|
|
float halfSize = 0.2f;
|
|
|
|
Gizmos.color = Color.red;
|
|
|
|
Gizmos.DrawWireCube(hitPoint, new Vector3(halfSize * 2, halfSize * 2, halfSize * 2));
|
|
|
|
}
|
|
|
|
#endif
|
2024-07-18 20:01:43 +08:00
|
|
|
|
|
|
|
private Camera _camera;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
_camera = transform.GetComponent<Camera>();
|
|
|
|
var size = _camera.orthographicSize;
|
|
|
|
_camera.orthographicSize = size * GlobalConstants.DesignResolutionWidth /
|
|
|
|
GlobalConstants.DesignResolutionHeight * Screen.height / Screen.width;
|
|
|
|
}
|
2024-06-12 15:01:54 +08:00
|
|
|
}
|