diff --git a/Assets/SampleAssets/Environment/Water/Water/Materials/WaterProNighttime.mat b/Assets/SampleAssets/Environment/Water/Water/Materials/WaterProNighttime.mat index f3b75df..9a4a245 100644 --- a/Assets/SampleAssets/Environment/Water/Water/Materials/WaterProNighttime.mat +++ b/Assets/SampleAssets/Environment/Water/Water/Materials/WaterProNighttime.mat @@ -31,23 +31,23 @@ Material: m_Offset: {x: 0, y: 0} data: first: - name: _ReflectionTex + name: _Fresnel second: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: 5b5c5575fd4c74abd9f7b30862fb76a3, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} data: first: - name: _Fresnel + name: _ReflectiveColor second: - m_Texture: {fileID: 2800000, guid: 5b5c5575fd4c74abd9f7b30862fb76a3, type: 3} + m_Texture: {fileID: 2800000, guid: b725b62cfc9d04e4886735ab2a8107d1, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} data: first: - name: _ReflectiveColor + name: _ReflectionTex second: - m_Texture: {fileID: 2800000, guid: b725b62cfc9d04e4886735ab2a8107d1, type: 3} + m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} data: @@ -82,10 +82,6 @@ Material: first: name: _Color second: {r: 1, g: 1, b: 1, a: 1} - data: - first: - name: _MainTex_ST - second: {r: 1, g: 1, b: 0, a: 0} data: first: name: _RefrColor @@ -118,6 +114,10 @@ Material: first: name: _RefractionTex_ST second: {r: 1, g: 1, b: 0, a: 0} + data: + first: + name: _MainTex_ST + second: {r: 1, g: 1, b: 0, a: 0} data: first: name: _ReflectiveColorCube_ST diff --git a/Assets/_Scripts/AudioController.cs b/Assets/_Scripts/AudioController.cs index 8279c06..cff3542 100644 --- a/Assets/_Scripts/AudioController.cs +++ b/Assets/_Scripts/AudioController.cs @@ -2,14 +2,13 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; -using NAudio; using NAudio.Wave; +using UnityEditor; public class AudioController : MonoBehaviour { struct SongData { public string path; - public string tempDir; + public string songDir; public int index; public AudioClip clip; } @@ -21,47 +20,52 @@ struct SongData { SongData nowPlaying; SongData upNext; - AudioSource src; + AudioSource audioSrc; int length = 0; int skipRate = 0; - // Use this for initialization - void Start () { - src = GetComponent(); + string _fpath; + string[] files; + + // Use this for initialization + void Start () { + audioSrc = GetComponent(); Application.targetFrameRate = 30; AudioListener.pause = true; + _fpath = EditorUtility.OpenFolderPanel("Select Music Folder Desired", "", ""); + SetupInitialSongs(); } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.Alpha1)) { - src.timeSamples = skipRate; + audioSrc.timeSamples = skipRate; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { - src.timeSamples = skipRate*2; + audioSrc.timeSamples = skipRate*2; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { - src.timeSamples = skipRate*3; + audioSrc.timeSamples = skipRate*3; } else if (Input.GetKeyDown(KeyCode.Alpha4)) { - src.timeSamples = skipRate*4; + audioSrc.timeSamples = skipRate*4; } else if (Input.GetKeyDown(KeyCode.Alpha5)) { - src.timeSamples = skipRate*5; + audioSrc.timeSamples = skipRate*5; } else if (Input.GetKeyDown(KeyCode.Alpha6)) { - src.timeSamples = skipRate*6; + audioSrc.timeSamples = skipRate*6; } else if (Input.GetKeyDown(KeyCode.Alpha7)) { - src.timeSamples = skipRate*7; + audioSrc.timeSamples = skipRate*7; } else if (Input.GetKeyDown(KeyCode.Alpha8)) { - src.timeSamples = skipRate*8; + audioSrc.timeSamples = skipRate*8; } else if (Input.GetKeyDown(KeyCode.Alpha9)) { - src.timeSamples = skipRate*9; + audioSrc.timeSamples = skipRate*9; } else if (Input.GetKeyDown (KeyCode.Alpha0)) { - src.timeSamples = 0; + audioSrc.timeSamples = 0; } if (Input.GetKeyDown(KeyCode.Space)) { AudioListener.pause = !AudioListener.pause; - if (!src.isPlaying) { + if (!audioSrc.isPlaying) { PlayNextTrack(); } } @@ -76,26 +80,44 @@ void Update () { // set now playing and up next tracks void SetupInitialSongs() { - string fpath = Application.dataPath + path; +// string _fpath = Application.dataPath + path; + // go through the directory and search for songs - if (Directory.Exists(fpath)) { - string[] files = Directory.GetFiles(fpath, "*.mp3", SearchOption.AllDirectories); + if (Directory.Exists(_fpath)) { + files = Directory.GetFiles(_fpath, "*.mp3", SearchOption.AllDirectories); Debug.Log(files.Length.ToString() + " mp3's found."); SetNowPlaying(); SetUpNext(); } else { - Debug.LogError("File path '" + fpath + "' does not exist."); + Debug.LogError("File path '" + _fpath + "' does not exist."); + } + } + + void SetNowPlaying() { + nowPlaying = GetAvailableTrack(); + if (!string.IsNullOrEmpty(nowPlaying.path)) { + songs.Add(nowPlaying); + } + } + + void SetUpNext() { + upNext = GetAvailableTrack(); + if (!string.IsNullOrEmpty(upNext.path)) { + StartCoroutine(LoadSong(upNext, false)); + songs.Add(upNext); } } SongData GetAvailableTrack() { SongData sd = new SongData(); - string fpath = Application.dataPath + path; - string[] files = Directory.GetFiles(fpath, "*.mp3", SearchOption.AllDirectories); +// string fpath = Application.dataPath + path; +// string[] files = Directory.GetFiles(_fpath, "*.mp3", SearchOption.AllDirectories); + + if (files.Length == 0) + return sd; - if (files.Length == 0) return sd; // pick a random song int r = Random.Range(0,files.Length); @@ -107,6 +129,7 @@ SongData GetAvailableTrack() { if (files[r].Contains("._")) { exists = true; } + foreach(SongData song in songs) { if (song.index == r) { exists = true; @@ -125,44 +148,72 @@ SongData GetAvailableTrack() { songs.Clear(); } else { sd.path = files[r]; - sd.tempDir = Application.dataPath + tempDir + Path.GetFileNameWithoutExtension(files[r]) + ".wav"; +// sd.songDir = _fpath; + sd.songDir = Application.dataPath + tempDir + Path.GetFileNameWithoutExtension(sd.path) + ".wav"; sd.index = r; } return sd; } - void SetNowPlaying() { - nowPlaying = GetAvailableTrack(); - if (!string.IsNullOrEmpty(nowPlaying.path)) { - songs.Add(nowPlaying); + IEnumerator LoadSong(SongData sd, bool playImmediate) { + if (!File.Exists(sd.songDir) || sd.clip == null) { + + // create the temp wav file + Debug.Log("Converting mp3 to wav: " + sd.path); + if (!Directory.Exists(Application.dataPath + tempDir)) { + Directory.CreateDirectory(Application.dataPath + tempDir); + } + using (Mp3FileReader reader = new Mp3FileReader(sd.path)) { + WaveFileWriter.CreateWaveFile(sd.songDir, reader); + } + + WWW song = new WWW("file://" + sd.songDir); + yield return song; + + if (!string.IsNullOrEmpty(song.error)) { + Debug.LogError("Could not load " + sd.songDir); + } + + AudioClip clip = song.GetAudioClip(false, true); + while (clip.loadState != AudioDataLoadState.Loaded && clip.loadState != AudioDataLoadState.Failed) { + yield return song; + } + + sd.clip = clip; + if (!playImmediate) { + upNext.clip = clip; + } + } + + if (sd.clip.loadState == AudioDataLoadState.Failed) { + Debug.LogError("Failed to load."); + } + else if (playImmediate) { + FinishedLoading(sd); + } + else { + Debug.Log("Finished loading next track " + sd.songDir); } + yield return null; } public void PlayNextTrack() { StopCoroutine(PrepareNextSong()); - if (string.IsNullOrEmpty(upNext.path)) + if (string.IsNullOrEmpty(upNext.path)){ SetUpNext(); - - if (!string.IsNullOrEmpty(upNext.path)) { - PlayUpNext(); } - } - - void SetUpNext() { - upNext = GetAvailableTrack(); - if (!string.IsNullOrEmpty(upNext.path)) { - StartCoroutine(LoadSong(upNext, false)); - songs.Add(upNext); + else { + PlayUpNext(); } } void PlayUpNext() { - src.Stop(); - src.timeSamples = 0; + audioSrc.Stop(); + audioSrc.timeSamples = 0; // remove previous played audio - if (!string.IsNullOrEmpty(nowPlaying.tempDir)) { + if (!string.IsNullOrEmpty(nowPlaying.songDir)) { UnloadWav(nowPlaying); } nowPlaying = upNext; @@ -185,7 +236,7 @@ IEnumerator PrepareNextSong() { yield return new WaitForEndOfFrame(); yield return new WaitForSeconds(nowPlaying.clip.length); - while (src.isPlaying) { + while (audioSrc.isPlaying) { yield return new WaitForEndOfFrame(); } @@ -193,59 +244,21 @@ IEnumerator PrepareNextSong() { yield return null; } - IEnumerator LoadSong(SongData sd, bool playImmediate) { - if (!File.Exists(sd.tempDir) || sd.clip == null) { - // create the temp wav file - Debug.Log("Converting mp3 to wav: " + sd.path); - if (!Directory.Exists(Application.dataPath + tempDir)) { - Directory.CreateDirectory(Application.dataPath + tempDir); - } - using (Mp3FileReader reader = new Mp3FileReader(sd.path)) { - WaveFileWriter.CreateWaveFile(sd.tempDir, reader); - } - - WWW song = new WWW("file://" + sd.tempDir); - yield return song; - - if (!string.IsNullOrEmpty(song.error)) { - Debug.LogError("Could not load " + sd.tempDir); - } - - AudioClip clip = song.GetAudioClip(false,true); - while (clip.loadState != AudioDataLoadState.Loaded && - clip.loadState != AudioDataLoadState.Failed) - yield return song; - - sd.clip = clip; - if (!playImmediate) - upNext.clip = clip; - } - - if (sd.clip.loadState == AudioDataLoadState.Failed) { - Debug.LogError("Failed to load."); - } else if (playImmediate) { - FinishedLoading(sd); - } else { - Debug.Log("Finished loading next track " + sd.tempDir); - } - yield return null; - } - void FinishedLoading(SongData sd) { - src.clip = sd.clip; - length = src.clip.samples; + audioSrc.clip = sd.clip; + length = audioSrc.clip.samples; skipRate = length / 10; - src.Play(); - Debug.Log("Playing " + sd.tempDir); + audioSrc.Play(); + Debug.Log("Playing " + sd.songDir); SongTitle st = FindObjectOfType(); - if (st != null) st.Set(Path.GetFileNameWithoutExtension(sd.tempDir)); + if (st != null) st.Set(Path.GetFileNameWithoutExtension(sd.songDir)); } void UnloadWav(SongData sd) { - if (songs.Contains(sd) && File.Exists(sd.tempDir)) { - File.Delete(sd.tempDir); - string meta = sd.tempDir; + if (songs.Contains(sd) && File.Exists(sd.songDir)) { + File.Delete(sd.songDir); + string meta = sd.songDir; meta = meta.Replace(".mp3", ".meta"); if (File.Exists(meta)) @@ -258,16 +271,16 @@ void OnApplicationQuit() { if (songs == null || songs.Count == 0) return; foreach (SongData sd in songs) { - if (File.Exists(sd.tempDir)) { - File.Delete(sd.tempDir); - string meta = sd.tempDir; + if (File.Exists(sd.songDir)) { + File.Delete(sd.songDir); + string meta = sd.songDir; meta = meta.Replace(".mp3", ".meta"); - if (File.Exists(meta)) + if (File.Exists(meta)) { File.Delete(meta); + } } } - songs.Clear(); } } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 40763c8..6d72c7d 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -117,6 +117,8 @@ PlayerSettings: m_Bits: 238 iPhoneSdkVersion: 988 iPhoneTargetOSVersion: 22 + tvOSSdkVersion: 0 + tvOSTargetOSVersion: 900 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 @@ -205,6 +207,7 @@ PlayerSettings: wiiUSystemHeapSize: 128 wiiUTVStartupScreen: {fileID: 0} wiiUGamePadStartupScreen: {fileID: 0} + wiiUDrcBufferDisabled: 0 wiiUProfilerLibPath: actionOnDotNetUnhandledException: 1 enableInternalProfiler: 0 @@ -272,6 +275,7 @@ PlayerSettings: ps4DownloadDataSize: 0 ps4GarlicHeapSize: 2048 ps4Passcode: uwTFsliQMpWzyyGG2iRwqu6zLOqWcXe8 + ps4UseDebugIl2cppLibs: 0 ps4pnSessions: 1 ps4pnPresence: 1 ps4pnFriends: 1 @@ -337,6 +341,7 @@ PlayerSettings: psp2UseLibLocation: 0 psp2InfoBarOnStartup: 0 psp2InfoBarColor: 0 + psp2UseDebugIl2cppLibs: 0 psmSplashimage: {fileID: 0} spritePackerPolicy: scriptingDefineSymbols: diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index c4684cd..558807b 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.3.4f1 +m_EditorVersion: 5.3.5f1 m_StandardAssetsVersion: 0 diff --git a/README.md b/README.md index 4a4243b..a370e43 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,10 @@ This project is far from perfect, but it's a good start for somebody that wants ## Future: -What I'd like to do, first and foremost, is get the scene and code cleaned up so it's more easily readable. However, I would like to get the following in place, and feel free to fork/contribute! -* Music browser and playlist - allow user to open a dialogue to select songs to play or add to a playlist. +What I'd like to do, first and foremost, is get the scene and code cleaned up so it's more easily readable. However, I would like to get the following in place, and feel free to fork/contribute! ** Cleaned up some of the code for better readability and flow -claytonNighthawk +* Music browser and playlist - allow user to open a dialogue to select songs to play or add to a playlist. + * Half done but its not usable outside of the editor... -claytonNighthawk * Audio streaming - not just .mp3's, but most common audio formats including .ogg and .mp4. Currently the audio must be placed in a resource folder and exported to .wav temporarily. + * Looking into a way to read other formats -claytonNighthawk * Real-time device listening - instead of having to play mp3s, I want the visualization to work off any audio playing on the system. * Submit your ideas to go here!