Button soudnds

This commit is contained in:
shadow8t4 2017-11-30 14:32:12 -06:00
parent 0a1cf805ba
commit a20a910f1d
37 changed files with 675 additions and 13 deletions

View file

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9ca64cdf9f2ab384f81d2d91ad487c0f
folderAsset: yes
timeCreated: 1505987639
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 74e37f7db68b7964b94637119f3dcad1
timeCreated: 1511930731
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 10d60a985d045cd488c913814441f86d
timeCreated: 1511930726
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 5c5aeb7a633468e4e92167459b1114d1
timeCreated: 1509480226
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 03b5433a3b01f1a478a0a60a4ab6c4ce
timeCreated: 1506626174
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 6043b8fe8a1e8164a945ac9b5aeca19b
timeCreated: 1511930728
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 7c8651e648d96d74f8751aa7648c2c78
timeCreated: 1511930726
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 65283b5f513b9a24395f6d6bbf81c4d4
timeCreated: 1511930729
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: e6e74ed8135a01a4d9035b7b74f1d9b5
timeCreated: 1511930727
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 77782521d29333547a5c38e852982ef4
timeCreated: 1511930732
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 26931c0590f54104282e38538f3a6d31
timeCreated: 1512003643
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: c7dee0dd94e8f7a44a3763dcc9b2d791
timeCreated: 1511930727
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 283868970ca0de4479c0569e4c1f8b7a
timeCreated: 1511930727
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: d69bc6a32aa94d44bbbfd3b31b0ba51a
timeCreated: 1511930723
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 74687976ad17bf142a3de0e50d1db956
timeCreated: 1511930727
licenseType: Free
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657868, g: 0.49641263, b: 0.57481706, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
@ -344,7 +344,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 354694118}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -259.95, y: 9, z: 0}
m_LocalPosition: {x: -220.95003, y: 9, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 21242708}
@ -466,7 +466,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 412709800}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -259.95, y: -184.5, z: 0}
m_LocalPosition: {x: -220.95003, y: -184.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1351649978}
@ -854,7 +854,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 978696437}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -259.95, y: -120, z: 0}
m_LocalPosition: {x: -220.95003, y: -120, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1162748024}
@ -951,6 +951,59 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 978696437}
--- !u!1 &1018096205
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1018096208}
- component: {fileID: 1018096207}
- component: {fileID: 1018096206}
m_Layer: 0
m_Name: AudioManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1018096206
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1018096205}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6ac34ffe2acbb5d46a45800119502349, type: 3}
m_Name:
m_EditorClassIdentifier:
Audiomanager: {fileID: 0}
--- !u!114 &1018096207
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1018096205}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b539363fbe794e74cb83faf330f4ae94, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1018096208
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1018096205}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1033044487
GameObject:
m_ObjectHideFlags: 0
@ -976,7 +1029,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1033044487}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -259.95, y: -55.5, z: 0}
m_LocalPosition: {x: -220.95003, y: -55.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1858353221}
@ -1087,7 +1140,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1040623454}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 476, y: -125, z: 0}
m_LocalPosition: {x: 437, y: -229.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2007653778}
@ -1282,7 +1335,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1265937153}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -189, y: 55, z: 0}
m_LocalPosition: {x: -150, y: 159.5, z: 0}
m_LocalScale: {x: 6, y: 1.5, z: 1}
m_Children:
- {fileID: 18095996}
@ -1414,6 +1467,7 @@ GameObject:
- component: {fileID: 1462892297}
- component: {fileID: 1462892296}
- component: {fileID: 1462892295}
- component: {fileID: 1462892299}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -1483,6 +1537,18 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1462892299
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1462892294}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6ac34ffe2acbb5d46a45800119502349, type: 3}
m_Name:
m_EditorClassIdentifier:
Audiomanager: {fileID: 0}
--- !u!1 &1658932715
GameObject:
m_ObjectHideFlags: 0
@ -1566,7 +1632,7 @@ RectTransform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1658932715}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 524, y: 163, z: 0}
m_LocalPosition: {x: 485, y: 267.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 756434826}
@ -1596,6 +1662,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5794cf98ccb53c6488fb9d30c6b0155b, type: 3}
m_Name:
m_EditorClassIdentifier:
button_sound: {fileID: 8300000, guid: f78b860e068714d41af40156d779a59a, type: 3}
button_sound_src: {fileID: 0}
ui: {fileID: 2097291472}
--- !u!1 &1858353220
GameObject:

View file

