NRTrackableImageBehaviour.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  10. {
  11. using UnityEngine;
  12. /// <summary> A nr trackable image behaviour. </summary>
  13. public class NRTrackableImageBehaviour : NRTrackableBehaviour
  14. {
  15. /// <summary> The aspect ratio. </summary>
  16. [HideInInspector, SerializeField]
  17. private float m_AspectRatio;
  18. /// <summary> The width. </summary>
  19. [HideInInspector, SerializeField]
  20. private float m_Width;
  21. /// <summary> The height. </summary>
  22. [HideInInspector, SerializeField]
  23. private float m_Height;
  24. /// <summary> The tracking image database. </summary>
  25. [HideInInspector, SerializeField]
  26. private string m_TrackingImageDatabase;
  27. /// <summary> Awakes this object. </summary>
  28. private void Awake()
  29. {
  30. #if !UNITY_EDITOR
  31. MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
  32. if (meshRenderer != null) Destroy(meshRenderer);
  33. MeshFilter mesh = GetComponent<MeshFilter>();
  34. if (mesh != null) Destroy(mesh);
  35. #endif
  36. }
  37. #if UNITY_EDITOR
  38. private void Update()
  39. {
  40. float extent = transform.lossyScale.x * 1000;
  41. if (NREmulatorManager.Instance.IsInGameView(transform.position))
  42. {
  43. NREmulatorTrackableProvider.UpdateTrackableData<NRTrackableImage>
  44. (transform.position, transform.rotation, extent, extent, (uint)DatabaseIndex, TrackingState.Tracking);
  45. }
  46. else
  47. {
  48. NREmulatorTrackableProvider.UpdateTrackableData<NRTrackableImage>
  49. (transform.position, transform.rotation, extent, extent, (uint)DatabaseIndex, TrackingState.Stopped);
  50. }
  51. }
  52. #endif
  53. }
  54. }