Colors.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using UnityEngine;
  2. namespace Smoothie.MonetColors.Runtime
  3. {
  4. public partial class Colors
  5. {
  6. public const int ColorsAmount = 65;
  7. public static string[] Names { get; } = new string[ColorsAmount] {
  8. "accent1_0",
  9. "accent1_10",
  10. "accent1_50",
  11. "accent1_100",
  12. "accent1_200",
  13. "accent1_300",
  14. "accent1_400",
  15. "accent1_500",
  16. "accent1_600",
  17. "accent1_700",
  18. "accent1_800",
  19. "accent1_900",
  20. "accent1_1000",
  21. "accent2_0",
  22. "accent2_10",
  23. "accent2_50",
  24. "accent2_100",
  25. "accent2_200",
  26. "accent2_300",
  27. "accent2_400",
  28. "accent2_500",
  29. "accent2_600",
  30. "accent2_700",
  31. "accent2_800",
  32. "accent2_900",
  33. "accent2_1000",
  34. "accent3_0",
  35. "accent3_10",
  36. "accent3_50",
  37. "accent3_100",
  38. "accent3_200",
  39. "accent3_300",
  40. "accent3_400",
  41. "accent3_500",
  42. "accent3_600",
  43. "accent3_700",
  44. "accent3_800",
  45. "accent3_900",
  46. "accent3_1000",
  47. "neutral1_0",
  48. "neutral1_10",
  49. "neutral1_50",
  50. "neutral1_100",
  51. "neutral1_200",
  52. "neutral1_300",
  53. "neutral1_400",
  54. "neutral1_500",
  55. "neutral1_600",
  56. "neutral1_700",
  57. "neutral1_800",
  58. "neutral1_900",
  59. "neutral1_1000",
  60. "neutral2_0",
  61. "neutral2_10",
  62. "neutral2_50",
  63. "neutral2_100",
  64. "neutral2_200",
  65. "neutral2_300",
  66. "neutral2_400",
  67. "neutral2_500",
  68. "neutral2_600",
  69. "neutral2_700",
  70. "neutral2_800",
  71. "neutral2_900",
  72. "neutral2_1000",
  73. };
  74. public static Color GetColor(int index)
  75. {
  76. Color color = _fallbackPalette[index];
  77. if (Application.platform == RuntimePlatform.Android)
  78. {
  79. AndroidJavaClass versionClass = new AndroidJavaClass("android.os.Build$VERSION");
  80. int sdkInt = versionClass.GetStatic<int>("SDK_INT");
  81. if (sdkInt > 30)
  82. {
  83. AndroidJavaClass colorClass = new AndroidJavaClass("android.R$color");
  84. int colorInt = colorClass.GetStatic<int>("system_" + Names[index]);
  85. AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  86. AndroidJavaObject context = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
  87. int colorValue = context.Call<AndroidJavaObject>("getResources").Call<int>("getColor", colorInt);
  88. colorClass = new AndroidJavaClass("android.graphics.Color");
  89. AndroidJavaObject colorObject = colorClass.CallStatic<AndroidJavaObject>("valueOf", colorValue);
  90. float red = colorObject.Call <float>("red");
  91. float green = colorObject.Call <float>("green");
  92. float blue = colorObject.Call <float>("blue");
  93. color = new Color(red, green, blue);
  94. }
  95. }
  96. return color;
  97. }
  98. }
  99. }