63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class SeekController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
|
|
{
|
|
public Transform cam;
|
|
public AudioAnalyzer audioAnalyzer;
|
|
public LineRenderer referenceLine;
|
|
public float startX, endX;
|
|
public float zoomingSpeed =0.001f;
|
|
|
|
|
|
Vector2 pointerDownPos;
|
|
Vector3 pointerDownCamPos;
|
|
|
|
float pointerDownZoomingYMult;
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Vector3 pointerDelta = eventData.position - pointerDownPos;
|
|
cam.position = pointerDownCamPos + (new Vector3(pointerDelta.x,0) * 0.035f);
|
|
if(cam.position.x < startX){
|
|
cam.position = new Vector3(startX, cam.position.y,-10);
|
|
}
|
|
if(cam.position.x > endX){
|
|
cam.position = new Vector3(endX, cam.position.y,-10);
|
|
}
|
|
if(eventData.position.x > Screen.width / 2f){
|
|
audioAnalyzer.SetZoomingYMult(pointerDownZoomingYMult + (pointerDelta.y * zoomingSpeed));
|
|
}
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
pointerDownPos = eventData.position;
|
|
pointerDownCamPos = cam.position;
|
|
pointerDownZoomingYMult = audioAnalyzer.zoomingYMult;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
pointerDownPos = Vector3.zero;
|
|
}
|
|
|
|
void Awake(){
|
|
startX = referenceLine.GetPosition(0).x;
|
|
endX = referenceLine.GetPosition(referenceLine.positionCount-1).x;
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
startX = referenceLine.GetPosition(0).x;
|
|
endX = referenceLine.GetPosition(referenceLine.positionCount-1).x;
|
|
}
|
|
}
|