prototyping
This commit is contained in:
@@ -3,8 +3,10 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEditor.SearchService;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.U2D;
|
||||
|
||||
public class Mover : MonoBehaviour
|
||||
@@ -45,10 +47,19 @@ public class Mover : MonoBehaviour
|
||||
public bool playReplay = false;
|
||||
|
||||
float defFOV;
|
||||
|
||||
public AudioSource source;
|
||||
|
||||
List<float> recordedTimes = null;
|
||||
List<float> pastTimes = null;
|
||||
private void Awake()
|
||||
{
|
||||
defFOV = Camera.main.orthographicSize;
|
||||
if (!playReplay) { themeMan.Randomize(); }
|
||||
|
||||
if(PrepConnector.saveLoadData != null){
|
||||
recordedTimes = PrepConnector.saveLoadData.hits;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -246,15 +257,34 @@ public class Mover : MonoBehaviour
|
||||
}
|
||||
|
||||
float tensionBuildup = 0f;
|
||||
float endTimer = 0;
|
||||
void PreWork()
|
||||
{
|
||||
float loudness_delta = splitter.loudness - prev_loud;
|
||||
bool notTooShort = (Time.time - LastTime) > yieldTime;
|
||||
bool oldLoudLogic = splitter.loudness > loudnessThreshold && prev_loud < loudnessThreshold;
|
||||
bool newLoudLogic = (loudness_delta > loudnessThreshold && notTooShort);
|
||||
|
||||
bool prepLogic = false;
|
||||
if(pastTimes.Count <= 0){
|
||||
if(endTimer < 10f){
|
||||
endTimer+=Time.deltaTime;
|
||||
}else{
|
||||
SceneManager.LoadScene("prep");
|
||||
endTimer=0;
|
||||
}
|
||||
}else{
|
||||
if(pastTimes[0] < source.time){
|
||||
prepLogic = true;
|
||||
pastTimes.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool newDynamicLogic = recordedTimes == null ? oldLoudLogic : prepLogic ;
|
||||
tensionBuildup += Time.deltaTime;
|
||||
|
||||
if (oldLoudLogic || Input.GetKeyDown(KeyCode.Space))
|
||||
if (newDynamicLogic || Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
Debug.Log(LastTime - Time.time);
|
||||
//Instantiate(prefab, transform.position, Quaternion.identity);
|
||||
|
||||
8
Assets/Scripts/Prep.meta
Normal file
8
Assets/Scripts/Prep.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e67bd1caee37724a9dfb28276d53de2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
139
Assets/Scripts/Prep/AudioAnalyzer.cs
Normal file
139
Assets/Scripts/Prep/AudioAnalyzer.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AudioAnalyzer : MonoBehaviour
|
||||
{
|
||||
|
||||
public AudioSource source;
|
||||
public AudioClip audioClip; // Assign your audio clip in the Inspector
|
||||
public LineRenderer lineRenderer;
|
||||
public LineRenderer lineRenderer2;
|
||||
public LineRenderer seeker;
|
||||
public float interval = 0.1f; // Interval in seconds to calculate RMS
|
||||
[SerializeField]public List<AudioSnapshot> snapshots = new List<AudioSnapshot>();
|
||||
|
||||
public bool getData = false;
|
||||
public bool updateJustChart = false;
|
||||
public Vector2 chartMultiplier1;
|
||||
public Vector2 chartMultiplier;
|
||||
public float zoomingYMult = 1f;
|
||||
|
||||
public float cutoffLevel = 0.05f;
|
||||
public float accelCutoffLevel = 0.05f;
|
||||
|
||||
|
||||
public static AudioAnalyzer instance;
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void SetZoomingYMult(float val){
|
||||
zoomingYMult = val;
|
||||
UpdateLine();
|
||||
}
|
||||
private void OnValidate()
|
||||
{
|
||||
if(getData)
|
||||
{
|
||||
getData = false;
|
||||
updateData();
|
||||
}
|
||||
|
||||
if(updateJustChart)
|
||||
{
|
||||
UpdateLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateData()
|
||||
{
|
||||
int sampleCount = audioClip.samples * audioClip.channels;
|
||||
float[] samples = new float[sampleCount];
|
||||
|
||||
// Extract the audio data
|
||||
bool result = audioClip.GetData(samples, 0);
|
||||
|
||||
if (result)
|
||||
{
|
||||
snapshots.Clear();
|
||||
// Number of samples per interval
|
||||
int samplesPerInterval = Mathf.FloorToInt(interval * audioClip.frequency * audioClip.channels);
|
||||
|
||||
for (int i = 0; i < sampleCount; i += samplesPerInterval)
|
||||
{
|
||||
// Calculate RMS value for the current interval
|
||||
float rms = 0f;
|
||||
int intervalSampleCount = Mathf.Min(samplesPerInterval, sampleCount - i);
|
||||
|
||||
for (int j = 0; j < intervalSampleCount; j++)
|
||||
{
|
||||
float sample = samples[i + j];
|
||||
rms += sample * sample;
|
||||
}
|
||||
|
||||
rms = Mathf.Sqrt(rms / intervalSampleCount);
|
||||
|
||||
// Calculate the time for the current interval
|
||||
float time = (float)i / (audioClip.frequency * audioClip.channels);
|
||||
|
||||
// Store the time and volume level in the dictionary
|
||||
//volumeLevels[time] = rms;
|
||||
|
||||
AudioSnapshot snapshot = new AudioSnapshot() { time = time, loudness=rms };
|
||||
snapshots.Add(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateLine();
|
||||
}
|
||||
|
||||
public void UpdateLine()
|
||||
{
|
||||
lineRenderer.positionCount = snapshots.Count;
|
||||
lineRenderer2.positionCount = snapshots.Count;
|
||||
Vector3[] positions = new Vector3[lineRenderer.positionCount];
|
||||
Vector3[] accelPositions = new Vector3[lineRenderer.positionCount];
|
||||
for(int i =0; i < snapshots.Count; i++)
|
||||
{
|
||||
//positions[i] = new Vector3(snapshots[i].time * chartMultiplier.x, snapshots[i].loudness > cutoffLevel ? snapshots[i].loudness * chartMultiplier.y : 0);
|
||||
positions[i] = new Vector3(snapshots[i].time * chartMultiplier1.x, snapshots[i].loudness * chartMultiplier1.y * zoomingYMult);
|
||||
float accel = i < 1 ? 0 : (snapshots[i].loudness - snapshots[i - 1].loudness);
|
||||
accelPositions[i] = new Vector3(snapshots[i].time * chartMultiplier.x, (accel > accelCutoffLevel ? accelCutoffLevel : 0)* chartMultiplier.y * zoomingYMult);
|
||||
}
|
||||
|
||||
lineRenderer.SetPositions(positions);
|
||||
lineRenderer2.SetPositions(accelPositions);
|
||||
|
||||
seeker.positionCount = 2;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
source.clip = audioClip;
|
||||
// source.Play();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector3[] seekerPositions = new Vector3[] {Vector3.zero, Vector3.zero};
|
||||
private void FixedUpdate()
|
||||
{
|
||||
chartMultiplier.x = zoomingYMult;
|
||||
chartMultiplier1.x = zoomingYMult;
|
||||
|
||||
seekerPositions[1] = new Vector3(source.time * AudioAnalyzer.instance.zoomingYMult, 0);
|
||||
seeker.SetPositions(seekerPositions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class AudioSnapshot
|
||||
{
|
||||
public float time;
|
||||
public float loudness;
|
||||
}
|
||||
11
Assets/Scripts/Prep/AudioAnalyzer.cs.meta
Normal file
11
Assets/Scripts/Prep/AudioAnalyzer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af69518736532f240a836a1ca9c59235
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Scripts/Prep/LoadFromPrep.cs
Normal file
46
Assets/Scripts/Prep/LoadFromPrep.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class LoadFromPrep : MonoBehaviour
|
||||
{
|
||||
public AudioSource source;
|
||||
|
||||
void Awake(){
|
||||
if(PrepConnector.saveLoadData == null){
|
||||
if(PlayerPrefs.HasKey("saveData")){
|
||||
PrepConnector.saveLoadData = JsonUtility.FromJson<SaveLoadData>(PlayerPrefs.GetString("saveData"));
|
||||
}
|
||||
}
|
||||
}
|
||||
void Start(){
|
||||
if(PrepConnector.saveLoadData != null){
|
||||
StartCoroutine(LoadAudioCoroutine(PrepConnector.saveLoadData.musicFile));
|
||||
PlayerPrefs.SetString("saveData", JsonUtility.ToJson(PrepConnector.saveLoadData));
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LoadAudioCoroutine(string fileName)
|
||||
{
|
||||
string filePath = Path.Combine(Application.persistentDataPath, fileName);
|
||||
string url = "file://" + filePath;
|
||||
|
||||
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV); // Use AudioType.MPEG for MP3 files
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.LogError(www.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
|
||||
source.clip = clip;
|
||||
source.Play();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Prep/LoadFromPrep.cs.meta
Normal file
11
Assets/Scripts/Prep/LoadFromPrep.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3c584756bc73bb4983f44318f7f5c09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Scripts/Prep/Marker.cs
Normal file
12
Assets/Scripts/Prep/Marker.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Marker : MonoBehaviour
|
||||
{
|
||||
public float myTime = 0f;
|
||||
|
||||
void Update(){
|
||||
transform.position = new Vector3(myTime * AudioAnalyzer.instance.zoomingYMult, 0);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/Marker.cs.meta
Normal file
11
Assets/Scripts/Prep/Marker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cf3d71d424a53d4798c98a190935a13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Assets/Scripts/Prep/MusicLoader.cs
Normal file
94
Assets/Scripts/Prep/MusicLoader.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MusicLoader : MonoBehaviour
|
||||
{
|
||||
public AudioSource audioSource;
|
||||
public Text txtPath;
|
||||
public RectTransform musicFileSelectionParent;
|
||||
public GameObject musicFileSelectionPrefab;
|
||||
public GameObject musicFilePanel;
|
||||
|
||||
|
||||
public static MusicLoader instance;
|
||||
|
||||
void Awake(){
|
||||
instance= this;
|
||||
}
|
||||
|
||||
public void ShowMusicFileSelection(){
|
||||
musicFilePanel.SetActive(true);
|
||||
PopulateMusicFileSelection();
|
||||
}
|
||||
|
||||
public void OnFileSelected(string file, bool containsRoot = false){
|
||||
musicFilePanel.SetActive(false);
|
||||
LoadFile(containsRoot ? file : (Application.persistentDataPath + file));
|
||||
}
|
||||
|
||||
|
||||
public void LoadFile(string file){
|
||||
txtPath.text = file;
|
||||
if(file.Contains("\\")){
|
||||
txtPath.text = file.Replace("\\","/");
|
||||
}
|
||||
StartCoroutine(LoadAudioCoroutine(file));
|
||||
}
|
||||
|
||||
private IEnumerator LoadAudioCoroutine(string fileName)
|
||||
{
|
||||
string filePath = Path.Combine(Application.persistentDataPath, fileName);
|
||||
string url = "file://" + filePath;
|
||||
|
||||
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV); // Use AudioType.MPEG for MP3 files
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.LogError(www.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
|
||||
audioSource.clip = clip;
|
||||
AudioAnalyzer.instance.audioClip = clip;
|
||||
AudioAnalyzer.instance.updateData();
|
||||
// audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
txtPath.text = Application.persistentDataPath;
|
||||
PopulateMusicFileSelection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void PopulateMusicFileSelection(){
|
||||
for(int i=0; i < musicFileSelectionParent.childCount; i++){
|
||||
|
||||
Destroy(musicFileSelectionParent.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
string[] files =Directory.GetFiles(Application.persistentDataPath);
|
||||
foreach(string file in files){
|
||||
if(!file.Contains(".wav")){continue;}
|
||||
|
||||
GameObject newItem = Instantiate(musicFileSelectionPrefab, musicFileSelectionParent);
|
||||
newItem.AddComponent<OnMusicFileSelected>();
|
||||
newItem.GetComponentInChildren<Text>().text = file.Replace(Application.persistentDataPath, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void CopyDataPath(){
|
||||
GUIUtility.systemCopyBuffer = Application.persistentDataPath;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/MusicLoader.cs.meta
Normal file
11
Assets/Scripts/Prep/MusicLoader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bbabe7faa5e5f8468a05bfa45f529fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Prep/PrepConnector.cs
Normal file
17
Assets/Scripts/Prep/PrepConnector.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PrepConnector : MonoBehaviour
|
||||
{
|
||||
|
||||
public static SaveLoadData saveLoadData;
|
||||
|
||||
public void LoadPlay(){
|
||||
SaveLoadPrep.instance.Save();
|
||||
saveLoadData = SaveLoadPrep.instance.saveLoadData;
|
||||
SceneManager.LoadScene("Runner");
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Prep/PrepConnector.cs.meta
Normal file
11
Assets/Scripts/Prep/PrepConnector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c21ebc29cc66b041a4f89e1400e1928
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
115
Assets/Scripts/Prep/PrepController.cs
Normal file
115
Assets/Scripts/Prep/PrepController.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PrepController : MonoBehaviour
|
||||
{
|
||||
public Transform cam;
|
||||
public AudioSource source;
|
||||
public GameObject markerPrefab;
|
||||
public GameObject flashIndicator;
|
||||
public Sprite playIcon;
|
||||
public Sprite pauseIcon;
|
||||
public Button playBtn;
|
||||
public Button pinBtn;
|
||||
public Button removePinBtn;
|
||||
public Toggle followSeekerToggle;
|
||||
|
||||
public static List<GameObject> markers = new List<GameObject>();
|
||||
|
||||
public static void Reset(){
|
||||
markers = new List<GameObject>();
|
||||
}
|
||||
|
||||
public static PrepController instance;
|
||||
void Awake(){
|
||||
playBtn.onClick.AddListener(TogglePlay);
|
||||
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);
|
||||
}
|
||||
bool anythingInProximity = false;
|
||||
for(int i=0; i < transform.childCount; i++){
|
||||
if(Mathf.Abs(transform.GetChild(i).position.x - source.time) < 0.1f){
|
||||
anythingInProximity = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flashIndicator.SetActive(anythingInProximity);
|
||||
}
|
||||
|
||||
float startTime;
|
||||
float startOffset;
|
||||
public void TogglePlay(){
|
||||
if(source.isPlaying){
|
||||
source.Pause();
|
||||
playBtn.GetComponent<Image>().sprite = playIcon;
|
||||
}else{
|
||||
source.time = cam.position.x / AudioAnalyzer.instance.zoomingYMult;
|
||||
source.Play();
|
||||
playBtn.GetComponent<Image>().sprite = pauseIcon;
|
||||
startTime = Time.time;
|
||||
startOffset = source.time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetMarkers(List<float> times){
|
||||
foreach(GameObject go in markers){
|
||||
Destroy(go);
|
||||
}
|
||||
|
||||
markers = new List<GameObject>();
|
||||
|
||||
foreach(float time in times){
|
||||
AddMarker(time);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMarker(){
|
||||
GameObject go = Instantiate(markerPrefab, transform);
|
||||
// go.transform.position = new Vector3(cam.position.x, 0);
|
||||
go.GetComponent<Marker>().myTime = cam.position.x / AudioAnalyzer.instance.zoomingYMult;
|
||||
|
||||
markers.Add(go);
|
||||
}
|
||||
|
||||
public void AddMarker(float time){
|
||||
GameObject go = Instantiate(markerPrefab, transform);
|
||||
// go.transform.position = new Vector3(time, 0);
|
||||
go.GetComponent<Marker>().myTime = time;
|
||||
markers.Add(go);
|
||||
}
|
||||
|
||||
public void RemoveMarker(){
|
||||
if(markers.Count <= 0){ return; }
|
||||
|
||||
GameObject closestOne = markers[0];
|
||||
foreach(GameObject marker in markers){
|
||||
float diff = Mathf.Abs(marker.transform.position.x - cam.position.x);
|
||||
float closestDiff = Mathf.Abs(closestOne.transform.position.x - cam.position.x);
|
||||
if(diff < closestDiff){
|
||||
closestOne = marker;
|
||||
}
|
||||
}
|
||||
|
||||
int indexToRemove = 0;
|
||||
for(int i =0; i < markers.Count; i++){
|
||||
if(markers[i] == closestOne){
|
||||
indexToRemove = i;
|
||||
}
|
||||
}
|
||||
markers.RemoveAt(indexToRemove);
|
||||
Destroy(closestOne);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Prep/PrepController.cs.meta
Normal file
11
Assets/Scripts/Prep/PrepController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5a9eaee79557ce4c80438fedf5fad89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Assets/Scripts/Prep/SaveLoadPrep.cs
Normal file
105
Assets/Scripts/Prep/SaveLoadPrep.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SaveLoadPrep : MonoBehaviour
|
||||
{
|
||||
public SaveLoadData saveLoadData;
|
||||
public Text txtPath;
|
||||
|
||||
public Button saveBtn;
|
||||
public Button loadBtn;
|
||||
|
||||
public GameObject saveContentPanel;
|
||||
public Button confirmSave;
|
||||
|
||||
public GameObject loadContentPanel;
|
||||
public Transform loadContentParent;
|
||||
public GameObject loadContentItemPrefab;
|
||||
|
||||
|
||||
public static SaveLoadPrep instance;
|
||||
void Awake(){
|
||||
saveBtn.onClick.AddListener(Save);
|
||||
loadBtn.onClick.AddListener(ShowLoadContent);
|
||||
instance =this;
|
||||
}
|
||||
|
||||
|
||||
public void ShowLoadContent(){
|
||||
loadContentPanel.SetActive(true);
|
||||
|
||||
PopulateContentPanel();
|
||||
}
|
||||
|
||||
public void OnFileSelected(string file){
|
||||
loadContentPanel.SetActive(false);
|
||||
LoadFile(Application.persistentDataPath + file);
|
||||
}
|
||||
|
||||
public void LoadFile(string file){
|
||||
string fileTxt = File.ReadAllText(file);
|
||||
saveLoadData = JsonUtility.FromJson<SaveLoadData>(fileTxt);
|
||||
|
||||
MusicLoader.instance.OnFileSelected(saveLoadData.musicFile, true);
|
||||
PrepController.instance.SetMarkers(saveLoadData.hits);
|
||||
}
|
||||
|
||||
|
||||
public void Save(){
|
||||
saveLoadData = new SaveLoadData(txtPath.text);
|
||||
foreach(GameObject marker in PrepController.markers){
|
||||
saveLoadData.hits.Add(marker.transform.position.x / AudioAnalyzer.instance.zoomingYMult);
|
||||
}
|
||||
|
||||
saveContentPanel.SetActive(true);
|
||||
string fileName = txtPath.text;
|
||||
if(fileName.Contains("/")){
|
||||
string[] bits = fileName.Split("/");
|
||||
fileName = bits[bits.Length-1];
|
||||
}else {
|
||||
string[] bits = fileName.Split("\\");
|
||||
fileName = bits[bits.Length-1];
|
||||
}
|
||||
fileName = fileName.Split('.')[0];
|
||||
saveContentPanel.GetComponentInChildren<InputField>().text = fileName;
|
||||
}
|
||||
|
||||
public void SaveConfirmed(){
|
||||
saveContentPanel.SetActive(false);
|
||||
string fileName = Application.persistentDataPath + "/" + saveContentPanel.GetComponentInChildren<InputField>().text + ".json";
|
||||
Debug.Log("Saving to " + fileName);
|
||||
File.WriteAllText(fileName , JsonUtility.ToJson(saveLoadData));
|
||||
}
|
||||
|
||||
public void PopulateContentPanel(){
|
||||
for(int i=0; i < loadContentParent.childCount; i++){
|
||||
|
||||
Destroy(loadContentParent.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
string[] files =Directory.GetFiles(Application.persistentDataPath);
|
||||
foreach(string file in files){
|
||||
if(!file.Contains(".json")){continue;}
|
||||
|
||||
GameObject newItem = Instantiate(loadContentItemPrefab, loadContentParent);
|
||||
newItem.AddComponent<OnContentFileSelected>();
|
||||
newItem.GetComponentInChildren<Text>().text = file.Replace(Application.persistentDataPath, "");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class SaveLoadData{
|
||||
public string musicFile;
|
||||
public List<float> hits;
|
||||
|
||||
public SaveLoadData(string file){
|
||||
musicFile = file;
|
||||
hits = new List<float>();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/SaveLoadPrep.cs.meta
Normal file
11
Assets/Scripts/Prep/SaveLoadPrep.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b81216c244c8004e960799930870477
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Assets/Scripts/Prep/SeekController.cs
Normal file
62
Assets/Scripts/Prep/SeekController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/SeekController.cs.meta
Normal file
11
Assets/Scripts/Prep/SeekController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b86087c8a2fd6a9418eed9f89da2c1d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Prep/UI.meta
Normal file
8
Assets/Scripts/Prep/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff78fa484d97b17409f765b93c5d7b00
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Prep/UI/OnContentFileSelected.cs
Normal file
15
Assets/Scripts/Prep/UI/OnContentFileSelected.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OnContentFileSelected : MonoBehaviour
|
||||
{
|
||||
void Awake(){
|
||||
GetComponent<Button>().onClick.AddListener(OnClicked);
|
||||
}
|
||||
|
||||
void OnClicked(){
|
||||
SaveLoadPrep.instance.OnFileSelected(GetComponentInChildren<Text>().text);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/UI/OnContentFileSelected.cs.meta
Normal file
11
Assets/Scripts/Prep/UI/OnContentFileSelected.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e47f1b6d89d09824d90a856753c14c41
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Prep/UI/OnMusicFileSelected.cs
Normal file
15
Assets/Scripts/Prep/UI/OnMusicFileSelected.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OnMusicFileSelected : MonoBehaviour
|
||||
{
|
||||
void Awake(){
|
||||
GetComponent<Button>().onClick.AddListener(OnClicked);
|
||||
}
|
||||
|
||||
void OnClicked(){
|
||||
MusicLoader.instance.OnFileSelected(GetComponentInChildren<Text>().text);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Prep/UI/OnMusicFileSelected.cs.meta
Normal file
11
Assets/Scripts/Prep/UI/OnMusicFileSelected.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8a4c24858db7e64ea7b3296074a1050
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
110
Assets/Scripts/PrepMover.cs
Normal file
110
Assets/Scripts/PrepMover.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PrepMover : MonoBehaviour
|
||||
{
|
||||
public AudioSource source;
|
||||
public List<float> allHits = new List<float>();
|
||||
public List<float> hitsQueue = new List<float>();
|
||||
public List<Vector3> targetPoints = new List<Vector3>();
|
||||
public Vector2 speeds = new Vector2();
|
||||
|
||||
public DrawShape botShape;
|
||||
public DrawShape topShape;
|
||||
void Start(){
|
||||
if(PrepConnector.saveLoadData != null){
|
||||
allHits = new List<float>
|
||||
{
|
||||
0
|
||||
};
|
||||
allHits.AddRange(PrepConnector.saveLoadData.hits);
|
||||
hitsQueue = new List<float>();
|
||||
hitsQueue.AddRange(allHits);
|
||||
}else{
|
||||
SceneManager.LoadScene("prep");
|
||||
}
|
||||
|
||||
ReadFuture();
|
||||
}
|
||||
|
||||
|
||||
void ReadFuture(){
|
||||
targetPoints = new List<Vector3>();
|
||||
List<Vector3> botPoints = new List<Vector3>();
|
||||
List<Vector3> topPoints = new List<Vector3>();
|
||||
|
||||
for(int i=0; i < allHits.Count; i++){
|
||||
float curT = allHits[i];
|
||||
float curY = GetYPoint(i);
|
||||
Vector3 thisPoint = new Vector3(curT * speeds.x, curY * speeds.y);
|
||||
targetPoints.Add(thisPoint);
|
||||
|
||||
bool flipside= i %2 == 0;
|
||||
|
||||
if(flipside){
|
||||
if (i > 2)
|
||||
{
|
||||
Vector3 prevPoint = targetPoints[i - 2];
|
||||
float xMid = prevPoint.x + ((thisPoint.x - prevPoint.x) / (2f * 2));
|
||||
float yMid = prevPoint.y + ((thisPoint.y - prevPoint.y) / 2f);
|
||||
xMid = targetPoints[i - 1].x; ;
|
||||
Vector3 newP1 = new Vector3(xMid, prevPoint.y);
|
||||
Vector3 newP2 = new Vector3(xMid, thisPoint.y);
|
||||
botPoints.Add(newP1);
|
||||
botPoints.Add(newP2);
|
||||
}
|
||||
botPoints.Add(thisPoint);
|
||||
}else{
|
||||
|
||||
topPoints.Add(thisPoint);
|
||||
}
|
||||
}
|
||||
|
||||
botShape.Draw(botPoints, new Vector3(0,-30));
|
||||
topShape.Draw(topPoints, new Vector3(0,30));
|
||||
}
|
||||
|
||||
public int curIndex =0;
|
||||
public float curProg = 0;
|
||||
void Update()
|
||||
{
|
||||
for(int i=0; i < allHits.Count; i++){
|
||||
if(allHits[i] < source.time){
|
||||
curIndex = i;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float curTime = allHits[curIndex];
|
||||
float nextTime = allHits[curIndex+1];
|
||||
|
||||
curProg = (source.time - curTime) / (nextTime-curTime);
|
||||
|
||||
transform.position = Vector3.Lerp(targetPoints[curIndex], targetPoints[curIndex+1], curProg);
|
||||
}
|
||||
|
||||
float GetYPoint(int index){
|
||||
float y = 0;
|
||||
for(int i=0; i < index; i++){
|
||||
float prevValue = i >0 ? allHits[i-1] : 0;
|
||||
float curValue = allHits[i];
|
||||
|
||||
float diff = curValue - prevValue;
|
||||
y += diff * (i %2 == 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Dry run;
|
||||
|
||||
times = (0, 1, 2, 2.5, 5, 10)
|
||||
y = (0, 1, -1, 1.5, -3.5, 6.5)
|
||||
addition(0, 1, )
|
||||
*/
|
||||
11
Assets/Scripts/PrepMover.cs.meta
Normal file
11
Assets/Scripts/PrepMover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc557983f35279c40bb1c2f6d1baf170
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/ProtoTyping.meta
Normal file
8
Assets/Scripts/ProtoTyping.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d218c6308645ed4aa350978bd50281c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Scripts/ProtoTyping/AlgorithmTest.cs
Normal file
44
Assets/Scripts/ProtoTyping/AlgorithmTest.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AlgorithmTest : MonoBehaviour
|
||||
{
|
||||
public List<float> allHits = new List<float>();
|
||||
public LineRenderer line;
|
||||
public Vector2 offsetMultipliers = Vector2.one;
|
||||
|
||||
void OnDrawGizmos(){
|
||||
RegenerateLines();
|
||||
}
|
||||
|
||||
void RegenerateLines(){
|
||||
Vector3[] points = new Vector3[allHits.Count];
|
||||
|
||||
for(int i=0; i < points.Length; i++){
|
||||
points[i] = GetPosition(i);
|
||||
}
|
||||
|
||||
line.positionCount = points.Length;
|
||||
line.SetPositions(points);
|
||||
}
|
||||
|
||||
Vector3 GetPosition(int index) {
|
||||
float hitX = allHits[index];
|
||||
|
||||
float diff = 0;
|
||||
float prevY = 0;
|
||||
|
||||
// Calculate diff and prevY if the index is greater than 0
|
||||
if (index > 0) {
|
||||
diff = allHits[index] - allHits[index - 1];
|
||||
prevY = GetPosition(index - 1).y; // Recursively get the previous Y value
|
||||
}
|
||||
|
||||
float flipSide = index % 2 == 0 ? 1 : -1;
|
||||
float y = prevY + (flipSide * diff);
|
||||
|
||||
return new Vector3(hitX * offsetMultipliers.x, y, 0);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/ProtoTyping/AlgorithmTest.cs.meta
Normal file
11
Assets/Scripts/ProtoTyping/AlgorithmTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4211f2cde196b14cb9d69a4879ae7cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/WallGenerator.cs
Normal file
19
Assets/Scripts/WallGenerator.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
|
||||
public class WallGenerator : MonoBehaviour
|
||||
{
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/WallGenerator.cs.meta
Normal file
11
Assets/Scripts/WallGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7ecb107d407d8a4baf738f938e654b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user