@ -0,0 +1,62 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
public class AudioManager : MonoBehaviour
{
public GameObject Audiomanager;
public static AudioManager Main
{
get
{
return GameObject.Find("AudioManager").GetComponent<AudioManager>();
}
}
public HashSet<Sound> sounds =
new HashSet<Sound>();
/// Creates a new sound, registers it, gives it the properties specified, and starts playing it
public Sound PlayNewSound(string soundName, bool loop = false, bool interrupts = false, Action<Sound> callback = null)
{
Sound sound = NewSound(soundName, loop, interrupts, callback);
sound.playing = true;
return sound;
}
/// Creates a new sound, registers it, and gives it the properties specified
public Sound NewSound(string soundName, bool loop = false, bool interrupts = false, Action<Sound> callback = null)
{
Sound sound = new Sound(soundName);
RegisterSound(sound);
sound.loop = loop;
sound.interrupts = interrupts;
sound.callback = callback;
return sound;
}
/// Registers a sound with the AudioManager and gives it an AudioSource if necessary
/// You should probably avoid calling this function directly and just use
/// NewSound and PlayNewSound instead
public void RegisterSound(Sound sound)
{
sounds.Add(sound);
sound.audioManager = this;
if (sound.source == null)
{
AudioSource source = gameObject.AddComponent<AudioSource>();
source.clip = sound.clip;
sound.source = source;
}
}
private void Update()
{
sounds.ToList().ForEach(sound => {
sound.Update();
});
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6ac34ffe2acbb5d46a45800119502349
timeCreated: 1512073101
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewScript : MonoBehaviour {
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
}
// Update is called once per frame
void Update () {
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b539363fbe794e74cb83faf330f4ae94
timeCreated: 1512073440
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,118 @@
using UnityEngine;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class Sound
{
public AudioManager audioManager;
public string name;
public AudioClip clip;
public AudioSource source;
public Action<Sound> callback;
public bool loop;
public bool interrupts;
private HashSet<Sound> interruptedSounds =
new HashSet<Sound>();
/// returns a float from 0.0 to 1.0 representing how much
/// of the sound has been played so far
public float progress
{
get
{
if (source == null || clip == null)
return 0f;
return (float)source.timeSamples / (float)clip.samples;
}
}
/// returns true if the sound has finished playing
/// will always be false for looping sounds
public bool finished
{
get
{
return !loop && progress >= 1f;
}
}
/// returns true if the sound is currently playing,
/// false if it is paused or finished
/// can be set to true or false to play/pause the sound
/// will register the sound before playing
public bool playing
{
get
{
return source != null && source.isPlaying;
}
set
{
if (value)
{
audioManager.RegisterSound(this);
}
PlayOrPause(value, interrupts);
}
}
/// Try to avoid calling this directly
/// Use AudioManager.NewSound instead
public Sound(string newName)
{
name = newName;
clip = (AudioClip)Resources.Load(name, typeof(AudioClip));
if (clip == null)
throw new Exception("Couldn't find AudioClip with name '" + name + "'. Are you sure the file is in a folder named 'Resources'?");
}
public void Update()
{
if (source != null)
source.loop = loop;
if (finished)
Finish();
}
/// Try to avoid calling this directly
/// Use the Sound.playing property instead
public void PlayOrPause(bool play, bool pauseOthers)
{
if (pauseOthers)
{
if (play)
{
interruptedSounds = new HashSet<Sound>(audioManager.sounds.Where(snd => snd.playing &&
snd != this));
}
interruptedSounds.ToList().ForEach(sound => sound.PlayOrPause(!play, false));
}
if (play && !source.isPlaying)
{
source.Play();
}
else
{
source.Pause();
}
}
/// performs necessary actions when a sound finishes
public void Finish()
{
PlayOrPause(false, true);
if (callback != null)
callback(this);
MonoBehaviour.Destroy(source);
source = null;
}
/// Reset the sound to its beginning
public void Reset()
{
source.time = 0f;
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 24a9cb1b6b81c004391b5dc62642fd18
timeCreated: 1512073186
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -4,21 +4,34 @@ using UnityEngine;
public class ButtonController : MonoBehaviour {
public GameObject ui;
public AudioClip button_sound;
public AudioSource button_sound_src;
public GameObject ui;
public void Start() {
button_sound_src = GetComponent<AudioSource>();
}
public void ExitGame() {
AudioManager.Main.PlayNewSound("button_sound");
Application.Quit();
}
public void NextScene(string name) {
Application.LoadLevel(name);
public void NextScene(string name)
{
AudioManager.Main.PlayNewSound("button_sound");
Application.LoadLevel(name);
}
public void ShowInstructions() {
ui.SetActive (true);
AudioManager.Main.PlayNewSound("button_sound");
ui.SetActive (true);
}
public void HideInstructions() {
ui.SetActive (false);
AudioManager.Main.PlayNewSound("button_sound");
ui.SetActive (false);
}
}