56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Unity.Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class CameraController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
|
|
{
|
|
[SerializeField]private CinemachineCamera _cinemachineCamera;
|
|
[SerializeField]private CinemachineOrbitalFollow orbital;
|
|
private Vector2 currentPos;
|
|
private bool fingerDown = false;
|
|
Vector2 delta = Vector2.zero;
|
|
public float minSwipeDistance = 10f;
|
|
public float speedX = 1f;
|
|
public float speedY = 1f;
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
delta = eventData.position - currentPos;
|
|
|
|
if (delta.magnitude >= minSwipeDistance)
|
|
{
|
|
orbital.HorizontalAxis.Value += delta.normalized.x * speedX * Time.deltaTime;
|
|
//orbital.HorizontalAxis.Value = Mathf.Clamp(orbital.HorizontalAxis.Value, -360f, 360f);
|
|
orbital.VerticalAxis.Value += delta.normalized.y * speedY * Time.deltaTime;
|
|
orbital.VerticalAxis.Value = Mathf.Clamp(orbital.VerticalAxis.Value, -360f, 360f);
|
|
}
|
|
currentPos = eventData.position;
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
currentPos = eventData.position;
|
|
fingerDown = true;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
fingerDown = false;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
//todo: should not always update
|
|
if (_cinemachineCamera.Follow == null && CECGameRun.Instance.GetHostPlayer() != null)
|
|
{
|
|
_cinemachineCamera.Follow = CECGameRun.Instance.GetHostPlayer().transform;
|
|
_cinemachineCamera.ForceCameraPosition(CECGameRun.Instance.GetHostPlayer().transform.position, Quaternion.identity);
|
|
orbital.HorizontalAxis.Value = 208;
|
|
orbital.VerticalAxis.Value = -268;
|
|
}
|
|
}
|
|
}
|
|
}
|