diff --git a/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab b/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab new file mode 100644 index 0000000..4487dca Binary files /dev/null and b/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab differ diff --git a/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab.meta b/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab.meta new file mode 100644 index 0000000..87fed3f --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Prefabs/SoundTester.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 757a4ad5f1afb4aa68f58e8bdbbdc4f9 +timeCreated: 1437836118 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab b/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab new file mode 100644 index 0000000..a4bcd65 Binary files /dev/null and b/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab differ diff --git a/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab.meta b/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab.meta new file mode 100644 index 0000000..d83f9b6 --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Prefabs/TestPlayer.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2e08ddbac2fd744bd92d05452d7cbceb +timeCreated: 1437839045 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity b/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity new file mode 100644 index 0000000..5b9bd06 Binary files /dev/null and b/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity differ diff --git a/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity.meta b/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity.meta new file mode 100644 index 0000000..a67f8aa --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scenes/ControllerTestScene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 77777042705174bbbbe45eb381451a92 +timeCreated: 1437841091 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity b/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity new file mode 100644 index 0000000..035122f Binary files /dev/null and b/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity differ diff --git a/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity.meta b/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity.meta new file mode 100644 index 0000000..133ce77 --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scenes/SoundTestScene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 41c2812a9d221495595205ef62d70d4a +timeCreated: 1437837021 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs b/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs new file mode 100644 index 0000000..238d08a --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs @@ -0,0 +1,60 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +public class ControllerTestScript : MonoBehaviour { + + private int m_id; + private HFTGamepad m_gamepad; + private static Dictionary s_ids= new Dictionary(); +// private HFTInput m_hftInput; + + void Start () + { + // Find an empty id; + bool foo = false; + for (int ii = 0; ii < 1000; ++ii) { + if (!s_ids.TryGetValue(ii, out foo)) { + m_id = ii; + s_ids[ii] = true; + break; + } + } + + m_gamepad = GetComponent(); +// m_hftInput = GetComponent(); + m_gamepad.NetPlayer.OnDisconnect += OnDisconnect; + } + + void OnDisconnect(object sender, System.EventArgs args) + { + s_ids.Remove(m_id); + } + + void OnGUI() + { + int unitWidth = 20; + int unitHeight = 20; + int xx = 10 + 110 * m_id; + int yy = 10; + GUI.Box(new Rect(xx, 10, 100, unitHeight), m_gamepad.Name); + yy += unitHeight; + GUI.Box(new Rect(xx, yy, 100, unitHeight), "buttons"); + yy += unitHeight; + for (int ii = 0; ii < m_gamepad.buttons.Length; ++ii) { + int x = ii % 4; + int y = ii / 4; + GUI.Box(new Rect(xx + x * unitWidth, yy + y * unitHeight, unitWidth, unitHeight), m_gamepad.buttons[ii].pressed ? "*" : ""); + } + yy += unitHeight * ((m_gamepad.buttons.Length + 3) / 4); + + GUI.Box(new Rect(xx, yy, 100, unitHeight), "axes"); + yy += unitHeight; + for (int ii = 0; ii < m_gamepad.axes.Length; ++ii) { + int x = ii % 4; + int y = ii / 4; + GUI.Box(new Rect(xx + x * unitWidth, yy + y * unitHeight, unitWidth, unitHeight), m_gamepad.axes[ii].ToString()); + } + + } +} diff --git a/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs.meta b/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs.meta new file mode 100644 index 0000000..f03cd76 --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scripts/ControllerTestScript.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d27786e181c27449b9af6430e847727b +timeCreated: 1437839064 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs b/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs new file mode 100644 index 0000000..3e68b4c --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs @@ -0,0 +1,30 @@ +using UnityEngine; +using System.Collections; + +public class SoundTest : MonoBehaviour { + + void Awake () + { + m_soundPlayer = GetComponent(); + } + + void Start() + { + StartCoroutine("Play"); + } + + IEnumerator Play() + { + while (true) + { + yield return new WaitForSeconds(1.0f); + m_soundPlayer.PlaySound("explosion"); + yield return new WaitForSeconds(1.0f); + m_soundPlayer.PlaySound("gameover"); + yield return new WaitForSeconds(1.0f); + m_soundPlayer.PlaySound("launch"); + } + } + + private HFTSoundPlayer m_soundPlayer; +} diff --git a/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs.meta b/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs.meta new file mode 100644 index 0000000..d74fd1d --- /dev/null +++ b/Assets/HappyFunTimes/Samples/Scripts/SoundTest.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ea3dc51d65b8d4f78b85d48c1765c93e +timeCreated: 1437835218 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs b/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs new file mode 100644 index 0000000..0903cff --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs @@ -0,0 +1,43 @@ +using HappyFunTimes; +using HFTSounds; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System.IO; + +public class HFTGlobalSoundHelper : MonoBehaviour { + + public static Sounds GetSounds() { + return s_sounds; + } + + void Awake() + { + if (s_sounds == null) { + InitSounds(); + } + } + + void InitSounds() + { + s_sounds = new Sounds(); + string baseFolder = Path.Combine(Path.Combine(Application.dataPath, "WebPlayerTemplates"), "HappyFunTimes"); + string soundFolder = Path.Combine(baseFolder, "sounds"); + if (Directory.Exists(soundFolder)) { + AddSoundFiles(baseFolder, Directory.GetFiles(soundFolder, "*.mp3")); + AddSoundFiles(baseFolder, Directory.GetFiles(soundFolder, "*.wav")); + } + } + + void AddSoundFiles(string baseFolder, string[] filenames) + { + foreach(string filename in filenames) + { + string filepath = filename.Substring(baseFolder.Length + 1).Replace("\\", "/"); + s_sounds[Path.GetFileNameWithoutExtension(filename)] = new SoundFile(filepath); + } + } + + private static Sounds s_sounds = null; +}; + diff --git a/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs.meta b/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs.meta new file mode 100644 index 0000000..083af04 --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTGlobalSoundHelper.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 612779ba57459498a87550aeebb42931 +timeCreated: 1437835302 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs b/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs new file mode 100644 index 0000000..2e4c455 --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs @@ -0,0 +1,49 @@ +using HappyFunTimes; +using HFTSounds; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +[RequireComponent (typeof (HFTGamepad))] +public class HFTSoundPlayer : MonoBehaviour { + + private class MessageLoadSounds : MessageCmdData { + public MessageLoadSounds(Sounds _sounds) { + sounds = _sounds; + } + public Sounds sounds = null; + } + + private class MessagePlaySound : MessageCmdData { + public MessagePlaySound(string _name, bool _loop = false) { + name = _name; + loop = _loop; + } + public string name; + public bool loop; + } + + void Awake() + { + try { + HFTGlobalSoundHelper.GetSounds(); + } catch (System.Exception) { + Debug.LogError("No HFTGlobalSoundHelper in scene. Please add one"); + } + m_gamepad = GetComponent(); + } + + void Start() + { + m_gamepad.NetPlayer.SendCmd("loadSounds", new MessageLoadSounds(HFTGlobalSoundHelper.GetSounds())); + } + + public void PlaySound(string name, bool loop = false) + { + m_gamepad.NetPlayer.SendCmd("playSound", new MessagePlaySound(name, loop)); + } + + private HFTGamepad m_gamepad; + +}; + diff --git a/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs.meta b/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs.meta new file mode 100644 index 0000000..d8d70cd --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTSoundPlayer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 49ca5391eb348422fb5e3f060f9736a4 +timeCreated: 1437835302 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HappyFunTimes/Scripts/HFTSounds.cs b/Assets/HappyFunTimes/Scripts/HFTSounds.cs new file mode 100644 index 0000000..8e475b8 --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTSounds.cs @@ -0,0 +1,195 @@ +using HappyFunTimes; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace HFTSounds { + public class Sound { + }; + + public class SoundFile : Sound { + public SoundFile(string _filename) { + filename = _filename; + } + public string filename; + }; + + public class SoundJSFX : Sound { + public SoundJSFX( + string generator, + float superSamplingQuality, + float masterVolume, + float attackTime, + float sustainTime, + float sustainPunch, + float decayTime, + float minFrequency, + float maxFrequency, + float slide, + float deltaSlide, + float vibratoDepth, + float vibratoFrequency, + float vibratoDepthSlide, + float vibratoFrequencySlide, + float changeAmount, + float changeSpeed, + float squareDuty, + float squareDutySweep, + float repeatSpeed, + float phaserSweep, + float lpFilterCutoff, + float lpFilterCutoffSweep, + float lpFilterResonance, + float hpFilterCutoff, + float hpFilterCutoffSweep) { + Init( + generator, + superSamplingQuality, + masterVolume, + attackTime, + sustainTime, + sustainPunch, + decayTime, + minFrequency, + maxFrequency, + slide, + deltaSlide, + vibratoDepth, + vibratoFrequency, + vibratoDepthSlide, + vibratoFrequencySlide, + changeAmount, + changeSpeed, + squareDuty, + squareDutySweep, + repeatSpeed, + phaserSweep, + lpFilterCutoff, + lpFilterCutoffSweep, + lpFilterResonance, + hpFilterCutoff, + hpFilterCutoffSweep); + } + + private SoundJSFX( + string generator, + double superSamplingQuality, + double masterVolume, + double attackTime, + double sustainTime, + double sustainPunch, + double decayTime, + double minFrequency, + double maxFrequency, + double slide, + double deltaSlide, + double vibratoDepth, + double vibratoFrequency, + double vibratoDepthSlide, + double vibratoFrequencySlide, + double changeAmount, + double changeSpeed, + double squareDuty, + double squareDutySweep, + double repeatSpeed, + double phaserSweep, + double lpFilterCutoff, + double lpFilterCutoffSweep, + double lpFilterResonance, + double hpFilterCutoff, + double hpFilterCutoffSweep) { + Init( + generator, + (float)superSamplingQuality, + (float)masterVolume, + (float)attackTime, + (float)sustainTime, + (float)sustainPunch, + (float)decayTime, + (float)minFrequency, + (float)maxFrequency, + (float)slide, + (float)deltaSlide, + (float)vibratoDepth, + (float)vibratoFrequency, + (float)vibratoDepthSlide, + (float)vibratoFrequencySlide, + (float)changeAmount, + (float)changeSpeed, + (float)squareDuty, + (float)squareDutySweep, + (float)repeatSpeed, + (float)phaserSweep, + (float)lpFilterCutoff, + (float)lpFilterCutoffSweep, + (float)lpFilterResonance, + (float)hpFilterCutoff, + (float)hpFilterCutoffSweep); + } + + void Init( + string _generator, + float superSamplingQuality, + float masterVolume, + float attackTime, + float sustainTime, + float sustainPunch, + float decayTime, + float minFrequency, + float maxFrequency, + float slide, + float deltaSlide, + float vibratoDepth, + float vibratoFrequency, + float vibratoDepthSlide, + float vibratoFrequencySlide, + float changeAmount, + float changeSpeed, + float squareDuty, + float squareDutySweep, + float repeatSpeed, + float phaserSweep, + float lpFilterCutoff, + float lpFilterCutoffSweep, + float lpFilterResonance, + float hpFilterCutoff, + float hpFilterCutoffSweep) { + generator = _generator; + parameters = new float[25]; + + parameters[ 0] = superSamplingQuality; + parameters[ 1] = masterVolume; + parameters[ 2] = attackTime; + parameters[ 3] = sustainTime; + parameters[ 4] = sustainPunch; + parameters[ 5] = decayTime; + parameters[ 6] = minFrequency; + parameters[ 7] = maxFrequency; + parameters[ 8] = slide; + parameters[ 9] = deltaSlide; + parameters[10] = vibratoDepth; + parameters[11] = vibratoFrequency; + parameters[12] = vibratoDepthSlide; + parameters[13] = vibratoFrequencySlide; + parameters[14] = changeAmount; + parameters[15] = changeSpeed; + parameters[16] = squareDuty; + parameters[17] = squareDutySweep; + parameters[18] = repeatSpeed; + parameters[19] = phaserSweep; + parameters[20] = lpFilterCutoff; + parameters[21] = lpFilterCutoffSweep; + parameters[22] = lpFilterResonance; + parameters[23] = hpFilterCutoff; + parameters[24] = hpFilterCutoffSweep; + } + + public string generator = ""; + public float[] parameters; + } + + public class Sounds : Dictionary { + + }; +} + diff --git a/Assets/HappyFunTimes/Scripts/HFTSounds.cs.meta b/Assets/HappyFunTimes/Scripts/HFTSounds.cs.meta new file mode 100644 index 0000000..6ca66ec --- /dev/null +++ b/Assets/HappyFunTimes/Scripts/HFTSounds.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 44ffe0cc4ccf54e69a106162e267d541 +timeCreated: 1437836868 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/scripts/controller.js b/Assets/WebPlayerTemplates/HappyFunTimes/scripts/controller.js index 0724354..650264c 100644 --- a/Assets/WebPlayerTemplates/HappyFunTimes/scripts/controller.js +++ b/Assets/WebPlayerTemplates/HappyFunTimes/scripts/controller.js @@ -40,6 +40,7 @@ requirejs([ 'hft/misc/strings', 'hft/misc/touch', '../3rdparty/chroma.min', + './bower_components/hft-utils/dist/audio', // '../3rdparty/gyronorm.complete.min', ], function( commonUI, @@ -49,7 +50,8 @@ requirejs([ mobileHacks, strings, touch, - chroma /*, + chroma, + AudioManager /*, GyroNorm */) { var $ = document.getElementById.bind(document); @@ -84,6 +86,7 @@ requirejs([ var fullElem = $("full"); var client = new GameClient(); + var audioManager = new AudioManager(); var layouts = { "1button": { @@ -203,11 +206,26 @@ requirejs([ fullElem.style.display = "none"; } + function handleLoadSounds(data) { + audioManager.loadSounds(data.sounds); + } + + var playingSounds = {}; + + function handlePlaySound(data) { + var sound = audioManager.playSound(data.name, 0, data.loop); + if (data.remember) { + handleStopSound(data); + playingSounds[data.name] = sound; + } + } + client.addEventListener('color', handleColor); client.addEventListener('options', handleOptions); client.addEventListener('full', handleFull); client.addEventListener('play', handlePlay); - + client.addEventListener('loadSounds', handleLoadSounds); + client.addEventListener('playSound', handlePlaySound); // This way of making buttons probably looks complicated but // it lets us easily make more buttons. diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds.meta b/Assets/WebPlayerTemplates/HappyFunTimes/sounds.meta new file mode 100644 index 0000000..d529837 --- /dev/null +++ b/Assets/WebPlayerTemplates/HappyFunTimes/sounds.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e097f44eeedb5415ba40b292bec7e0ed +folderAsset: yes +timeCreated: 1437834206 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3 b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3 new file mode 100644 index 0000000..a1bed8c Binary files /dev/null and b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3 differ diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3.meta b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3.meta new file mode 100644 index 0000000..e3db6a0 --- /dev/null +++ b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/explosion.mp3.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: afbb5c214d50942c08a5d82f1ecc9cc2 +timeCreated: 1437834206 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3 b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3 new file mode 100644 index 0000000..3096de5 Binary files /dev/null and b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3 differ diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3.meta b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3.meta new file mode 100644 index 0000000..c9e33a4 --- /dev/null +++ b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/gameover.mp3.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 58af48638e01a4616bf99eb32bc36bb5 +timeCreated: 1437834206 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3 b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3 new file mode 100644 index 0000000..162e2e7 Binary files /dev/null and b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3 differ diff --git a/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3.meta b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3.meta new file mode 100644 index 0000000..41e1738 --- /dev/null +++ b/Assets/WebPlayerTemplates/HappyFunTimes/sounds/launch.mp3.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1943cd6152e104bf691cdce3e8a379e3 +timeCreated: 1437834206 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index f7bcabd..28249ce 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,6 @@ another example showing using the phone as a touch pad. * added HFTGamepad.BUTTON_TOUCH for whether or not the user is touching the screen on the orientation and touch controllers. +* added ability to play sound through controller +