2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.5 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace HTC.UnityPlugin.Vive
  7. {
  8. public class VIUProjectSettings : ScriptableObject, ISerializationCallbackReceiver
  9. {
  10. private const string DEFAULT_ASSET_PATH = "Assets/VIUSettings/Editor/Resources/VIUProjectSettings.asset";
  11. private const string DEFAULT_RESOURCES_PATH = "VIUProjectSettings";
  12. private static VIUProjectSettings s_instance = null;
  13. private static string s_defaultAssetPath;
  14. private static string s_partialActionDirPath;
  15. [SerializeField] private bool m_isInstallingWaveXRPlugin;
  16. [SerializeField] private bool m_isInstallingOpenVRXRPlugin;
  17. [SerializeField] private List<string> m_ignoreKeys;
  18. public bool isInstallingWaveXRPlugin
  19. {
  20. get
  21. {
  22. return m_isInstallingWaveXRPlugin;
  23. }
  24. set
  25. {
  26. m_isInstallingWaveXRPlugin = value;
  27. Save();
  28. }
  29. }
  30. public bool isInstallingOpenVRXRPlugin
  31. {
  32. get
  33. {
  34. return m_isInstallingOpenVRXRPlugin;
  35. }
  36. set
  37. {
  38. m_isInstallingOpenVRXRPlugin = value;
  39. Save();
  40. }
  41. }
  42. private HashSet<string> m_ignoreKeySet;
  43. private bool m_isDirty;
  44. public static VIUProjectSettings Instance
  45. {
  46. get
  47. {
  48. if (s_instance == null)
  49. {
  50. Load();
  51. }
  52. return s_instance;
  53. }
  54. }
  55. public static string defaultAssetPath
  56. {
  57. get
  58. {
  59. if (s_defaultAssetPath == null)
  60. {
  61. s_defaultAssetPath = DEFAULT_ASSET_PATH;
  62. }
  63. return s_defaultAssetPath;
  64. }
  65. }
  66. public static string partialActionDirPath
  67. {
  68. get
  69. {
  70. if (string.IsNullOrEmpty(s_partialActionDirPath))
  71. {
  72. MonoScript script = MonoScript.FromScriptableObject(Instance);
  73. string path = AssetDatabase.GetAssetPath(script);
  74. s_partialActionDirPath = Path.GetFullPath(Path.GetDirectoryName(path) + "/../Misc/SteamVRExtension/PartialInputBindings");
  75. }
  76. return s_partialActionDirPath;
  77. }
  78. }
  79. public static string partialActionFileName
  80. {
  81. get { return "actions.json"; }
  82. }
  83. public static bool hasChanged
  84. {
  85. get { return Instance.m_isDirty; }
  86. set { Instance.m_isDirty = value; }
  87. }
  88. public void OnBeforeSerialize()
  89. {
  90. if (m_isDirty)
  91. {
  92. if (m_ignoreKeySet != null && m_ignoreKeySet.Count > 0)
  93. {
  94. if (m_ignoreKeys == null) { m_ignoreKeys = new List<string>(); }
  95. m_ignoreKeys.Clear();
  96. m_ignoreKeys.AddRange(m_ignoreKeySet);
  97. }
  98. EditorUtility.SetDirty(this);
  99. m_isDirty = false;
  100. }
  101. }
  102. public void OnAfterDeserialize()
  103. {
  104. if (m_ignoreKeySet == null) { m_ignoreKeySet = new HashSet<string>(); }
  105. m_ignoreKeySet.Clear();
  106. if (m_ignoreKeys != null && m_ignoreKeys.Count > 0)
  107. {
  108. for (int i = 0, imax = m_ignoreKeys.Count; i < imax; ++i)
  109. {
  110. if (!string.IsNullOrEmpty(m_ignoreKeys[i]))
  111. {
  112. m_ignoreKeySet.Add(m_ignoreKeys[i]);
  113. }
  114. }
  115. }
  116. }
  117. private void OnDestroy()
  118. {
  119. if (s_instance == this)
  120. {
  121. s_instance = null;
  122. }
  123. }
  124. public static void Load(string path = null)
  125. {
  126. if (path == null)
  127. {
  128. path = DEFAULT_RESOURCES_PATH;
  129. }
  130. if ((s_instance = Resources.Load<VIUProjectSettings>(DEFAULT_RESOURCES_PATH)) == null)
  131. {
  132. s_instance = CreateInstance<VIUProjectSettings>();
  133. }
  134. }
  135. public static void Save(string path = null)
  136. {
  137. if (path == null)
  138. {
  139. path = AssetDatabase.GetAssetPath(Instance);
  140. }
  141. if (!string.IsNullOrEmpty(path))
  142. {
  143. return;
  144. }
  145. path = defaultAssetPath;
  146. Directory.CreateDirectory(Path.GetDirectoryName(path));
  147. AssetDatabase.CreateAsset(Instance, path);
  148. }
  149. public static bool AddIgnoreKey(string key)
  150. {
  151. if (Instance.m_ignoreKeySet == null) { Instance.m_ignoreKeySet = new HashSet<string>(); }
  152. var changed = Instance.m_ignoreKeySet.Add(key);
  153. if (changed) { Instance.m_isDirty = true; }
  154. return changed;
  155. }
  156. public static bool RemoveIgnoreKey(string key)
  157. {
  158. var changed = Instance.m_ignoreKeySet == null ? false : Instance.m_ignoreKeySet.Remove(key);
  159. if (changed) { Instance.m_isDirty = true; }
  160. return changed;
  161. }
  162. public static bool HasIgnoreKey(string key)
  163. {
  164. return Instance.m_ignoreKeySet == null ? false : Instance.m_ignoreKeySet.Contains(key);
  165. }
  166. }
  167. }