using System;
using UnityEngine;

// Token: 0x020000EA RID: 234
[AddComponentMenu("Camera-Control/Mouse Orbit with zoom")]
public class MouseOrbitImproved : MonoBehaviour
{
	// Token: 0x0600151C RID: 5404 RVA: 0x001977D8 File Offset: 0x001959D8
	private void Start()
	{
		Vector3 eulerAngles = base.transform.eulerAngles;
		this.x = eulerAngles.y;
		this.y = eulerAngles.x;
		this.rigidbodyM = base.GetComponent<Rigidbody>();
		if (this.rigidbodyM != null)
		{
			this.rigidbodyM.freezeRotation = true;
		}
	}

	// Token: 0x0600151D RID: 5405 RVA: 0x00197830 File Offset: 0x00195A30
	private void LateUpdate()
	{
		if (this.target && Input.GetMouseButton(0))
		{
			this.x += Input.GetAxis("Mouse X") * this.xSpeed * this.distance * 0.02f;
			this.y -= Input.GetAxis("Mouse Y") * this.ySpeed * 0.02f;
		}
		this.y = MouseOrbitImproved.ClampAngle(this.y, this.yMinLimit, this.yMaxLimit);
		Quaternion quaternion = Quaternion.Euler(this.y, this.x, 0f);
		this.distance = Mathf.Clamp(this.distance - Input.GetAxis("Mouse ScrollWheel") * 5f, this.distanceMin, this.distanceMax);
		RaycastHit raycastHit;
		if (Physics.Linecast(this.target.position, base.transform.position, out raycastHit))
		{
			this.distance -= raycastHit.distance;
		}
		Vector3 vector = new Vector3(0f, 0f, -this.distance);
		Vector3 vector2 = quaternion * vector + this.target.position;
		base.transform.rotation = quaternion;
		base.transform.position = vector2;
	}

	// Token: 0x0600151E RID: 5406 RVA: 0x0019797E File Offset: 0x00195B7E
	public static float ClampAngle(float angle, float min, float max)
	{
		if (angle < -360f)
		{
			angle += 360f;
		}
		if (angle > 360f)
		{
			angle -= 360f;
		}
		return Mathf.Clamp(angle, min, max);
	}

	// Token: 0x040024FB RID: 9467
	public Transform target;

	// Token: 0x040024FC RID: 9468
	public float distance = 5f;

	// Token: 0x040024FD RID: 9469
	public float xSpeed = 120f;

	// Token: 0x040024FE RID: 9470
	public float ySpeed = 120f;

	// Token: 0x040024FF RID: 9471
	public float yMinLimit = -20f;

	// Token: 0x04002500 RID: 9472
	public float yMaxLimit = 80f;

	// Token: 0x04002501 RID: 9473
	public float distanceMin = 0.5f;

	// Token: 0x04002502 RID: 9474
	public float distanceMax = 15f;

	// Token: 0x04002503 RID: 9475
	private Rigidbody rigidbodyM;

	// Token: 0x04002504 RID: 9476
	private float x;

	// Token: 0x04002505 RID: 9477
	private float y;
}
