Instantly share code, notes, and snippets.
Created
January 12, 2018 01:53
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save ginxx009/e077122632b5e7bcf40e1bb413631dc2 to your computer and use it in GitHub Desktop.
Saving a settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class MobileOpt : MonoBehaviour { | |
[SerializeField] | |
Button openButton, closeButton; | |
[SerializeField] | |
GameObject OPTION_UI;//parent | |
[SerializeField] | |
GameObject open_option_button, close_option_button; | |
[SerializeField] | |
GameObject[] settings; | |
[SerializeField] | |
Toggle[] toggle; | |
bool Found = false; | |
void Start() | |
{ | |
OPTION_UI.SetActive(false); | |
Button OPENBUTTON = openButton.GetComponent<Button>(); | |
Button CLOSEBUTTON = closeButton.GetComponent<Button>(); | |
OPENBUTTON.onClick.AddListener(OpenUI); | |
CLOSEBUTTON.onClick.AddListener(CloseUI); | |
toggle[2].isOn = true; | |
//fog | |
if (PlayerPrefs.GetInt("SaveFog") == 1) | |
{ | |
toggle[0].isOn = true; | |
} | |
else | |
{ | |
toggle[0].isOn = false; | |
} | |
//camera | |
if (PlayerPrefs.GetInt("SaveCamera") == 1) | |
{ | |
toggle[1].isOn = true; | |
} | |
else | |
{ | |
toggle[1].isOn = false; | |
} | |
//livestreaming | |
if (PlayerPrefs.GetInt("SaveLiveStream") == 1) | |
{ | |
toggle[2].isOn = true; | |
} | |
else | |
{ | |
toggle[2].isOn = false; | |
} | |
//rendering | |
if (PlayerPrefs.GetInt("SaveRendering") == 1) | |
{ | |
toggle[3].isOn = true; | |
} | |
else | |
{ | |
toggle[3].isOn = false; | |
} | |
} | |
void Update() | |
{ | |
if (Found) | |
{ | |
StartCoroutine(GameOptions()); | |
} else | |
{ | |
StopCoroutine(GameOptions()); | |
} | |
} | |
IEnumerator GameOptions() | |
{ | |
/* | |
* fog , camera | |
* livestream, rendering | |
* */ | |
//get the options | |
settings = GameObject.FindGameObjectsWithTag("MobileOption"); | |
//fog | |
if (toggle[0].isOn == true) | |
{ | |
PlayerPrefs.SetInt("SaveFog", 1); | |
} else | |
{ | |
PlayerPrefs.SetInt("SaveFog", 0); | |
} | |
//camera | |
if (toggle[1].isOn == true) | |
{ | |
PlayerPrefs.SetInt("SaveCamera", 1); | |
} else | |
{ | |
PlayerPrefs.SetInt("SaveCamera", 0); | |
} | |
//livestream | |
if (toggle[2].isOn == true) | |
{ | |
PlayerPrefs.SetInt("SaveLiveStream" , 1); | |
} else | |
{ | |
PlayerPrefs.SetInt("SaveLiveStream", 0); | |
} | |
//rendering | |
if (toggle[3].isOn == true) | |
{ | |
PlayerPrefs.SetInt("SaveRendering", 1); | |
} else | |
{ | |
PlayerPrefs.SetInt("SaveRendering", 0); | |
} | |
yield return null; | |
} | |
//activate UI | |
void OpenUI() | |
{ | |
Found = true; | |
open_option_button.SetActive(false); | |
close_option_button.SetActive(true); | |
OPTION_UI.SetActive(true); | |
} | |
//deactivate UI | |
void CloseUI() | |
{ | |
Found = false; | |
open_option_button.SetActive(true); | |
close_option_button.SetActive(false); | |
OPTION_UI.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment