NxrMarkerEditor.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Nxr.Internal
  6. {
  7. public class NxrMarkerEditor
  8. {
  9. [DrawGizmo(GizmoType.InSelectionHierarchy)] // Draw the gizmo if it
  10. static void RenderARTrackedObjectGizmo(NibiruMarker marker, GizmoType gizmoType)
  11. {
  12. bool selected = (gizmoType & GizmoType.Active) != 0;
  13. if (selected)
  14. {
  15. Gizmos.color = Color.white;
  16. Gizmos.DrawCube(marker.transform.position - new Vector3(0, 0.02f, 0), new Vector3(0.08f, 0.001f, 0.08f));
  17. Gizmos.color = Color.red;
  18. DrawWord("Marker", 0.01f, new Vector3(-0.15f, -0.02f, -0.10f), new Vector3(0, 0, 1), new Vector3(1, 0, 0));
  19. }
  20. }
  21. private static void DrawRectangle(Vector3 centre, Vector3 up, Vector3 right, float width, float height, Color color)
  22. {
  23. Gizmos.color = color;
  24. //ARController.Log("DrawRectangle centre=" + centre.ToString("F3") + ", up=" + up.ToString("F3") + ", right=" + right.ToString("F3") + ", width=" + width.ToString("F3") + ", height=" + height.ToString("F3") + ".");
  25. Vector3 u = up * height;
  26. Vector3 r = right * width;
  27. Vector3 p = centre - (u * 0.5f) - (r * 0.5f);
  28. Gizmos.DrawLine(p, p + u);
  29. Gizmos.DrawLine(p + u, p + u + r);
  30. Gizmos.DrawLine(p + u + r, p + r);
  31. Gizmos.DrawLine(p + r, p);
  32. }
  33. private static void DrawWord(String word, float size, Vector3 origin, Vector3 forward, Vector3 right)
  34. {
  35. foreach (char c in word.ToUpper())
  36. {
  37. DrawLetter(c, size, origin, forward, right);
  38. origin += right * size * 6.0f;
  39. }
  40. }
  41. private static void DrawLetter(char letter, float size, Vector3 origin, Vector3 forward, Vector3 right)
  42. {
  43. String path = letters[letter];
  44. Vector3 f = forward * size;
  45. Vector3 r = right * size;
  46. Vector3 down = origin;
  47. Vector3 current = origin;
  48. foreach (char c in path)
  49. {
  50. switch (c)
  51. {
  52. case '(':
  53. down = current;
  54. continue;
  55. case ')':
  56. Gizmos.DrawLine(down, current);
  57. continue;
  58. case 'U':
  59. current += f;
  60. break;
  61. case 'D':
  62. current -= f;
  63. break;
  64. case 'R':
  65. current += r;
  66. break;
  67. case 'L':
  68. current -= r;
  69. break;
  70. }
  71. }
  72. }
  73. private readonly static Dictionary<char, String> letters = new Dictionary<char, String>() {
  74. {' ', ""},
  75. {'!', "RR(U)U(UU)"},
  76. {'"', "UUUUR(D)URR(D)"},
  77. {'#', "R(UUUU)RR(DDDD)UR(LLLL)UU(RRRR)"},
  78. {'$', "RR(UUUU)DR(LL)(D)(RR)(D)(LL)"},
  79. {'%', "RUUUU(D)DDD(RRUUUU)DDD(D)"},
  80. {'&', "RRRRUU(DDLL)(L)(UL)(RRRUU)(UL)(DL)(DDDRRR)"},
  81. {'\'',"RRUUU(U)"},
  82. {'(', "RRR(UL)(UU)(UR)"},
  83. {')', "R(UR)(UU)(UL)"},
  84. {'*', "RR(UUUU)DL(DDRR)UU(DDLL)UL(RRRR)"},
  85. {'+', "RUU(RR)LU(DD)"},
  86. {',', "R(UR)"},
  87. {'-', "UR(RR)"},
  88. {'.', "RR(U)"},
  89. {'/', "R(UUUURR)"},
  90. {'0', "(UUUU)(RRRR)(DDDD)(LLLL)"},
  91. {'1', "RR(UUUU)"},
  92. {'2', "UUU(UR)(RR)(DR)(DDDLLLL)(RRRR)"},
  93. {'3', "U(DR)(RR)(UR)(ULL)(URR)(UL)(LL)(DL)"},
  94. {'4', "RRRRU(LLLL)(UUURRR)(DDDD)"},
  95. {'5', "(RRRR)(UU)(LLLL)(UU)(RRRR)"},
  96. {'6', "UUUURRR(LL)(DDL)(DD)(RRRR)(UU)(LLLL)"},
  97. {'7', "UUUU(RRRR)(DDDDLL)"},
  98. {'8', "(UUUU)(RRRR)(DDDD)(LLLL)UU(RRRR)"},
  99. {'9', "R(RR)(UUR)(LLLL)(UU)(RRRR)(DD)"},
  100. {':', "RR(U)UU(U)"},
  101. {';', "R(UR)UU(U)"},
  102. {'<', "RRR(UULL)(RRUU)"},
  103. {'=', "UR(RR)UU(LL)"},
  104. {'>', "R(UURR)(LLUU)"},
  105. {'?', "RR(U)U(R)(UR)(UL)(L)(DL)"},
  106. {'@', "RRR(LL)(UL)(UU)(UR)(RR)(DR)(DD)(LL)(U)(R)(D)"},
  107. {'A', "(UUU)(UR)(RR)(DR)(DDD)UU(LLLL)"},
  108. {'B', "(UUUU)(RRR)(DR)(DD)(DL)(LLL)UU(RRRR)"},
  109. {'C', "RRRRU(DL)(LL)(UL)(UU)(UR)(RR)(DR)"},
  110. {'D', "(UUUU)(RRR)(DR)(DD)(DL)(LLL)"},
  111. {'E', "(UUUU)(RRRR)DDLL(LL)DD(RRRR)"},
  112. {'F', "(UUUU)(RRRR)DDLL(LL)"},
  113. {'G', "UURR(RR)(DD)(LLL)(UL)(UU)(UR)(RR)(DR)"},
  114. {'H', "(UUUU)DD(RRRR)UU(DDDD)"},
  115. {'I', "(RRRR)LL(UUUU)LL(RRRR)"},
  116. {'J', "U(D)(RR)(UUUU)LL(RRRR)"},
  117. {'K', "(UUUU)RRRR(DDLLLL)(DDRRRR)"},
  118. {'L', "UUUU(DDDD)(RRRR)"},
  119. {'M', "(UUUU)(DDRR)(UURR)(DDDD)"},
  120. {'N', "(UUUU)(DDDDRRRR)(UUUU)"},
  121. {'O', "U(UU)(UR)(RR)(DR)(DD)(DL)(LL)(UL)"},
  122. {'P', "(UUUU)(RRR)(DR)(D)(DL)(LLL)"},
  123. {'Q', "U(UU)(UR)(RR)(DR)(DD)(DL)(LL)(UL)RRR(DR)"},
  124. {'R', "(UUUU)(RRR)(DR)(D)(DL)(LLL)RRR(DR)"},
  125. {'S', "U(DR)(RR)(UR)(UL)(LL)(UL)(UR)(RR)(DR)"},
  126. {'T', "RR(UUUU)LL(RRRR)"},
  127. {'U', "UUUU(DDDD)(RRR)(UR)(UUU)"},
  128. {'V', "UUUU(DDDDRR)(UUUURR)"},
  129. {'W', "UUUU(DDDDR)(UUR)(DDR)(UUUUR)"},
  130. {'X', "(UUUURRRR)LLLL(DDDDRRRR)"},
  131. {'Y', "UUUU(DDRR)(UURR)DDLL(DD)"},
  132. {'Z', "UUUU(RRRR)(DDDDLLLL)(RRRR)"},
  133. {'[', "RRR(L)(UUUU)(R)"},
  134. {'\\',"RRR(UUUULL)"},
  135. {']', "R(R)(UUUU)(L)"},
  136. {'^', "UUR(UUR)(DDR)"},
  137. {'_', "(RRRR)"},
  138. {'`', "UUUURR(DR)"},
  139. {'{', "RRR(L)(U)(LU)(RU)(U)(R)"},
  140. {'|', "RR(UUUU)"},
  141. {'}', "R(R)(U)(RU)(LU)(U)(L)"},
  142. {'~', "UU(UR)(DDRR)(UR)"}
  143. };
  144. }
  145. }