ActiveMapsListItem.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.ActiveMapsList
  12. {
  13. public class ActiveMapsListItem : MonoBehaviour
  14. {
  15. [SerializeField]
  16. private TextMeshProUGUI m_MapIdField = null;
  17. [SerializeField]
  18. private TextMeshProUGUI nameField = null;
  19. [SerializeField]
  20. private Toggle toggle = null;
  21. public int mapId = -1;
  22. private ActiveMapsListControl m_ActiveMapsListControl = null;
  23. private void ToggleValueChanged(Toggle t)
  24. {
  25. if(t.isOn && mapId > 0)
  26. {
  27. Debug.Log(string.Format("toggle on: {0}", mapId));
  28. m_ActiveMapsListControl.rootMapId = mapId;
  29. }
  30. }
  31. public void SetStateManually(bool isOn)
  32. {
  33. toggle.isOn = isOn;
  34. ToggleValueChanged(toggle);
  35. }
  36. public void SetMapId(int id)
  37. {
  38. if (m_MapIdField != null)
  39. {
  40. mapId = id;
  41. m_MapIdField.text = string.Format("{0}", id);
  42. }
  43. }
  44. public void SetToggleGroup(ToggleGroup toggleGroup)
  45. {
  46. if (toggle != null)
  47. {
  48. toggle.group = toggleGroup;
  49. }
  50. }
  51. public void SetName(string mapName)
  52. {
  53. if (nameField != null)
  54. {
  55. nameField.text = string.Format("{0}", mapName);
  56. }
  57. }
  58. public void SetListController(ActiveMapsListControl activeMapsListControl)
  59. {
  60. m_ActiveMapsListControl = activeMapsListControl;
  61. }
  62. private void Start()
  63. {
  64. toggle.onValueChanged.AddListener(delegate {ToggleValueChanged(toggle);});
  65. }
  66. }
  67. }