ProjectSettings.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using bs;
  6. namespace bs.Editor
  7. {
  8. /** @addtogroup Settings
  9. * @{
  10. */
  11. /// <summary>
  12. /// Contains various settings that are applied globally per project. Settings will persist through editor sessions.
  13. /// </summary>
  14. internal static class ProjectSettings
  15. {
  16. /// <summary>
  17. /// Contains the path to the last open scene. Path is relative to the project's resources folder.
  18. /// </summary>
  19. public static string LastOpenScene
  20. {
  21. get { return Internal_GetLastOpenScene(); }
  22. set { Internal_SetLastOpenScene(value); }
  23. }
  24. /// <summary>
  25. /// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
  26. /// external systems to track when they might need to reload the settings.
  27. /// </summary>
  28. public static int Hash
  29. {
  30. get { return Internal_GetHash(); }
  31. }
  32. /// <summary>
  33. /// Sets a generic floating point property.
  34. /// </summary>
  35. /// <param name="name">Name to record the property under.</param>
  36. /// <param name="value">Value of the property.</param>
  37. public static void SetFloat(string name, float value)
  38. {
  39. Internal_SetFloat(name, value);
  40. }
  41. /// <summary>
  42. /// Sets a generic integer property.
  43. /// </summary>
  44. /// <param name="name">Name to record the property under.</param>
  45. /// <param name="value">Value of the property.</param>
  46. public static void SetInt(string name, int value)
  47. {
  48. Internal_SetInt(name, value);
  49. }
  50. /// <summary>
  51. /// Sets a generic boolean property.
  52. /// </summary>
  53. /// <param name="name">Name to record the property under.</param>
  54. /// <param name="value">Value of the property.</param>
  55. public static void SetBool(string name, bool value)
  56. {
  57. Internal_SetBool(name, value);
  58. }
  59. /// <summary>
  60. /// Sets a generic string property.
  61. /// </summary>
  62. /// <param name="name">Name to record the property under.</param>
  63. /// <param name="value">Value of the property.</param>
  64. public static void SetString(string name, String value)
  65. {
  66. Internal_SetString(name, value);
  67. }
  68. /// <summary>
  69. /// Sets a generic object property. Any object marked with <see cref="SerializeObject"/> attribute can be provided,
  70. /// excluding components and resources.
  71. /// </summary>
  72. /// <param name="name">Name to record the property under.</param>
  73. /// <param name="value">Value of the property.</param>
  74. public static void SetObject(string name, object value)
  75. {
  76. Internal_SetObject(name, value);
  77. }
  78. /// <summary>
  79. /// Retrieves a generic floating point property.
  80. /// </summary>
  81. /// <param name="name">Name of the property to retrieve.</param>
  82. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  83. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  84. public static float GetFloat(string name, float defaultValue = 0.0f)
  85. {
  86. return Internal_GetFloat(name, defaultValue);
  87. }
  88. /// <summary>
  89. /// Retrieves a generic integer property.
  90. /// </summary>
  91. /// <param name="name">Name of the property to retrieve.</param>
  92. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  93. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  94. public static int GetInt(string name, int defaultValue = 0)
  95. {
  96. return Internal_GetInt(name, defaultValue);
  97. }
  98. /// <summary>
  99. /// Retrieves a generic boolean property.
  100. /// </summary>
  101. /// <param name="name">Name of the property to retrieve.</param>
  102. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  103. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  104. public static bool GetBool(string name, bool defaultValue = false)
  105. {
  106. return Internal_GetBool(name, defaultValue);
  107. }
  108. /// <summary>
  109. /// Retrieves a generic string property.
  110. /// </summary>
  111. /// <param name="name">Name of the property to retrieve.</param>
  112. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  113. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  114. public static string GetString(string name, string defaultValue = "")
  115. {
  116. return Internal_GetString(name, defaultValue);
  117. }
  118. /// <summary>
  119. /// Retrieves a generic object property.
  120. /// </summary>
  121. /// <param name="name">Name of the property to retrieve.</param>
  122. /// <returns>
  123. /// Value of the property if it exists, otherwise an empty instance of the object. Returns null if the tyoe of
  124. /// the stored object doesn't match the requested type.
  125. /// </returns>
  126. public static T GetObject<T>(string name) where T : class, new()
  127. {
  128. object obj = Internal_GetObject(name);
  129. if (obj == null)
  130. return new T();
  131. return obj as T;
  132. }
  133. /// <summary>
  134. /// Checks does a generic property with the specified name exists.
  135. /// </summary>
  136. /// <param name="name">Name of the property to check.</param>
  137. /// <returns>True if the property exists, false otherwise.</returns>
  138. public static bool HasKey(string name)
  139. {
  140. return Internal_HasKey(name);
  141. }
  142. /// <summary>
  143. /// Deletes a generic property with the specified name.
  144. /// </summary>
  145. /// <param name="name">Name of the property to delete.</param>
  146. public static void DeleteKey(string name)
  147. {
  148. Internal_DeleteKey(name);
  149. }
  150. /// <summary>
  151. /// Deletes all generic properties.
  152. /// </summary>
  153. public static void DeleteAllKeys()
  154. {
  155. Internal_DeleteAllKeys();
  156. }
  157. /// <summary>
  158. /// Saves project settings to the disk.
  159. /// </summary>
  160. public static void Save()
  161. {
  162. Internal_Save();
  163. }
  164. [MethodImpl(MethodImplOptions.InternalCall)]
  165. private static extern string Internal_GetLastOpenScene();
  166. [MethodImpl(MethodImplOptions.InternalCall)]
  167. private static extern void Internal_SetLastOpenScene(string value);
  168. [MethodImpl(MethodImplOptions.InternalCall)]
  169. private static extern void Internal_SetFloat(string name, float value);
  170. [MethodImpl(MethodImplOptions.InternalCall)]
  171. private static extern void Internal_SetInt(string name, int value);
  172. [MethodImpl(MethodImplOptions.InternalCall)]
  173. private static extern void Internal_SetBool(string name, bool value);
  174. [MethodImpl(MethodImplOptions.InternalCall)]
  175. private static extern void Internal_SetString(string name, string value);
  176. [MethodImpl(MethodImplOptions.InternalCall)]
  177. private static extern void Internal_SetObject(string name, object value);
  178. [MethodImpl(MethodImplOptions.InternalCall)]
  179. private static extern float Internal_GetFloat(string name, float defaultValue);
  180. [MethodImpl(MethodImplOptions.InternalCall)]
  181. private static extern int Internal_GetInt(string name, int defaultValue);
  182. [MethodImpl(MethodImplOptions.InternalCall)]
  183. private static extern bool Internal_GetBool(string name, bool defaultValue);
  184. [MethodImpl(MethodImplOptions.InternalCall)]
  185. private static extern string Internal_GetString(string name, string defaultValue);
  186. [MethodImpl(MethodImplOptions.InternalCall)]
  187. private static extern object Internal_GetObject(string name);
  188. [MethodImpl(MethodImplOptions.InternalCall)]
  189. private static extern bool Internal_HasKey(string name);
  190. [MethodImpl(MethodImplOptions.InternalCall)]
  191. private static extern void Internal_DeleteKey(string name);
  192. [MethodImpl(MethodImplOptions.InternalCall)]
  193. private static extern void Internal_DeleteAllKeys();
  194. [MethodImpl(MethodImplOptions.InternalCall)]
  195. private static extern int Internal_GetHash();
  196. [MethodImpl(MethodImplOptions.InternalCall)]
  197. private static extern void Internal_Save();
  198. }
  199. /** @} */
  200. }