Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.1 KiB

  1. using System;
  2. #if UNITY_EDITOR
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEditor;
  6. #endif
  7. namespace VRTK
  8. {
  9. public static class VRTK_Defines
  10. {
  11. /// <summary>
  12. /// The current version of VRTK.
  13. /// </summary>
  14. public static readonly Version CurrentVersion = new Version(3, 3, 0);
  15. /// <summary>
  16. /// The previously known versions of VRTK.
  17. /// </summary>
  18. public static readonly Version[] PreviousVersions =
  19. {
  20. new Version(3, 1, 0),
  21. new Version(3, 2, 0),
  22. new Version(3, 2, 1),
  23. };
  24. /// <summary>
  25. /// The scripting define symbol that is used for the current version of VRTK.
  26. /// </summary>
  27. public static string CurrentExactVersionScriptingDefineSymbol { get; private set; }
  28. public const string VersionScriptingDefineSymbolPrefix = "VRTK_VERSION_";
  29. public const string VersionScriptingDefineSymbolSuffix = "_OR_NEWER";
  30. static VRTK_Defines()
  31. {
  32. CurrentExactVersionScriptingDefineSymbol = ExactVersionSymbol(CurrentVersion);
  33. }
  34. #if UNITY_EDITOR
  35. [InitializeOnLoadMethod]
  36. private static void EnsureVersionSymbolIsSet()
  37. {
  38. if (EditorApplication.isPlayingOrWillChangePlaymode)
  39. {
  40. return;
  41. }
  42. IEnumerable<string> atLeastVersionSymbols = new[] { CurrentVersion }
  43. .Concat(PreviousVersions)
  44. .Select(AtLeastVersionSymbol);
  45. string[] versionSymbols = new[] { CurrentExactVersionScriptingDefineSymbol }
  46. .Concat(atLeastVersionSymbols)
  47. .ToArray();
  48. foreach (BuildTargetGroup targetGroup in VRTK_SharedMethods.GetValidBuildTargetGroups())
  49. {
  50. string[] currentSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup)
  51. .Split(';')
  52. .Distinct()
  53. .OrderBy(symbol => symbol, StringComparer.Ordinal)
  54. .ToArray();
  55. string[] newSymbols = currentSymbols.Where(symbol => !symbol.StartsWith(VersionScriptingDefineSymbolPrefix, StringComparison.Ordinal))
  56. .Concat(versionSymbols)
  57. .ToArray();
  58. if (!currentSymbols.SequenceEqual(newSymbols))
  59. {
  60. PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", newSymbols));
  61. }
  62. }
  63. }
  64. #endif
  65. private static string ExactVersionSymbol(Version version)
  66. {
  67. return string.Format("{0}{1}", VersionScriptingDefineSymbolPrefix, version.ToString().Replace(".", "_"));
  68. }
  69. private static string AtLeastVersionSymbol(Version version)
  70. {
  71. return string.Format("{0}{1}", ExactVersionSymbol(version), VersionScriptingDefineSymbolSuffix);
  72. }
  73. }
  74. }