Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using UnityEngine.UI;
- using System.Runtime.Serialization.Formatters.Binary;
- public class ToggleSave : MonoBehaviour {
- public Toggle workingDay1;
- public OnChecmark wd1;
- public Toggle workingDay2;
- public OnChecmark wd2;
- public Toggle workingDay3;
- public OnChecmark wd3;
- public Toggle workingDay4;
- public OnChecmark wd4;
- public Toggle educationalDay1;
- public OnChecmark ed1;
- public Toggle educationalDay2;
- public OnChecmark ed2;
- public Toggle educationalDay3;
- public OnChecmark ed3;
- public Toggle educationalDay4;
- public OnChecmark ed4;
- public DayProccessor _proccessor;
- public GameObject go1;
- public GameObject go2;
- public GameObject go3;
- public GameObject go4;
- public GameObject go5;
- public GameObject go6;
- public GameObject go7;
- public GameObject go8;
- public GameObject go9;
- public bool _go1;
- public bool _go2;
- public bool _go3;
- public bool _go4;
- public bool _go5;
- public bool _go6;
- public bool _go7;
- public bool _go8;
- public bool _go9;
- void Start()
- {
- workingDay1 = workingDay1.GetComponent<Toggle>();
- workingDay2 = workingDay2.GetComponent<Toggle>();
- workingDay3 = workingDay3.GetComponent<Toggle>();
- workingDay4 = workingDay4.GetComponent<Toggle>();
- educationalDay1 = educationalDay1.GetComponent<Toggle>();
- educationalDay2 = educationalDay2.GetComponent<Toggle>();
- educationalDay3 = educationalDay3.GetComponent<Toggle>();
- educationalDay4 = educationalDay4.GetComponent<Toggle>();
- _go1 = _go2 = _go3 = _go4 = _go5 = _go6 = _go7 = _go8 = false;
- }
- void Update()
- {
- _go1 = go1.activeSelf;
- _go2 = go2.activeSelf;
- _go3 = go3.activeSelf;
- _go4 = go4.activeSelf;
- _go5 = go5.activeSelf;
- _go6 = go6.activeSelf;
- _go7 = go7.activeSelf;
- _go8 = go8.activeSelf;
- _go9 = go9.activeSelf;
- if (_go9 == true)
- {
- if (_go1 == true)
- {
- workingDay1.isOn = true;
- }
- else if (_go1 == false)
- {
- workingDay1.isOn = false;
- }
- if (_go2 == true)
- {
- workingDay2.isOn = true;
- }
- else if (_go2 == false)
- {
- workingDay2.isOn = false;
- }
- if (_go3 == true)
- {
- workingDay3.isOn = true;
- }
- else if (_go3 == false)
- {
- workingDay3.isOn = false;
- }
- if (_go4 == true)
- {
- workingDay4.isOn = true;
- }
- else if (_go4 == false)
- {
- workingDay4.isOn = false;
- }
- if (_go5 == true)
- {
- educationalDay1.isOn = true;
- }
- else if (_go5 == false)
- {
- educationalDay1.isOn = false;
- }
- if (_go6 == true)
- {
- educationalDay2.isOn = true;
- }
- else if (_go6 == false)
- {
- educationalDay2.isOn = false;
- }
- if (_go7 == true)
- {
- educationalDay3.isOn = true;
- }
- else if (_go7 == false)
- {
- educationalDay3.isOn = false;
- }
- if (_go8 == true)
- {
- educationalDay4.isOn = true;
- }
- else if (_go8 == false)
- {
- educationalDay4.isOn = false;
- }
- }
- }
- [System.Serializable]
- public class Bool
- {
- public bool _wd1;
- public bool _wd2;
- public bool _wd3;
- public bool _wd4;
- public bool _ed1;
- public bool _ed2;
- public bool _ed3;
- public bool _ed4;
- public bool _9;
- }
- public void SaveGraph()
- {
- Bool state = new Bool();
- state._wd1 = workingDay1;
- state._wd2 = workingDay2;
- state._wd3 = workingDay3;
- state._wd4 = workingDay4;
- state._ed1 = educationalDay1;
- state._ed2 = educationalDay2;
- state._ed3 = educationalDay3;
- state._ed4 = educationalDay4;
- state._9 = _go9;
- if (!Directory.Exists(Application.dataPath + "/saves"))
- Directory.CreateDirectory(Application.dataPath + "/saves");
- FileStream fs3 = new FileStream(Application.dataPath + "/saves/saveg.lg", FileMode.Create);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(fs3, state);
- fs3.Close();
- }
- public void LoadGraph()
- {
- if (_go9 == true)
- {
- if (File.Exists(Application.dataPath + "/saves/saveg.lg"))
- {
- FileStream fs3 = new FileStream(Application.dataPath + "/saves/saveg.lg", FileMode.Open);
- BinaryFormatter formatter = new BinaryFormatter();
- try
- {
- Bool state = (Bool)formatter.Deserialize(fs3);
- go1.SetActive(state._wd1);
- go2.SetActive(state._wd2);
- go3.SetActive(state._wd3);
- go4.SetActive(state._wd4);
- go5.SetActive(state._ed1);
- go6.SetActive(state._ed2);
- go7.SetActive(state._ed3);
- go8.SetActive(state._ed4);
- go9.SetActive(state._9);
- }
- catch (System.Exception)
- {
- }
- finally
- {
- fs3.Close();
- }
- }
- else
- {
- Application.Quit();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement