prototyping
This commit is contained in:
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:
|
||||
Reference in New Issue
Block a user