SvrConfigOptions.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using UnityEngine;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. public class SvrConfigOptions
  5. {
  6. public static SvrConfigOptions Instance
  7. {
  8. get
  9. {
  10. if (instance == null)
  11. {
  12. instance = new SvrConfigOptions();
  13. }
  14. return instance;
  15. }
  16. }
  17. private static SvrConfigOptions instance;
  18. private static string optionsFileName = "config.txt";
  19. public bool FreezeAnimations { get; private set; }
  20. public float FreezeAnimationsAtTimeInSecs { get; private set; }
  21. public bool UseFixedViewport { get; private set; }
  22. public Vector3 FixedViewportPosition { get; private set; }
  23. public Vector3 FixedViewportEulerAnglesRotation { get; private set; }
  24. public int OverrideRenderTextureMSAA { get; private set; }
  25. public bool DisableAudio { get; private set; }
  26. public bool DisableParticles { get; private set; }
  27. public bool FoveationEnabled { get; private set; }
  28. public float FoveationArea { get; private set; }
  29. public Vector2 FoveationGain { get; private set; }
  30. public float FoveationMinimum { get; private set; }
  31. public bool FocusEnabled { get; private set; }
  32. public float FocusSpeed { get; private set; }
  33. public Vector2 FocusAmplitude { get; private set; }
  34. public Vector2 FocusFrequency { get; private set; }
  35. public bool? TrackEyesEnabled { get; private set; }
  36. public bool? TrackPositionEnabled { get; private set; }
  37. public bool? GazeReticleEnabled { get; private set; }
  38. public bool ThermalEnabled { get; private set; }
  39. public bool ThermalTouchTest { get; private set; }
  40. public List<string> ThermalStatesDefault { get; private set; }
  41. public List<string> CpuState0 { get; private set; }
  42. public List<string> CpuState1 { get; private set; }
  43. public List<string> CpuState2 { get; private set; }
  44. public List<string> CpuState3 { get; private set; }
  45. public List<string> CpuState4 { get; private set; }
  46. public List<string> GpuState0 { get; private set; }
  47. public List<string> GpuState1 { get; private set; }
  48. public List<string> GpuState2 { get; private set; }
  49. public List<string> GpuState3 { get; private set; }
  50. public List<string> GpuState4 { get; private set; }
  51. public List<string> SkinState0 { get; private set; }
  52. public List<string> SkinState1 { get; private set; }
  53. public List<string> SkinState2 { get; private set; }
  54. public List<string> SkinState3 { get; private set; }
  55. public List<string> SkinState4 { get; private set; }
  56. private string ConfigFilePath
  57. {
  58. get
  59. {
  60. string optionsFileFullPath = "";
  61. if (Application.platform == RuntimePlatform.WindowsEditor)
  62. {
  63. optionsFileFullPath = Application.dataPath + "/../etc/config";
  64. }
  65. else if (Application.platform == RuntimePlatform.Android)
  66. {
  67. optionsFileFullPath = Application.persistentDataPath;
  68. }
  69. optionsFileFullPath += "/" + optionsFileName;
  70. return optionsFileFullPath;
  71. }
  72. }
  73. private SvrConfigOptions()
  74. {
  75. Debug.Log("Looking for config file at: " + ConfigFilePath);
  76. ParseConfigFile(ConfigFilePath);
  77. }
  78. void ParseConfigFile(string path)
  79. {
  80. try
  81. {
  82. StreamReader sr = File.OpenText(path);
  83. Debug.Log("Config file found at: " + path);
  84. while (!sr.EndOfStream)
  85. {
  86. string line = sr.ReadLine();
  87. if (line.Length == 0)
  88. {
  89. continue;
  90. }
  91. line = line.Replace(" ", "");
  92. int commentStartIndex = line.LastIndexOf("//");
  93. line = commentStartIndex > -1 ? line.Replace(line.Substring(commentStartIndex), "") : line;
  94. if (string.IsNullOrEmpty(line))
  95. {
  96. continue;
  97. }
  98. string[] tokens = line.Split('=', ',');
  99. if (tokens.Length < 2)
  100. {
  101. Debug.LogError("line: " + line + "is invalid!");
  102. }
  103. switch (tokens[0])
  104. {
  105. case "FreezeAnimations":
  106. FreezeAnimations = bool.Parse(tokens[1]);
  107. break;
  108. case "FreezeAnimationsAtTimeInSecs":
  109. FreezeAnimationsAtTimeInSecs = float.Parse(tokens[1]);
  110. break;
  111. case "DisableParticles":
  112. DisableParticles = bool.Parse(tokens[1]);
  113. break;
  114. case "UseFixedViewport":
  115. UseFixedViewport = bool.Parse(tokens[1]);
  116. break;
  117. case "FixedViewportPosition":
  118. FixedViewportPosition = new Vector3( float.Parse(tokens[1]), float.Parse(tokens[2]), float.Parse(tokens[3]) );
  119. break;
  120. case "FixedViewportEulerAnglesRotation":
  121. FixedViewportEulerAnglesRotation = new Vector3(float.Parse(tokens[1]), float.Parse(tokens[2]), float.Parse(tokens[3]));
  122. break;
  123. case "OverrideRenderTextureMSAA":
  124. OverrideRenderTextureMSAA = int.Parse(tokens[1]);
  125. break;
  126. case "DisableAudio":
  127. DisableAudio = bool.Parse(tokens[1]);
  128. break;
  129. case "FoveationEnabled":
  130. FoveationEnabled = bool.Parse(tokens[1]);
  131. break;
  132. case "FoveationArea":
  133. FoveationArea = float.Parse(tokens[1]);
  134. break;
  135. case "FoveationGain":
  136. FoveationGain = new Vector2(float.Parse(tokens[1]), float.Parse(tokens[2]));
  137. break;
  138. case "FoveationMinimum":
  139. FoveationMinimum = float.Parse(tokens[1]);
  140. break;
  141. case "FocusEnabled":
  142. FocusEnabled = bool.Parse(tokens[1]);
  143. break;
  144. case "FocusSpeed":
  145. FocusSpeed = float.Parse(tokens[1]);
  146. break;
  147. case "FocusAmplitude":
  148. FocusAmplitude = new Vector2(float.Parse(tokens[1]), float.Parse(tokens[2]));
  149. break;
  150. case "FocusFrequency":
  151. FocusFrequency = new Vector2(float.Parse(tokens[1]), float.Parse(tokens[2]));
  152. break;
  153. case "TrackEyesEnabled":
  154. TrackEyesEnabled = bool.Parse(tokens[1]);
  155. break;
  156. case "TrackPositionEnabled":
  157. TrackPositionEnabled = bool.Parse(tokens[1]);
  158. break;
  159. case "GazeReticleEnabled":
  160. GazeReticleEnabled = bool.Parse(tokens[1]);
  161. break;
  162. case "ThermalEnabled":
  163. ThermalEnabled = bool.Parse(tokens[1]);
  164. break;
  165. case "ThermalTouchTest":
  166. ThermalTouchTest = bool.Parse(tokens[1]);
  167. break;
  168. case "ThermalStatesDefault":
  169. ThermalStatesDefault = new List<string>();
  170. for (int i = 1; i < tokens.Length; i++) ThermalStatesDefault.Add(tokens[i]);
  171. break;
  172. case "CpuState0":
  173. CpuState0 = new List<string>();
  174. for (int i = 1; i < tokens.Length; i++) CpuState0.Add(tokens[i]);
  175. break;
  176. case "CpuState1":
  177. CpuState1 = new List<string>();
  178. for (int i = 1; i < tokens.Length; i++) CpuState1.Add(tokens[i]);
  179. break;
  180. case "CpuState2":
  181. CpuState2 = new List<string>();
  182. for (int i = 1; i < tokens.Length; i++) CpuState2.Add(tokens[i]);
  183. break;
  184. case "CpuState3":
  185. CpuState3 = new List<string>();
  186. for (int i = 1; i < tokens.Length; i++) CpuState3.Add(tokens[i]);
  187. break;
  188. case "CpuState4":
  189. CpuState4 = new List<string>();
  190. for (int i = 1; i < tokens.Length; i++) CpuState4.Add(tokens[i]);
  191. break;
  192. case "GpuState0":
  193. GpuState0 = new List<string>();
  194. for (int i = 1; i < tokens.Length; i++) GpuState0.Add(tokens[i]);
  195. break;
  196. case "GpuState1":
  197. GpuState1 = new List<string>();
  198. for (int i = 1; i < tokens.Length; i++) GpuState1.Add(tokens[i]);
  199. break;
  200. case "GpuState2":
  201. GpuState2 = new List<string>();
  202. for (int i = 1; i < tokens.Length; i++) GpuState2.Add(tokens[i]);
  203. break;
  204. case "GpuState3":
  205. GpuState3 = new List<string>();
  206. for (int i = 1; i < tokens.Length; i++) GpuState3.Add(tokens[i]);
  207. break;
  208. case "GpuState4":
  209. GpuState4 = new List<string>();
  210. for (int i = 1; i < tokens.Length; i++) GpuState4.Add(tokens[i]);
  211. break;
  212. case "SkinState0":
  213. SkinState0 = new List<string>();
  214. for (int i = 1; i < tokens.Length; i++) SkinState0.Add(tokens[i]);
  215. break;
  216. case "SkinState1":
  217. SkinState1 = new List<string>();
  218. for (int i = 1; i < tokens.Length; i++) SkinState1.Add(tokens[i]);
  219. break;
  220. case "SkinState2":
  221. SkinState2 = new List<string>();
  222. for (int i = 1; i < tokens.Length; i++) SkinState2.Add(tokens[i]);
  223. break;
  224. case "SkinState3":
  225. SkinState3 = new List<string>();
  226. for (int i = 1; i < tokens.Length; i++) SkinState3.Add(tokens[i]);
  227. break;
  228. case "SkinState4":
  229. SkinState4 = new List<string>();
  230. for (int i = 1; i < tokens.Length; i++) SkinState4.Add(tokens[i]);
  231. break;
  232. default:
  233. Debug.LogError("Option: " + tokens[0] + " not supported!");
  234. break;
  235. }
  236. }
  237. }
  238. catch (System.Exception e)
  239. {
  240. Debug.Log(e.Message + "Using default values");
  241. }
  242. }
  243. }