DrawControl.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class DrawControl : MonoBehaviour
  6. {
  7. public Toggle arrowToggle_;
  8. public Toggle textToggle_;
  9. public Toggle brushToggle_;
  10. public Toggle targetToggle_;
  11. public static DrawScript drawScript_;
  12. public void Clear()
  13. {
  14. drawScript_.Clear();
  15. arrowToggle_.isOn = false;
  16. textToggle_.isOn = false;
  17. brushToggle_.isOn = false;
  18. targetToggle_.isOn = false;
  19. }
  20. // Use this for initialization
  21. public void Init()
  22. {
  23. arrowToggle_.onValueChanged.AddListener(OnArrowToggleValueChanged);
  24. textToggle_.onValueChanged.AddListener(OnTextToggleValueChanged);
  25. brushToggle_.onValueChanged.AddListener(OnBrushToggleValueChanged);
  26. targetToggle_.onValueChanged.AddListener(OnTargetToggleValueChanged);
  27. }
  28. private void OnArrowToggleValueChanged(bool isOn)
  29. {
  30. ColorBlock cb = arrowToggle_.colors;
  31. if (isOn)
  32. {
  33. cb.normalColor = Color.gray;
  34. cb.highlightedColor = Color.gray;
  35. textToggle_.isOn = false;
  36. brushToggle_.isOn = false;
  37. targetToggle_.isOn = false;
  38. drawScript_.DrawMode = DrawScript.DRAW_MODE.ARROW;
  39. }
  40. else
  41. {
  42. cb.normalColor = Color.white;
  43. cb.highlightedColor = Color.white;
  44. drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
  45. }
  46. arrowToggle_.colors = cb;
  47. }
  48. private void OnTextToggleValueChanged(bool isOn)
  49. {
  50. ColorBlock cb = textToggle_.colors;
  51. if (isOn)
  52. {
  53. cb.normalColor = Color.gray;
  54. cb.highlightedColor = Color.gray;
  55. arrowToggle_.isOn = false;
  56. brushToggle_.isOn = false;
  57. targetToggle_.isOn = false;
  58. drawScript_.DrawMode = DrawScript.DRAW_MODE.TEXT;
  59. }
  60. else
  61. {
  62. cb.normalColor = Color.white;
  63. cb.highlightedColor = Color.white;
  64. drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
  65. }
  66. textToggle_.colors = cb;
  67. }
  68. private void OnBrushToggleValueChanged(bool isOn)
  69. {
  70. ColorBlock cb = brushToggle_.colors;
  71. if (isOn)
  72. {
  73. cb.normalColor = Color.gray;
  74. cb.highlightedColor = Color.gray;
  75. arrowToggle_.isOn = false;
  76. textToggle_.isOn = false;
  77. targetToggle_.isOn = false;
  78. drawScript_.DrawMode = DrawScript.DRAW_MODE.PAINTBRUSH;
  79. }
  80. else
  81. {
  82. cb.normalColor = Color.white;
  83. cb.highlightedColor = Color.white;
  84. drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
  85. }
  86. brushToggle_.colors = cb;
  87. }
  88. private void OnTargetToggleValueChanged(bool isOn)
  89. {
  90. ColorBlock cb = targetToggle_.colors;
  91. if (isOn)
  92. {
  93. cb.normalColor = Color.gray;
  94. cb.highlightedColor = Color.gray;
  95. arrowToggle_.isOn = false;
  96. textToggle_.isOn = false;
  97. brushToggle_.isOn = false;
  98. drawScript_.DrawMode = DrawScript.DRAW_MODE.TARGET;
  99. }
  100. else
  101. {
  102. cb.normalColor = Color.white;
  103. cb.highlightedColor = Color.white;
  104. drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
  105. }
  106. targetToggle_.colors = cb;
  107. }
  108. }