AnchorItem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental.Persistence
  10. {
  11. using NRKernal.Experimental.Persistence;
  12. using System;
  13. using UnityEngine;
  14. using UnityEngine.EventSystems;
  15. /// <summary> An anchor item. </summary>
  16. public class AnchorItem : MonoBehaviour, IPointerClickHandler
  17. {
  18. /// <summary> The key. </summary>
  19. public string key;
  20. /// <summary> The on anchor item click. </summary>
  21. public Action<string, GameObject> OnAnchorItemClick;
  22. private NRWorldAnchorStore m_NRWorldAnchorStore;
  23. void Start()
  24. {
  25. NRWorldAnchorStore.GetAsync((anchorstore) =>
  26. {
  27. m_NRWorldAnchorStore = anchorstore;
  28. });
  29. }
  30. public void DeleteKey()
  31. {
  32. m_NRWorldAnchorStore?.Delete(key);
  33. }
  34. /// <summary> <para>Use this callback to detect clicks.</para> </summary>
  35. /// <param name="eventData"> Current event data.</param>
  36. public void OnPointerClick(PointerEventData eventData)
  37. {
  38. OnAnchorItemClick?.Invoke(key, gameObject);
  39. }
  40. }
  41. }