Added audiosettings.txt as audio save and load, v1.0.2
This commit is contained in:
parent
82640ba473
commit
94bff88d4c
@ -1,5 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -17,6 +19,8 @@ public class AudioHandler : MonoBehaviour
|
||||
AudioSource cameraAudio;
|
||||
AudioSource playerAudio;
|
||||
|
||||
string filepath = "./audiosettings.txt";
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@ -96,11 +100,47 @@ public class AudioHandler : MonoBehaviour
|
||||
|
||||
public void changeVolumeEffects()
|
||||
{
|
||||
playerAudio.volume = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
playerAudio.volume = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
}
|
||||
|
||||
private void loadAudioSettings()
|
||||
public void setSlider()
|
||||
{
|
||||
//Need to work on
|
||||
GameObject.Find("slideEffects").GetComponent<Slider>().value = playerAudio.volume;
|
||||
GameObject.Find("slideMusic").GetComponent<Slider>().value = cameraAudio.volume;
|
||||
}
|
||||
|
||||
public void loadAudioSettings()
|
||||
{
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
string[] lines = File.ReadAllLines(filepath);
|
||||
cameraAudio.volume = float.Parse(lines[0].Split(':')[1]);
|
||||
playerAudio.volume = float.Parse(lines[1].Split(':')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
StreamWriter sw = File.CreateText(filepath);
|
||||
sw.WriteLine("Music:0.5");
|
||||
sw.WriteLine("Effects:0.5");
|
||||
sw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAudioSettings()
|
||||
{
|
||||
float music = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
float effects = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
StreamWriter sw;
|
||||
if (!File.Exists(filepath))
|
||||
{
|
||||
sw = File.CreateText(filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw = new StreamWriter(filepath);
|
||||
}
|
||||
sw.WriteLine("Music:"+ music);
|
||||
sw.WriteLine("Effects:"+ effects);
|
||||
sw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ namespace Assets.Scripts
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
audioHandler.loadAudioSettings();
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
@ -109,6 +110,7 @@ namespace Assets.Scripts
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.adaptScreen();
|
||||
audioHandler.saveAudioSettings();
|
||||
}
|
||||
|
||||
public void closeTutorial()
|
||||
|
||||
@ -181,6 +181,7 @@ namespace Assets.Scripts
|
||||
public void openOptions()
|
||||
{
|
||||
options.SetActive(true);
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().setSlider();
|
||||
hideOtherElements(options);
|
||||
if (state == UIState.MAINMENU)
|
||||
{
|
||||
|
||||
2
audiosettings.txt
Normal file
2
audiosettings.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Music:0.07957498
|
||||
Effects:1
|
||||
Loading…
x
Reference in New Issue
Block a user