ProjectSettings.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using BansheeEngine;
  10. namespace BansheeEditor
  11. {
  12. /// <summary>
  13. /// Contains various settings that are applied globally per project. Settings will persist through editor sessions.
  14. /// </summary>
  15. internal static class ProjectSettings
  16. {
  17. /// <summary>
  18. /// Contains the path to the last open scene. Path is relative to the project's resources folder.
  19. /// </summary>
  20. public static string LastOpenScene
  21. {
  22. get { return Internal_GetLastOpenScene(); }
  23. set { Internal_SetLastOpenScene(value); }
  24. }
  25. /// <summary>
  26. /// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
  27. /// external systems to track when they might need to reload the settings.
  28. /// </summary>
  29. public static int Hash
  30. {
  31. get { return Internal_GetHash(); }
  32. }
  33. /// <summary>
  34. /// Sets a generic floating point property.
  35. /// </summary>
  36. /// <param name="name">Name to record the property under.</param>
  37. /// <param name="value">Value of the property.</param>
  38. public static void SetFloat(string name, float value)
  39. {
  40. Internal_SetFloat(name, value);
  41. }
  42. /// <summary>
  43. /// Sets a generic integer property.
  44. /// </summary>
  45. /// <param name="name">Name to record the property under.</param>
  46. /// <param name="value">Value of the property.</param>
  47. public static void SetInt(string name, int value)
  48. {
  49. Internal_SetInt(name, value);
  50. }
  51. /// <summary>
  52. /// Sets a generic boolean property.
  53. /// </summary>
  54. /// <param name="name">Name to record the property under.</param>
  55. /// <param name="value">Value of the property.</param>
  56. public static void SetBool(string name, bool value)
  57. {
  58. Internal_SetBool(name, value);
  59. }
  60. /// <summary>
  61. /// Sets a generic string property.
  62. /// </summary>
  63. /// <param name="name">Name to record the property under.</param>
  64. /// <param name="value">Value of the property.</param>
  65. public static void SetString(string name, String value)
  66. {
  67. Internal_SetString(name, value);
  68. }
  69. /// <summary>
  70. /// Retrieves a generic floating point property.
  71. /// </summary>
  72. /// <param name="name">Name of the property to retrieve.</param>
  73. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  74. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  75. public static float GetFloat(string name, float defaultValue = 0.0f)
  76. {
  77. return Internal_GetFloat(name, defaultValue);
  78. }
  79. /// <summary>
  80. /// Retrieves a generic integer property.
  81. /// </summary>
  82. /// <param name="name">Name of the property to retrieve.</param>
  83. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  84. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  85. public static int GetInt(string name, int defaultValue = 0)
  86. {
  87. return Internal_GetInt(name, defaultValue);
  88. }
  89. /// <summary>
  90. /// Retrieves a generic boolean property.
  91. /// </summary>
  92. /// <param name="name">Name of the property to retrieve.</param>
  93. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  94. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  95. public static bool GetBool(string name, bool defaultValue = false)
  96. {
  97. return Internal_GetBool(name, defaultValue);
  98. }
  99. /// <summary>
  100. /// Retrieves a generic string property.
  101. /// </summary>
  102. /// <param name="name">Name of the property to retrieve.</param>
  103. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  104. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  105. public static String GetString(string name, string defaultValue = "")
  106. {
  107. return Internal_GetString(name, defaultValue);
  108. }
  109. /// <summary>
  110. /// Checks does a generic property with the specified name exists.
  111. /// </summary>
  112. /// <param name="name">Name of the property to check.</param>
  113. /// <returns>True if the property exists, false otherwise.</returns>
  114. public static bool HasKey(string name)
  115. {
  116. return Internal_HasKey(name);
  117. }
  118. /// <summary>
  119. /// Deletes a generic property with the specified name.
  120. /// </summary>
  121. /// <param name="name">Name of the property to delete.</param>
  122. public static void DeleteKey(string name)
  123. {
  124. Internal_DeleteKey(name);
  125. }
  126. /// <summary>
  127. /// Deletes all generic properties.
  128. /// </summary>
  129. public static void DeleteAllKeys()
  130. {
  131. Internal_DeleteAllKeys();
  132. }
  133. /// <summary>
  134. /// Saves project settings to the disk.
  135. /// </summary>
  136. public static void Save()
  137. {
  138. Internal_Save();
  139. }
  140. [MethodImpl(MethodImplOptions.InternalCall)]
  141. private static extern string Internal_GetLastOpenScene();
  142. [MethodImpl(MethodImplOptions.InternalCall)]
  143. private static extern void Internal_SetLastOpenScene(string value);
  144. [MethodImpl(MethodImplOptions.InternalCall)]
  145. private static extern void Internal_SetFloat(string name, float value);
  146. [MethodImpl(MethodImplOptions.InternalCall)]
  147. private static extern void Internal_SetInt(string name, int value);
  148. [MethodImpl(MethodImplOptions.InternalCall)]
  149. private static extern void Internal_SetBool(string name, bool value);
  150. [MethodImpl(MethodImplOptions.InternalCall)]
  151. private static extern void Internal_SetString(string name, String value);
  152. [MethodImpl(MethodImplOptions.InternalCall)]
  153. private static extern float Internal_GetFloat(string name, float defaultValue);
  154. [MethodImpl(MethodImplOptions.InternalCall)]
  155. private static extern int Internal_GetInt(string name, int defaultValue);
  156. [MethodImpl(MethodImplOptions.InternalCall)]
  157. private static extern bool Internal_GetBool(string name, bool defaultValue);
  158. [MethodImpl(MethodImplOptions.InternalCall)]
  159. private static extern string Internal_GetString(string name, string defaultValue);
  160. [MethodImpl(MethodImplOptions.InternalCall)]
  161. private static extern bool Internal_HasKey(string name);
  162. [MethodImpl(MethodImplOptions.InternalCall)]
  163. private static extern void Internal_DeleteKey(string name);
  164. [MethodImpl(MethodImplOptions.InternalCall)]
  165. private static extern void Internal_DeleteAllKeys();
  166. [MethodImpl(MethodImplOptions.InternalCall)]
  167. private static extern int Internal_GetHash();
  168. [MethodImpl(MethodImplOptions.InternalCall)]
  169. private static extern void Internal_Save();
  170. }
  171. }