mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
created audio manager and Sound class
This commit is contained in:
8
Assets/Audios.meta
Normal file
8
Assets/Audios.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 07778ec755e38984e8ab154c052dbfe3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/Audios/test.wav
Normal file
BIN
Assets/Audios/test.wav
Normal file
Binary file not shown.
22
Assets/Audios/test.wav.meta
Normal file
22
Assets/Audios/test.wav.meta
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c1a5d2c14eea7144d888cf025464b077
|
||||||
|
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:
|
||||||
@@ -1189,6 +1189,56 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 609661063}
|
m_GameObject: {fileID: 609661063}
|
||||||
m_CullTransparentMesh: 1
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!1 &650918549
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 650918551}
|
||||||
|
- component: {fileID: 650918550}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: AudioManager
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &650918550
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 650918549}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 0018a9494d9c3f5439fea5ecf8a53a26, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
sounds:
|
||||||
|
- name: test
|
||||||
|
clip: {fileID: 8300000, guid: c1a5d2c14eea7144d888cf025464b077, type: 3}
|
||||||
|
volume: 1
|
||||||
|
pitch: 1
|
||||||
|
source: {fileID: 0}
|
||||||
|
--- !u!4 &650918551
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 650918549}
|
||||||
|
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_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &686586640
|
--- !u!1 &686586640
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1282,7 +1332,7 @@ Transform:
|
|||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 4
|
||||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||||
--- !u!114 &686586643
|
--- !u!114 &686586643
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -1687,7 +1737,7 @@ Transform:
|
|||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 2
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &958699931
|
--- !u!114 &958699931
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -2060,7 +2110,7 @@ RectTransform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1535827566}
|
- {fileID: 1535827566}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 4
|
m_RootOrder: 5
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
@@ -2132,7 +2182,7 @@ Transform:
|
|||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 5
|
m_RootOrder: 6
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!224 &1128837698 stripped
|
--- !u!224 &1128837698 stripped
|
||||||
RectTransform:
|
RectTransform:
|
||||||
@@ -5056,7 +5106,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7086846156459211593, guid: 0f6d9d1e97686d34d9872b5028512de5, type: 3}
|
- target: {fileID: 7086846156459211593, guid: 0f6d9d1e97686d34d9872b5028512de5, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 0
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7086846156459211593, guid: 0f6d9d1e97686d34d9872b5028512de5, type: 3}
|
- target: {fileID: 7086846156459211593, guid: 0f6d9d1e97686d34d9872b5028512de5, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
@@ -5117,7 +5167,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7631475222009660906, guid: 05731c1ab7f50df438d8ad4231f0e4e5, type: 3}
|
- target: {fileID: 7631475222009660906, guid: 05731c1ab7f50df438d8ad4231f0e4e5, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 1
|
value: 2
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7631475222009660906, guid: 05731c1ab7f50df438d8ad4231f0e4e5, type: 3}
|
- target: {fileID: 7631475222009660906, guid: 05731c1ab7f50df438d8ad4231f0e4e5, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
|
|||||||
8
Assets/Scripts/Audio.meta
Normal file
8
Assets/Scripts/Audio.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b6dcdcc23d4d29b468275ced8b179728
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
51
Assets/Scripts/Audio/AudioManager.cs
Normal file
51
Assets/Scripts/Audio/AudioManager.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using UnityEditor.Audio;
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class AudioManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Sound[] sounds;
|
||||||
|
|
||||||
|
public static AudioManager instance;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
if(instance == null)
|
||||||
|
instance = this;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DontDestroyOnLoad(gameObject);
|
||||||
|
|
||||||
|
foreach(Sound s in sounds)
|
||||||
|
{
|
||||||
|
s.source = gameObject.AddComponent<AudioSource>();
|
||||||
|
s.source.clip = s.clip;
|
||||||
|
|
||||||
|
s.source.volume = s.volume;
|
||||||
|
s.source.pitch = s.pitch;
|
||||||
|
s.source.loop = s.loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
// Enter Music here
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Play(string name)
|
||||||
|
{
|
||||||
|
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||||
|
if(s == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Sound: " + s.name + " not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s.source.Play();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/Audio/AudioManager.cs.meta
Normal file
11
Assets/Scripts/Audio/AudioManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0018a9494d9c3f5439fea5ecf8a53a26
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
21
Assets/Scripts/Audio/Sound.cs
Normal file
21
Assets/Scripts/Audio/Sound.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using UnityEngine.Audio;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class Sound
|
||||||
|
{
|
||||||
|
public string name;
|
||||||
|
|
||||||
|
public AudioClip clip;
|
||||||
|
|
||||||
|
[Range(0f, 1f)]
|
||||||
|
public float volume;
|
||||||
|
|
||||||
|
[Range (.1f, 3f)]
|
||||||
|
public float pitch;
|
||||||
|
|
||||||
|
[HideInInspector]
|
||||||
|
public AudioSource source;
|
||||||
|
|
||||||
|
public bool loop;
|
||||||
|
}
|
||||||
11
Assets/Scripts/Audio/Sound.cs.meta
Normal file
11
Assets/Scripts/Audio/Sound.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 19dd45dc7a1b8284aabf85e506a4c065
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -67,6 +67,7 @@ public class HomeSceneBtnScript : MonoBehaviour, IPointerEnterHandler, IPointerE
|
|||||||
public void OnPointerEnter(PointerEventData eventData)
|
public void OnPointerEnter(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
isHovering = true;
|
isHovering = true;
|
||||||
|
FindObjectOfType<AudioManager>().Play("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPointerExit(PointerEventData eventData)
|
public void OnPointerExit(PointerEventData eventData)
|
||||||
|
|||||||
Reference in New Issue
Block a user