IsNavigationTarget.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 System.Collections.Generic;
  9. using UnityEngine;
  10. namespace Immersal.Samples.Navigation
  11. {
  12. public class IsNavigationTarget : MonoBehaviour
  13. {
  14. public NavigationTargets.NavigationCategory navigationCategory = NavigationTargets.NavigationCategory.Locations;
  15. public string targetName;
  16. public Sprite icon;
  17. public Vector3 position
  18. {
  19. get
  20. {
  21. return m_collider.bounds.center;
  22. }
  23. set
  24. {
  25. }
  26. }
  27. private Collider m_collider = null;
  28. private void Start()
  29. {
  30. NavigationGraphManager.Instance?.AddTarget(this);
  31. }
  32. private void OnDestroy()
  33. {
  34. NavigationGraphManager.Instance?.RemoveTarget(this);
  35. }
  36. private void OnEnable()
  37. {
  38. m_collider = GetComponent<Collider>();
  39. if (!NavigationTargets.NavigationTargetsDict.ContainsKey(navigationCategory))
  40. NavigationTargets.NavigationTargetsDict[navigationCategory] = new List<GameObject>();
  41. NavigationTargets.NavigationTargetsDict[navigationCategory].Add(gameObject);
  42. if (targetName.Equals(""))
  43. {
  44. targetName = gameObject.name;
  45. }
  46. }
  47. private void OnDisable()
  48. {
  49. if (NavigationTargets.NavigationTargetsDict.ContainsKey(navigationCategory))
  50. NavigationTargets.NavigationTargetsDict[navigationCategory].Remove(gameObject);
  51. }
  52. }
  53. }