ProjectSettings.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 BansheeEngine;
  6. namespace BansheeEditor
  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. /// Retrieves a generic floating point property.
  70. /// </summary>
  71. /// <param name="name">Name of the property to retrieve.</param>
  72. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  73. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  74. public static float GetFloat(string name, float defaultValue = 0.0f)
  75. {
  76. return Internal_GetFloat(name, defaultValue);
  77. }
  78. /// <summary>
  79. /// Retrieves a generic integer 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 int GetInt(string name, int defaultValue = 0)
  85. {
  86. return Internal_GetInt(name, defaultValue);
  87. }
  88. /// <summary>
  89. /// Retrieves a generic boolean 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 bool GetBool(string name, bool defaultValue = false)
  95. {
  96. return Internal_GetBool(name, defaultValue);
  97. }
  98. /// <summary>
  99. /// Retrieves a generic string 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 String GetString(string name, string defaultValue = "")
  105. {
  106. return Internal_GetString(name, defaultValue);
  107. }
  108. /// <summary>
  109. /// Checks does a generic property with the specified name exists.
  110. /// </summary>
  111. /// <param name="name">Name of the property to check.</param>
  112. /// <returns>True if the property exists, false otherwise.</returns>
  113. public static bool HasKey(string name)
  114. {
  115. return Internal_HasKey(name);
  116. }
  117. /// <summary>
  118. /// Deletes a generic property with the specified name.
  119. /// </summary>
  120. /// <param name="name">Name of the property to delete.</param>
  121. public static void DeleteKey(string name)
  122. {
  123. Internal_DeleteKey(name);
  124. }
  125. /// <summary>
  126. /// Deletes all generic properties.
  127. /// </summary>
  128. public static void DeleteAllKeys()
  129. {
  130. Internal_DeleteAllKeys();
  131. }
  132. /// <summary>
  133. /// Saves project settings to the disk.
  134. /// </summary>
  135. public static void Save()
  136. {
  137. Internal_Save();
  138. }
  139. [MethodImpl(MethodImplOptions.InternalCall)]
  140. private static extern string Internal_GetLastOpenScene();
  141. [MethodImpl(MethodImplOptions.InternalCall)]
  142. private static extern void Internal_SetLastOpenScene(string value);
  143. [MethodImpl(MethodImplOptions.InternalCall)]
  144. private static extern void Internal_SetFloat(string name, float value);
  145. [MethodImpl(MethodImplOptions.InternalCall)]
  146. private static extern void Internal_SetInt(string name, int value);
  147. [MethodImpl(MethodImplOptions.InternalCall)]
  148. private static extern void Internal_SetBool(string name, bool value);
  149. [MethodImpl(MethodImplOptions.InternalCall)]
  150. private static extern void Internal_SetString(string name, String value);
  151. [MethodImpl(MethodImplOptions.InternalCall)]
  152. private static extern float Internal_GetFloat(string name, float defaultValue);
  153. [MethodImpl(MethodImplOptions.InternalCall)]
  154. private static extern int Internal_GetInt(string name, int defaultValue);
  155. [MethodImpl(MethodImplOptions.InternalCall)]
  156. private static extern bool Internal_GetBool(string name, bool defaultValue);
  157. [MethodImpl(MethodImplOptions.InternalCall)]
  158. private static extern string Internal_GetString(string name, string defaultValue);
  159. [MethodImpl(MethodImplOptions.InternalCall)]
  160. private static extern bool Internal_HasKey(string name);
  161. [MethodImpl(MethodImplOptions.InternalCall)]
  162. private static extern void Internal_DeleteKey(string name);
  163. [MethodImpl(MethodImplOptions.InternalCall)]
  164. private static extern void Internal_DeleteAllKeys();
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern int Internal_GetHash();
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern void Internal_Save();
  169. }
  170. /** @} */
  171. }