mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Improved adding and removal of anim events
This commit is contained in:
parent
f0d46df3d6
commit
8523abf957
276 changed files with 1401 additions and 5422 deletions
96
Assets/Scripts/Managers/CameraController.cs
Normal file
96
Assets/Scripts/Managers/CameraController.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
private Camera cam;
|
||||
|
||||
[Header("Scroll controls")]
|
||||
public float scrollSpeed = 100f;
|
||||
|
||||
[Header("Zoom controls")]
|
||||
public float zoom = -5f;
|
||||
public float minZoom = -3f;
|
||||
public float maxZoom = -15f;
|
||||
|
||||
[Header("Max bounds")]
|
||||
public float maxBoundsXAxis = 30;
|
||||
public float maxBoundsYAxis = 30;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
private float curZoom;
|
||||
private bool mouseDragActive = false;
|
||||
private Vector3 mouseDragOrigin;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
x = transform.position.x;
|
||||
y = transform.position.y;
|
||||
|
||||
curZoom = zoom;
|
||||
|
||||
transform.position = new Vector3(transform.position.x, transform.position.y, -10);
|
||||
cam = this.GetComponent<Camera>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButton(2))
|
||||
{ StartMouseDrag(); }
|
||||
|
||||
else if (Input.GetMouseButtonUp(2))
|
||||
{ ResetMouseDrag(); }
|
||||
|
||||
curZoom += Input.GetAxis("Mouse ScrollWheel") * scrollSpeed * 0.1f;
|
||||
curZoom = Mathf.Clamp(curZoom, maxZoom, minZoom);
|
||||
|
||||
Vector3 cameraPosition = Vector3.Lerp(transform.position, new Vector3(x, y, -10), 0.2f);
|
||||
transform.position = cameraPosition;
|
||||
cam.orthographicSize = Mathf.Abs(curZoom);
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
x = position.x;
|
||||
y = position.y;
|
||||
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
public void SetZoom(float zoom)
|
||||
{
|
||||
this.zoom = Mathf.Clamp(zoom, maxZoom, minZoom);
|
||||
}
|
||||
|
||||
public void StartMouseDrag()
|
||||
{
|
||||
Vector3 delta = cam.ScreenToWorldPoint(Input.mousePosition) - cam.transform.position;
|
||||
|
||||
if (mouseDragActive == false)
|
||||
{
|
||||
mouseDragActive = true;
|
||||
mouseDragOrigin = cam.ScreenToWorldPoint(Input.mousePosition);
|
||||
}
|
||||
|
||||
cam.transform.position = mouseDragOrigin - delta;
|
||||
}
|
||||
|
||||
public void ResetMouseDrag()
|
||||
{
|
||||
mouseDragActive = false;
|
||||
}
|
||||
|
||||
public void ResetCamera()
|
||||
{
|
||||
cam.transform.position = new Vector3(0, 0, -10);
|
||||
curZoom = zoom;
|
||||
|
||||
mouseDragActive = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue