Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine.UI;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. public class ToggleSave : MonoBehaviour {
  7. public Toggle workingDay1;
  8. public OnChecmark wd1;
  9. public Toggle workingDay2;
  10. public OnChecmark wd2;
  11. public Toggle workingDay3;
  12. public OnChecmark wd3;
  13. public Toggle workingDay4;
  14. public OnChecmark wd4;
  15. public Toggle educationalDay1;
  16. public OnChecmark ed1;
  17. public Toggle educationalDay2;
  18. public OnChecmark ed2;
  19. public Toggle educationalDay3;
  20. public OnChecmark ed3;
  21. public Toggle educationalDay4;
  22. public OnChecmark ed4;
  23. public DayProccessor _proccessor;
  24. public GameObject go1;
  25. public GameObject go2;
  26. public GameObject go3;
  27. public GameObject go4;
  28. public GameObject go5;
  29. public GameObject go6;
  30. public GameObject go7;
  31. public GameObject go8;
  32. public GameObject go9;
  33. public bool _go1;
  34. public bool _go2;
  35. public bool _go3;
  36. public bool _go4;
  37. public bool _go5;
  38. public bool _go6;
  39. public bool _go7;
  40. public bool _go8;
  41. public bool _go9;
  42. void Start()
  43. {
  44. workingDay1 = workingDay1.GetComponent<Toggle>();
  45. workingDay2 = workingDay2.GetComponent<Toggle>();
  46. workingDay3 = workingDay3.GetComponent<Toggle>();
  47. workingDay4 = workingDay4.GetComponent<Toggle>();
  48. educationalDay1 = educationalDay1.GetComponent<Toggle>();
  49. educationalDay2 = educationalDay2.GetComponent<Toggle>();
  50. educationalDay3 = educationalDay3.GetComponent<Toggle>();
  51. educationalDay4 = educationalDay4.GetComponent<Toggle>();
  52. _go1 = _go2 = _go3 = _go4 = _go5 = _go6 = _go7 = _go8 = false;
  53. }
  54. void Update()
  55. {
  56. _go1 = go1.activeSelf;
  57. _go2 = go2.activeSelf;
  58. _go3 = go3.activeSelf;
  59. _go4 = go4.activeSelf;
  60. _go5 = go5.activeSelf;
  61. _go6 = go6.activeSelf;
  62. _go7 = go7.activeSelf;
  63. _go8 = go8.activeSelf;
  64. _go9 = go9.activeSelf;
  65. if (_go9 == true)
  66. {
  67. if (_go1 == true)
  68. {
  69. workingDay1.isOn = true;
  70. }
  71. else if (_go1 == false)
  72. {
  73. workingDay1.isOn = false;
  74. }
  75. if (_go2 == true)
  76. {
  77. workingDay2.isOn = true;
  78. }
  79. else if (_go2 == false)
  80. {
  81. workingDay2.isOn = false;
  82. }
  83. if (_go3 == true)
  84. {
  85. workingDay3.isOn = true;
  86. }
  87. else if (_go3 == false)
  88. {
  89. workingDay3.isOn = false;
  90. }
  91. if (_go4 == true)
  92. {
  93. workingDay4.isOn = true;
  94. }
  95. else if (_go4 == false)
  96. {
  97. workingDay4.isOn = false;
  98. }
  99. if (_go5 == true)
  100. {
  101. educationalDay1.isOn = true;
  102. }
  103. else if (_go5 == false)
  104. {
  105. educationalDay1.isOn = false;
  106. }
  107. if (_go6 == true)
  108. {
  109. educationalDay2.isOn = true;
  110. }
  111. else if (_go6 == false)
  112. {
  113. educationalDay2.isOn = false;
  114. }
  115. if (_go7 == true)
  116. {
  117. educationalDay3.isOn = true;
  118. }
  119. else if (_go7 == false)
  120. {
  121. educationalDay3.isOn = false;
  122. }
  123. if (_go8 == true)
  124. {
  125. educationalDay4.isOn = true;
  126. }
  127. else if (_go8 == false)
  128. {
  129. educationalDay4.isOn = false;
  130. }
  131. }
  132. }
  133. [System.Serializable]
  134. public class Bool
  135. {
  136. public bool _wd1;
  137. public bool _wd2;
  138. public bool _wd3;
  139. public bool _wd4;
  140. public bool _ed1;
  141. public bool _ed2;
  142. public bool _ed3;
  143. public bool _ed4;
  144. public bool _9;
  145. }
  146. public void SaveGraph()
  147. {
  148. Bool state = new Bool();
  149. state._wd1 = workingDay1;
  150. state._wd2 = workingDay2;
  151. state._wd3 = workingDay3;
  152. state._wd4 = workingDay4;
  153. state._ed1 = educationalDay1;
  154. state._ed2 = educationalDay2;
  155. state._ed3 = educationalDay3;
  156. state._ed4 = educationalDay4;
  157. state._9 = _go9;
  158. if (!Directory.Exists(Application.dataPath + "/saves"))
  159. Directory.CreateDirectory(Application.dataPath + "/saves");
  160. FileStream fs3 = new FileStream(Application.dataPath + "/saves/saveg.lg", FileMode.Create);
  161. BinaryFormatter formatter = new BinaryFormatter();
  162. formatter.Serialize(fs3, state);
  163. fs3.Close();
  164. }
  165. public void LoadGraph()
  166. {
  167. if (_go9 == true)
  168. {
  169. if (File.Exists(Application.dataPath + "/saves/saveg.lg"))
  170. {
  171. FileStream fs3 = new FileStream(Application.dataPath + "/saves/saveg.lg", FileMode.Open);
  172. BinaryFormatter formatter = new BinaryFormatter();
  173. try
  174. {
  175. Bool state = (Bool)formatter.Deserialize(fs3);
  176. go1.SetActive(state._wd1);
  177. go2.SetActive(state._wd2);
  178. go3.SetActive(state._wd3);
  179. go4.SetActive(state._wd4);
  180. go5.SetActive(state._ed1);
  181. go6.SetActive(state._ed2);
  182. go7.SetActive(state._ed3);
  183. go8.SetActive(state._ed4);
  184. go9.SetActive(state._9);
  185. }
  186. catch (System.Exception)
  187. {
  188.  
  189. }
  190. finally
  191. {
  192. fs3.Close();
  193. }
  194. }
  195. else
  196. {
  197. Application.Quit();
  198. }
  199. }
  200.  
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement