NavigationTargetListButton.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.EventSystems;
  10. using UnityEngine.UI;
  11. using TMPro;
  12. namespace Immersal.Samples.Navigation
  13. {
  14. public class NavigationTargetListButton : Button, IPointerClickHandler
  15. {
  16. [HideInInspector]
  17. public GameObject targetObject = null;
  18. [SerializeField]
  19. private TextMeshProUGUI m_TextMeshProUGUI = null;
  20. [SerializeField]
  21. private Image m_Image = null;
  22. private string targetName = null;
  23. public void SetText(string text)
  24. {
  25. targetName = text;
  26. if (m_TextMeshProUGUI != null)
  27. {
  28. m_TextMeshProUGUI.text = targetName;
  29. }
  30. }
  31. public void SetIcon(Sprite icon)
  32. {
  33. if (m_Image != null)
  34. {
  35. m_Image.sprite = icon;
  36. }
  37. }
  38. public void SetTarget(GameObject go)
  39. {
  40. targetObject = go;
  41. }
  42. override public void OnPointerClick(PointerEventData pointerEventData)
  43. {
  44. NavigationManager.Instance.InitializeNavigation(this);
  45. NavigationManager.Instance.ToggleTargetsList();
  46. base.OnPointerClick(pointerEventData);
  47. }
  48. }
  49. }