ApplicationOptions.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. namespace Urho
  5. {
  6. /// <summary>
  7. /// Application options, see full description at:
  8. /// http://urho3d.github.io/documentation/1.5/_running.html
  9. /// </summary>
  10. public class ApplicationOptions
  11. {
  12. /// <param name="assetsFolder">usually it's "Data". Can be null if built-in assets are enough for you</param>
  13. public ApplicationOptions(string assetsFolder)
  14. {
  15. if (assetsFolder != null)
  16. {
  17. ResourcePaths = new[] { assetsFolder };
  18. }
  19. }
  20. public ApplicationOptions() {}
  21. /// <summary>
  22. /// Desktop only
  23. /// </summary>
  24. public int Width { get; set; } = 0;
  25. /// <summary>
  26. /// Desktop only
  27. /// </summary>
  28. public int Height { get; set; } = 0;
  29. /// <summary>
  30. /// Desktop only
  31. /// </summary>
  32. public bool WindowedMode { get; set; } = true;
  33. /// <summary>
  34. /// Desktop only
  35. /// </summary>
  36. public bool ResizableWindow { get; set; } = false;
  37. /// <summary>
  38. /// With limit enabled: 200 fps for Desktop (and always 60 fps for mobile despite of the flag)
  39. /// </summary>
  40. public bool LimitFps { get; set; } = true;
  41. /// <summary>
  42. /// iOS & Android only
  43. /// </summary>
  44. public OrientationType Orientation { get; set; }
  45. #if IOS && !XFORMS
  46. = OrientationType.Landscape;
  47. #else
  48. = OrientationType.LandscapeAndPortrait;
  49. #endif
  50. /// <summary>
  51. /// Resource path(s) to use (default: Data, CoreData)
  52. /// </summary>
  53. public string[] ResourcePaths { get; set; } = null;
  54. /// <summary>
  55. /// Resource package files to use (default: empty)
  56. /// </summary>
  57. public string[] ResourcePackagesPaths { get; set; } = null;
  58. #if WINDOWS_UWP
  59. public bool TouchEmulation { get { return true; } set {} }
  60. #else
  61. /// <summary>
  62. /// Touch emulation on desktop platform
  63. /// </summary>
  64. public bool TouchEmulation { get; set; } = false;
  65. #endif
  66. /// <summary>
  67. /// Enable high DPI, only supported by Apple platforms (OSX, iOS, and tvOS)
  68. /// </summary>
  69. public bool HighDpi { get; set; } = true;
  70. /// <summary>
  71. /// Add any flag listed here: http://urho3d.github.io/documentation/1.5/_running.html
  72. /// </summary>
  73. public string AdditionalFlags { get; set; } = string.Empty;
  74. /// <summary>
  75. /// Windows: external window handle (WinForms Panel.Handle) to use in order to display Urho game
  76. /// You can use it in WPF via WindowsFormsHost (and a WF panel inside it)
  77. /// </summary>
  78. public IntPtr ExternalWindow { get; set; }
  79. public bool DelayedStart { get; set; } = false;
  80. public bool AutoloadCoreData { get; set; } = true;
  81. public string[] ResourcePrefixPaths { get; set; }
  82. public int Multisampling { get; set; }
  83. public enum OrientationType
  84. {
  85. Landscape,
  86. Portrait,
  87. LandscapeAndPortrait
  88. }
  89. public override string ToString()
  90. {
  91. StringBuilder builder = new StringBuilder();
  92. builder.Append("args");//it will be skipped by Urho;
  93. #if !IOS //always use -w on iOS
  94. if (WindowedMode)
  95. #endif
  96. builder.Append(" -w");
  97. if (!LimitFps)
  98. builder.Append(" -nolimit");
  99. if (DelayedStart)
  100. builder.Append(" -delayedstart");
  101. if (Width > 0)
  102. builder.AppendFormat(" -x {0}", Width);
  103. if (Height > 0)
  104. builder.AppendFormat(" -y {0}", Height);
  105. if (Multisampling > 0)
  106. builder.AppendFormat(" -m {0}", Multisampling);
  107. #if !IOS //always use -s on iOS
  108. if (ResizableWindow)
  109. #endif
  110. builder.Append(" -s");
  111. string[] resourcePathes = new[] { "CoreData" }.Concat(ResourcePaths ?? new string[0]).ToArray();
  112. if (!AutoloadCoreData)
  113. resourcePathes = ResourcePaths ?? new string[0];
  114. builder.AppendFormat(" -p \"{0}\"", string.Join(";", resourcePathes.Distinct()));
  115. if (ResourcePackagesPaths?.Length > 0)
  116. builder.AppendFormat(" -pf \"{0}\"", string.Join(";", ResourcePackagesPaths));
  117. string[] resourcePrefixPaths = ResourcePrefixPaths;
  118. #if DESKTOP
  119. var urhoDllFolder = System.IO.Path.GetDirectoryName(typeof(SimpleApplication).Assembly.Location);
  120. var possibleCoreDataDirectories = new[]
  121. {
  122. Environment.CurrentDirectory,
  123. System.IO.Path.Combine(urhoDllFolder, "../../native"), //in case if Urho.dll is loaded from the nuget directory directly (see UrhoSharp.targets)
  124. urhoDllFolder,
  125. };
  126. if (ResourcePrefixPaths?.Length > 0)
  127. possibleCoreDataDirectories = ResourcePrefixPaths.Concat(possibleCoreDataDirectories).Distinct().ToArray();
  128. resourcePrefixPaths = possibleCoreDataDirectories;
  129. #endif
  130. if (resourcePrefixPaths?.Length > 0)
  131. builder.AppendFormat(" -pp \"{0}\"", string.Join(";", resourcePrefixPaths));
  132. #if !WINDOWS_UWP
  133. if (TouchEmulation)
  134. #endif
  135. builder.Append(" -touch");
  136. if (HighDpi)
  137. builder.Append(" -hd");
  138. switch (Orientation)
  139. {
  140. case OrientationType.Landscape:
  141. builder.Append(" -landscape");
  142. break;
  143. case OrientationType.Portrait:
  144. builder.Append(" -portrait");
  145. break;
  146. case OrientationType.LandscapeAndPortrait:
  147. builder.Append(" -landscape -portrait");
  148. break;
  149. }
  150. return builder + " " + AdditionalFlags;
  151. }
  152. }
  153. }