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