Reworked code, Code cleanup, No new Version
This commit is contained in:
128
Assets/Scripts/Handler/AudioHandler.cs
Normal file
128
Assets/Scripts/Handler/AudioHandler.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Assets.Scripts;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AudioHandler : MonoBehaviour
|
||||
{
|
||||
public AudioClip buttonClick;
|
||||
public AudioClip damage;
|
||||
public AudioClip explosion;
|
||||
public AudioClip hit;
|
||||
public AudioClip hitDagger;
|
||||
public AudioClip IceHit;
|
||||
public AudioClip LevelUp;
|
||||
public AudioClip jump;
|
||||
|
||||
AudioSource cameraAudio;
|
||||
AudioSource playerAudio;
|
||||
|
||||
string filepath = "./audiosettings.txt";
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void Start()
|
||||
{
|
||||
cameraAudio = GameObject.Find("Main Camera").GetComponent<AudioSource>();
|
||||
playerAudio = GameObject.Find("Player").GetComponent<AudioSource>();
|
||||
loadAudioSettings();
|
||||
}
|
||||
|
||||
public void playButtonClick()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = buttonClick;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playDamage()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = damage;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playExplosion()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = explosion;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = hit;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playDaggerHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = hitDagger;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playIceHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = IceHit;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playJump()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = jump;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playLevelUp()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = LevelUp;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void changeVolumeMusic()
|
||||
{
|
||||
cameraAudio.volume = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
int volume = (int)(cameraAudio.volume * 100);
|
||||
GameObject.Find("txtMusic").GetComponent<Text>().text = "Music (" + volume + "%)";
|
||||
}
|
||||
|
||||
public void changeVolumeEffects()
|
||||
{
|
||||
playerAudio.volume = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
int volume = (int)(playerAudio.volume * 100);
|
||||
GameObject.Find("txtEffects").GetComponent<Text>().text = "Effects (" + volume + "%)";
|
||||
}
|
||||
|
||||
public void setSlider()
|
||||
{
|
||||
GameObject.Find("slideEffects").GetComponent<Slider>().value = playerAudio.volume;
|
||||
GameObject.Find("slideMusic").GetComponent<Slider>().value = cameraAudio.volume;
|
||||
}
|
||||
|
||||
public void loadAudioSettings()
|
||||
{
|
||||
FileHandler.loadAudio(filepath, cameraAudio, playerAudio);
|
||||
}
|
||||
|
||||
public void saveAudioSettings()
|
||||
{
|
||||
float music = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
float effects = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
FileHandler.saveAudio(filepath, music, effects);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user