Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"Options.cs"
 * 
 *	This script provides a runtime instance of OptionsData,
 *	and has functions for saving and loading this data
 *	into the PlayerPrefs
 * 
 */

using UnityEngine;
using System.Collections;
using AC;

public class Options : MonoBehaviour
{
	
	public OptionsData optionsData;
	
	private string ppKey = "Options";
	
	
	private void Awake ()
	{
		optionsData = new OptionsData();
		LoadPrefs ();
	}
	
	
	public void SavePrefs ()
	{
		string optionsBinary = Serializer.SerializeObjectBinary (optionsData);
		PlayerPrefs.SetString (ppKey, optionsBinary);
		Debug.Log ("PlayerPrefs saved.");
	}
	
	
	private void LoadPrefs ()
	{
		if (PlayerPrefs.HasKey (ppKey))
		{
			string optionsBinary = PlayerPrefs.GetString (ppKey);
			optionsData = Serializer.DeserializeObjectBinary <OptionsData> (optionsBinary);
			Debug.Log ("PlayerPrefs loaded.");
		}
	}
	
	
	private void OnLevelWasLoaded ()
	{
		SetVolume (SoundType.Music);
		SetVolume (SoundType.SFX);	
	}
	
	
	public void SetVolume (SoundType _soundType)
	{
		Sound[] soundObs = FindObjectsOfType (typeof (Sound)) as Sound[];
		
		foreach (Sound soundOb in soundObs)
		{
			if (soundOb.soundType == _soundType)
			{
				soundOb.SetMaxVolume ();
			}
		}
	}

	
	public static int GetLanguage ()
	{
		if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
		{
			return (GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>().optionsData.language);
		}
		else
		{
			return 0;
		}
	}

}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Options/Options.cs

Diff revisions: vs.
Revision Author Commited Message
83 FMMortaroli picture FMMortaroli Tue 13 May, 2014 11:32:51 +0000