Predective algo
This commit is contained in:
@@ -7,6 +7,7 @@ using UnityEngine.Networking;
|
||||
public class LoadFromPrep : MonoBehaviour
|
||||
{
|
||||
public AudioSource source;
|
||||
public PredictiveMover mover;
|
||||
|
||||
void Awake(){
|
||||
if(PrepConnector.saveLoadData == null){
|
||||
@@ -18,6 +19,7 @@ public class LoadFromPrep : MonoBehaviour
|
||||
void Start(){
|
||||
if(PrepConnector.saveLoadData != null){
|
||||
StartCoroutine(LoadAudioCoroutine(PrepConnector.saveLoadData.musicFile));
|
||||
mover.allHits = PrepConnector.saveLoadData.hits;
|
||||
PlayerPrefs.SetString("saveData", JsonUtility.ToJson(PrepConnector.saveLoadData));
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -15,7 +16,7 @@ public class PrepController : MonoBehaviour
|
||||
public Button pinBtn;
|
||||
public Button removePinBtn;
|
||||
public Toggle followSeekerToggle;
|
||||
|
||||
public TMP_Text playbackTimeTxt;
|
||||
public static List<GameObject> markers = new List<GameObject>();
|
||||
|
||||
public static void Reset(){
|
||||
@@ -28,12 +29,20 @@ public class PrepController : MonoBehaviour
|
||||
pinBtn.onClick.AddListener(AddMarker);
|
||||
removePinBtn.onClick.AddListener(RemoveMarker);
|
||||
instance = this;
|
||||
|
||||
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if(followSeekerToggle.isOn && source.isPlaying){
|
||||
cam.position = new Vector3(source.time * AudioAnalyzer.instance.zoomingYMult, cam.position.y, cam.position.z);
|
||||
source.time = startOffset + (Time.time - startTime);
|
||||
playbackTimeTxt.text = source.time.ToString("n3");
|
||||
|
||||
if(followSeekerToggle.isOn){
|
||||
if(source.isPlaying){
|
||||
cam.position = new Vector3(source.time * AudioAnalyzer.instance.zoomingYMult, cam.position.y, cam.position.z);
|
||||
source.time = startOffset + (Time.time - startTime);
|
||||
}else{
|
||||
source.time = cam.position.x / AudioAnalyzer.instance.zoomingYMult;
|
||||
}
|
||||
}
|
||||
bool anythingInProximity = false;
|
||||
for(int i=0; i < transform.childCount; i++){
|
||||
@@ -80,6 +89,7 @@ public class PrepController : MonoBehaviour
|
||||
// go.transform.position = new Vector3(cam.position.x, 0);
|
||||
go.GetComponent<Marker>().myTime = cam.position.x / AudioAnalyzer.instance.zoomingYMult;
|
||||
|
||||
|
||||
markers.Add(go);
|
||||
}
|
||||
|
||||
@@ -111,5 +121,23 @@ public class PrepController : MonoBehaviour
|
||||
markers.RemoveAt(indexToRemove);
|
||||
Destroy(closestOne);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnSeekerDragged(Vector3 newCamPos){
|
||||
if(source.isPlaying){
|
||||
TogglePlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool playAfterDragEnd = false;
|
||||
public void OnSeekerDown(){
|
||||
playAfterDragEnd=source.isPlaying;
|
||||
}
|
||||
|
||||
public void OnSeekerUp(){
|
||||
if(playAfterDragEnd){
|
||||
TogglePlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,13 @@ public class SaveLoadPrep : MonoBehaviour
|
||||
|
||||
public void Save(){
|
||||
saveLoadData = new SaveLoadData(txtPath.text);
|
||||
List<float> unsortedHits = new List<float>();
|
||||
foreach(GameObject marker in PrepController.markers){
|
||||
saveLoadData.hits.Add(marker.transform.position.x / AudioAnalyzer.instance.zoomingYMult);
|
||||
unsortedHits.Add(marker.transform.position.x / AudioAnalyzer.instance.zoomingYMult);
|
||||
}
|
||||
|
||||
saveLoadData.hits = Helpers.BubbleSort(unsortedHits);
|
||||
|
||||
saveContentPanel.SetActive(true);
|
||||
string fileName = txtPath.text;
|
||||
if(fileName.Contains("/")){
|
||||
|
||||
@@ -7,6 +7,7 @@ public class SeekController : MonoBehaviour, IPointerDownHandler, IPointerUpHand
|
||||
{
|
||||
public Transform cam;
|
||||
public AudioAnalyzer audioAnalyzer;
|
||||
public PrepController controller;
|
||||
public LineRenderer referenceLine;
|
||||
public float startX, endX;
|
||||
public float zoomingSpeed =0.001f;
|
||||
@@ -20,16 +21,18 @@ public class SeekController : MonoBehaviour, IPointerDownHandler, IPointerUpHand
|
||||
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);
|
||||
Vector3 newCamPos = pointerDownCamPos + (new Vector3(pointerDelta.x,0) * 0.035f);
|
||||
if(newCamPos.x < startX){
|
||||
newCamPos = new Vector3(startX, newCamPos.y,-10);
|
||||
}
|
||||
if(cam.position.x > endX){
|
||||
cam.position = new Vector3(endX, cam.position.y,-10);
|
||||
if(newCamPos.x > endX){
|
||||
newCamPos = new Vector3(endX, newCamPos.y,-10);
|
||||
}
|
||||
if(eventData.position.x > Screen.width / 2f){
|
||||
audioAnalyzer.SetZoomingYMult(pointerDownZoomingYMult + (pointerDelta.y * zoomingSpeed));
|
||||
audioAnalyzer.SetZoomingYMult(pointerDownZoomingYMult + (pointerDelta.y * zoomingSpeed));
|
||||
}
|
||||
controller.OnSeekerDragged(newCamPos);
|
||||
cam.position = newCamPos;
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
@@ -37,11 +40,14 @@ public class SeekController : MonoBehaviour, IPointerDownHandler, IPointerUpHand
|
||||
pointerDownPos = eventData.position;
|
||||
pointerDownCamPos = cam.position;
|
||||
pointerDownZoomingYMult = audioAnalyzer.zoomingYMult;
|
||||
|
||||
controller.OnSeekerDown();
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
pointerDownPos = Vector3.zero;
|
||||
controller.OnSeekerUp();
|
||||
}
|
||||
|
||||
void Awake(){
|
||||
|
||||
43
Assets/Scripts/Prep/TimescaleAdjuster.cs
Normal file
43
Assets/Scripts/Prep/TimescaleAdjuster.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TimescaleAdjuster : MonoBehaviour
|
||||
{
|
||||
public Button nextBtn;
|
||||
public Button prevBtn;
|
||||
public TMP_Text txt;
|
||||
|
||||
void Start()
|
||||
{
|
||||
nextBtn.onClick.AddListener(IncrementTime);
|
||||
prevBtn.onClick.AddListener(DecrementTime);
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
void IncrementTime(){
|
||||
if(Time.timeScale < 0.25f){
|
||||
Time.timeScale = 0.25f;
|
||||
}else{
|
||||
Time.timeScale += 0.25f;
|
||||
}
|
||||
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
void DecrementTime(){
|
||||
if(Time.timeScale > 0.25f){
|
||||
Time.timeScale -= 0.25f;
|
||||
}else{
|
||||
Time.timeScale = 0.1f;
|
||||
}
|
||||
UpdateText();
|
||||
|
||||
}
|
||||
|
||||
void UpdateText(){
|
||||
txt.text = Time.timeScale.ToString("n2");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/TimescaleAdjuster.cs.meta
Normal file
11
Assets/Scripts/Prep/TimescaleAdjuster.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78209ab90a9209446921f39c899d1147
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user