mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-23 23:55:38 +03:00
160 lines
4.8 KiB
C#
160 lines
4.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using System.Collections;
|
|
public class forCamera : MonoBehaviour
|
|
/*{
|
|
public enum RotationAxes
|
|
{
|
|
MouseXAndY = 0,
|
|
MouseX = 1,
|
|
MouseY = 2
|
|
}
|
|
public RotationAxes axes = RotationAxes.MouseXAndY;
|
|
public float sensitivityHor = 1.0f;
|
|
public float sensitivityVert = 1.0f;
|
|
public float minimumVert = -45.0f;
|
|
public float maximumVert = 45.0f;
|
|
private float _rotationX = 0;
|
|
void Start()
|
|
{
|
|
Cursor.visible = true;
|
|
Rigidbody body = GetComponent<Rigidbody>();
|
|
if (body != null)
|
|
body.freezeRotation = true;
|
|
}
|
|
void Update()
|
|
{
|
|
if (axes == RotationAxes.MouseX)
|
|
{
|
|
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityHor, 0);
|
|
}
|
|
else if (axes == RotationAxes.MouseY)
|
|
{
|
|
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
|
|
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
|
|
float rotationY = transform.localEulerAngles.y;
|
|
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
|
|
}
|
|
else
|
|
{
|
|
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
|
|
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
|
|
float delta = Input.GetAxis("Mouse X") * sensitivityHor;
|
|
float rotationY = transform.localEulerAngles.y + delta;
|
|
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
|
|
}
|
|
}
|
|
}*/
|
|
|
|
|
|
|
|
|
|
{
|
|
public float sensitivity = 1.5f;
|
|
public float limitVert = 145f;
|
|
private Vector3 mouseOrigin;
|
|
private bool isRotating;
|
|
Manager man;
|
|
Camera fovComp;
|
|
//** Try Zoom
|
|
public int zoom = 20;
|
|
int normal = 60;
|
|
float smooth = 3;
|
|
|
|
private void Start()
|
|
{
|
|
man = GameObject.Find("Manager").GetComponent<Manager>();
|
|
fovComp = Camera.main.GetComponent<Camera>();
|
|
}
|
|
|
|
protected float ClampAngle(float angle, float min, float max)
|
|
{
|
|
angle = NormalizeAngle(angle);
|
|
if (angle > 180)
|
|
{
|
|
angle -= 360;
|
|
}
|
|
else
|
|
if (angle < -180)
|
|
{
|
|
angle += 360;
|
|
}
|
|
|
|
min = NormalizeAngle(min);
|
|
if (min > 180)
|
|
{
|
|
min -= 360;
|
|
}
|
|
else
|
|
if (min < -180)
|
|
{
|
|
min += 360;
|
|
}
|
|
|
|
max = NormalizeAngle(max);
|
|
if (max > 180)
|
|
{
|
|
max -= 360;
|
|
}
|
|
else
|
|
if (max < -180)
|
|
{
|
|
max += 360;
|
|
}
|
|
|
|
return Mathf.Clamp(angle, min, max);
|
|
}
|
|
|
|
protected float NormalizeAngle(float angle)
|
|
{
|
|
return (angle+360) % 360;
|
|
}
|
|
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (man.mode == "view")
|
|
return;
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
|
|
mouseOrigin = Input.mousePosition;
|
|
isRotating = true;
|
|
}
|
|
|
|
if (!Input.GetMouseButton(1))
|
|
isRotating = false;
|
|
|
|
if (isRotating)
|
|
{
|
|
Camera.main.transform.localEulerAngles = new Vector3(ClampAngle(Camera.main.transform.localEulerAngles.x, -65, 65), ClampAngle(Camera.main.transform.localEulerAngles.y, -limitVert, limitVert), 0);
|
|
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);
|
|
transform.RotateAround(transform.position, transform.right, -pos.y * sensitivity);
|
|
transform.RotateAround(transform.position, Vector3.up, pos.x * sensitivity); //
|
|
}
|
|
//**** Try Zoom
|
|
//if (EventSystem.current.IsPointerOverGameObject() && EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.layer == LayerMask.NameToLayer("UI")) //.CompareTag("Ui")
|
|
if(man.isMouseOverUI)
|
|
return; //Если указатель над UI, тогда отключаем scroll
|
|
|
|
if (Input.GetAxis("Mouse ScrollWheel") > 0) //&& man.mode != "scedit"
|
|
{
|
|
//float curFOV = Camera.main.GetComponent<Camera>().fieldOfView;
|
|
float curFOV = fovComp.fieldOfView;
|
|
if (curFOV > zoom) curFOV -= smooth;
|
|
if (curFOV < zoom) curFOV = zoom;
|
|
//Camera.main.GetComponent<Camera>().fieldOfView = curFOV;
|
|
fovComp.fieldOfView = curFOV;
|
|
}
|
|
else if (Input.GetAxis("Mouse ScrollWheel") < 0) //&& man.mode != "scedit"
|
|
{
|
|
//float curFOV = Camera.main.GetComponent<Camera>().fieldOfView;
|
|
float curFOV = fovComp.fieldOfView;
|
|
if (curFOV < normal) curFOV += smooth;
|
|
if (curFOV > normal) curFOV = normal;
|
|
//Camera.main.GetComponent<Camera>().fieldOfView = curFOV;
|
|
fovComp.fieldOfView = curFOV;
|
|
}
|
|
|
|
}
|
|
} |