MappingUIComponent.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using TMPro;
  11. namespace Immersal.Samples.Mapping
  12. {
  13. public class MappingUIComponent : MonoBehaviour
  14. {
  15. [SerializeField]
  16. private GameObject target_button = null;
  17. [SerializeField]
  18. private TextMeshProUGUI[] texts = null;
  19. private Image image = null;
  20. private Button button = null;
  21. private Color button_normalColor = new Color(0f, 0f, 0f, 0.8f);
  22. private Color button_disabledColor = new Color(0f, 0f, 0f, 0.4f);
  23. private Color icon_normalColor = new Color(1f, 1f, 1f, 1f);
  24. private Color icon_disabledColor = new Color(0.5f, 0.5f, 0.5f, 1f);
  25. private void Start() {
  26. image = GetComponent<Image>();
  27. if(image == null) {
  28. image = target_button.GetComponent<Image>();
  29. }
  30. button = GetComponent<Button>();
  31. if (button == null) {
  32. button = target_button.GetComponent<Button>();
  33. }
  34. }
  35. public void Activate() {
  36. if(image != null) {
  37. image.color = button_normalColor;
  38. }
  39. if(button != null) {
  40. ColorBlock cb = button.colors;
  41. cb.normalColor = icon_normalColor;
  42. button.colors = cb;
  43. button.interactable = true;
  44. }
  45. foreach (TextMeshProUGUI text in texts) {
  46. if (text != null) {
  47. text.color = icon_normalColor;
  48. }
  49. }
  50. }
  51. public void Disable() {
  52. if (image != null) {
  53. image.color = button_disabledColor;
  54. }
  55. if (button != null) {
  56. ColorBlock cb = button.colors;
  57. cb.normalColor = icon_disabledColor;
  58. button.colors = cb;
  59. button.interactable = false;
  60. }
  61. foreach (TextMeshProUGUI text in texts) {
  62. if (text != null) {
  63. text.color = icon_disabledColor;
  64. }
  65. }
  66. }
  67. }
  68. }