BuildManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Contains a list of valid platforms that can be built for.
  8. /// </summary>
  9. public enum PlatformType // Note: Must match C++ enum PlatformType
  10. {
  11. Windows,
  12. Count // Keep at end
  13. }
  14. /// <summary>
  15. /// Contains build data for a specific platform.
  16. /// </summary>
  17. public abstract class PlatformInfo : ScriptObject
  18. {
  19. /// <summary>
  20. /// Creates a new platform info. For internal runtime use only.
  21. /// </summary>
  22. protected PlatformInfo()
  23. { }
  24. /// <summary>
  25. /// Returns the platform that this object contains data for.
  26. /// </summary>
  27. public PlatformType Type
  28. {
  29. get { return Internal_GetType(mCachedPtr); }
  30. }
  31. /// <summary>
  32. /// Initial scene that is loaded when application is first started.
  33. /// </summary>
  34. public Prefab MainScene
  35. {
  36. get { return Internal_GetMainScene(mCachedPtr); }
  37. set
  38. {
  39. IntPtr scenePtr = IntPtr.Zero;
  40. if (value != null)
  41. scenePtr = value.GetCachedPtr();
  42. Internal_SetMainScene(mCachedPtr, scenePtr);
  43. }
  44. }
  45. /// <summary>
  46. /// Determines should the application be started in fullscreen using the user's desktop resolution.
  47. /// </summary>
  48. public bool Fullscreen
  49. {
  50. get { return Internal_GetFullscreen(mCachedPtr); }
  51. set { Internal_SetFullscreen(mCachedPtr, value); }
  52. }
  53. /// <summary>
  54. /// Width of a window if the game is started in windowed mode. This is only relevant if <see cref="Fullscreen"/>
  55. /// is off.
  56. /// </summary>
  57. public int WindowedWidth
  58. {
  59. get
  60. {
  61. int width, height;
  62. Internal_GetResolution(mCachedPtr, out width, out height);
  63. return width;
  64. }
  65. set { Internal_SetResolution(mCachedPtr, value, WindowedHeight); }
  66. }
  67. /// <summary>
  68. /// Height of a window if the game is started in windowed mode. This is only relevant if <see cref="Fullscreen"/>
  69. /// is off.
  70. /// </summary>
  71. public int WindowedHeight
  72. {
  73. get
  74. {
  75. int width, height;
  76. Internal_GetResolution(mCachedPtr, out width, out height);
  77. return height;
  78. }
  79. set { Internal_SetResolution(mCachedPtr, WindowedWidth, value); }
  80. }
  81. /// <summary>
  82. /// A set of semicolon separated defines to use when compiling scripts for this platform.
  83. /// </summary>
  84. public string Defines
  85. {
  86. get { return Internal_GetDefines(mCachedPtr); }
  87. set { Internal_SetDefines(mCachedPtr, value); }
  88. }
  89. [MethodImpl(MethodImplOptions.InternalCall)]
  90. private static extern PlatformType Internal_GetType(IntPtr thisPtr);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. private static extern string Internal_GetDefines(IntPtr thisPtr);
  93. [MethodImpl(MethodImplOptions.InternalCall)]
  94. private static extern void Internal_SetDefines(IntPtr thisPtr, string value);
  95. [MethodImpl(MethodImplOptions.InternalCall)]
  96. private static extern Prefab Internal_GetMainScene(IntPtr thisPtr);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. static extern void Internal_SetMainScene(IntPtr thisPtr, IntPtr prefabPtr);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. static extern bool Internal_GetFullscreen(IntPtr thisPtr);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. static extern void Internal_SetFullscreen(IntPtr thisPtr, bool fullscreen);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. static extern void Internal_GetResolution(IntPtr thisPtr, out int width, out int height);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. static extern void Internal_SetResolution(IntPtr thisPtr, int width, int height);
  107. }
  108. /// <summary>
  109. /// Supported icon sizes for Windows platform.
  110. /// </summary>
  111. public enum WinIconSizes
  112. {
  113. Icon16 = 16,
  114. Icon32 = 32,
  115. Icon48 = 48,
  116. Icon64 = 64,
  117. Icon96 = 96,
  118. Icon128 = 128,
  119. Icon196 = 196,
  120. Icon256 = 256
  121. }
  122. /// <summary>
  123. /// Platform data specific to Windows.
  124. /// </summary>
  125. public class WinPlatformInfo : PlatformInfo
  126. {
  127. /// <summary>
  128. /// Texture that will be displayed in the taskbar when the application is running.
  129. /// </summary>
  130. public Texture2D TaskbarIcon
  131. {
  132. get { return Internal_GetTaskbarIcon(mCachedPtr); }
  133. set
  134. {
  135. IntPtr texturePtr = IntPtr.Zero;
  136. if (value != null)
  137. texturePtr = value.GetCachedPtr();
  138. Internal_SetTaskbarIcon(mCachedPtr, texturePtr);
  139. }
  140. }
  141. /// <summary>
  142. /// Text that will be displayed in the application's title bar.
  143. /// </summary>
  144. public string TitleText
  145. {
  146. get { return Internal_GetTitleText(mCachedPtr); }
  147. set { Internal_SetTitleText(mCachedPtr, value); }
  148. }
  149. /// <summary>
  150. /// Returns a texture of a specific icon size that will be added to the executable.
  151. /// </summary>
  152. /// <param name="size">Type of icon to retrieve the texture for.</param>
  153. /// <returns>Texture for the specified icon size.</returns>
  154. public Texture2D GetIcon(WinIconSizes size)
  155. {
  156. return Internal_GetIcon(mCachedPtr, (int)size);
  157. }
  158. /// <summary>
  159. /// Sets a texture of a specific icon size that will be added to the executable.
  160. /// </summary>
  161. /// <param name="size">Type of icon to set the texture for.</param>
  162. /// <param name="texture">Texture for the specified icon size.</param>
  163. public void SetIcon(WinIconSizes size, Texture2D texture)
  164. {
  165. IntPtr texturePtr = IntPtr.Zero;
  166. if (texture != null)
  167. texturePtr = texture.GetCachedPtr();
  168. Internal_SetIcon(mCachedPtr, (int)size, texturePtr);
  169. }
  170. [MethodImpl(MethodImplOptions.InternalCall)]
  171. private static extern Texture2D Internal_GetIcon(IntPtr thisPtr, int size);
  172. [MethodImpl(MethodImplOptions.InternalCall)]
  173. private static extern void Internal_SetIcon(IntPtr thisPtr, int size, IntPtr texturePtr);
  174. [MethodImpl(MethodImplOptions.InternalCall)]
  175. private static extern Texture2D Internal_GetTaskbarIcon(IntPtr thisPtr);
  176. [MethodImpl(MethodImplOptions.InternalCall)]
  177. private static extern void Internal_SetTaskbarIcon(IntPtr thisPtr, IntPtr texturePtr);
  178. [MethodImpl(MethodImplOptions.InternalCall)]
  179. private static extern string Internal_GetTitleText(IntPtr thisPtr);
  180. [MethodImpl(MethodImplOptions.InternalCall)]
  181. private static extern void Internal_SetTitleText(IntPtr thisPtr, string value);
  182. }
  183. /// <summary>
  184. /// Handles building of the game executable and packaging of all necessary resources, making the game be ready to ran
  185. /// as a standalone product.
  186. /// </summary>
  187. public static class BuildManager
  188. {
  189. /// <summary>
  190. /// Returns a list of all available platforms that can be built for.
  191. /// </summary>
  192. public static PlatformType[] AvailablePlatforms
  193. {
  194. get { return Internal_GetAvailablePlatforms(); }
  195. }
  196. /// <summary>
  197. /// Returns the currently active platform.
  198. /// </summary>
  199. public static PlatformType ActivePlatform
  200. {
  201. get { return Internal_GetActivePlatform(); }
  202. set { Internal_SetActivePlatform(value); }
  203. }
  204. /// <summary>
  205. /// Returns the data about the currently active platform.
  206. /// </summary>
  207. public static PlatformInfo ActivePlatformInfo
  208. {
  209. get { return Internal_GetActivePlatformInfo(); }
  210. }
  211. /// <summary>
  212. /// Builds the executable and packages the game.
  213. /// </summary>
  214. public static void Build()
  215. {
  216. // TODO
  217. }
  218. /// <summary>
  219. /// Returns a list of .NET framework managed assemblies to be included for the specified platform.
  220. /// </summary>
  221. /// <param name="type">Platform type to retrieve the list of assemblies for.</param>
  222. /// <returns>A list of .NET framework managed assemblies that will be included with the build.</returns>
  223. internal static string[] GetFrameworkAssemblies(PlatformType type)
  224. {
  225. return Internal_GetFrameworkAssemblies(type);
  226. }
  227. /// <summary>
  228. /// Returns the location of the executable for the provided platform.
  229. /// </summary>
  230. /// <param name="type">Platform type to retrieve the executable location for.</param>
  231. /// <returns>Path to the executable in the editor install folder.</returns>
  232. internal static string GetMainExecutable(PlatformType type)
  233. {
  234. return Internal_GetMainExecutable(type);
  235. }
  236. /// <summary>
  237. /// Returns a list of semicolon separated defines that will be used when compiling scripts for the specified
  238. /// platform.
  239. /// </summary>
  240. /// <param name="type">Platfrom type to retrieve the defines for.</param>
  241. /// <returns>Semicolor separated defines that will be passed along to the script compiler.</returns>
  242. internal static string GetDefines(PlatformType type)
  243. {
  244. return Internal_GetDefines(type);
  245. }
  246. /// <summary>
  247. /// Returns an object containing all platform specific build data.
  248. /// </summary>
  249. /// <param name="type">Platform type to retrieve the data for.</param>
  250. /// <returns>An object containing all platform specific build data</returns>
  251. internal static PlatformInfo GetPlatformInfo(PlatformType type)
  252. {
  253. return Internal_GetPlatformInfo(type);
  254. }
  255. [MethodImpl(MethodImplOptions.InternalCall)]
  256. private static extern PlatformType[] Internal_GetAvailablePlatforms();
  257. [MethodImpl(MethodImplOptions.InternalCall)]
  258. private static extern PlatformType Internal_GetActivePlatform();
  259. [MethodImpl(MethodImplOptions.InternalCall)]
  260. private static extern void Internal_SetActivePlatform(PlatformType value);
  261. [MethodImpl(MethodImplOptions.InternalCall)]
  262. private static extern PlatformInfo Internal_GetActivePlatformInfo();
  263. [MethodImpl(MethodImplOptions.InternalCall)]
  264. private static extern PlatformInfo Internal_GetPlatformInfo(PlatformType type);
  265. [MethodImpl(MethodImplOptions.InternalCall)]
  266. private static extern string[] Internal_GetFrameworkAssemblies(PlatformType type);
  267. [MethodImpl(MethodImplOptions.InternalCall)]
  268. private static extern string Internal_GetMainExecutable(PlatformType type);
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern string Internal_GetDefines(PlatformType type);
  271. }
  272. }