NRTrackablePlaneBehaviour.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 plane behaviour. </summary>
  13. public class NRTrackablePlaneBehaviour : NRTrackableBehaviour
  14. {
  15. /// <summary> Starts this object. </summary>
  16. private void Start()
  17. {
  18. #if UNITY_EDITOR
  19. DatabaseIndex = NREmulatorManager.SIMPlaneID;
  20. NREmulatorManager.SIMPlaneID++;
  21. #endif
  22. #if !UNITY_EDITOR
  23. MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
  24. if (meshRenderer != null) Destroy(meshRenderer);
  25. MeshFilter mesh = GetComponent<MeshFilter>();
  26. if (mesh != null) Destroy(mesh);
  27. #endif
  28. }
  29. #if UNITY_EDITOR
  30. /// <summary> Updates this object. </summary>
  31. private void Update()
  32. {
  33. float extent = transform.lossyScale.x * 1000;
  34. if (NREmulatorManager.Instance.IsInGameView(transform.position))
  35. {
  36. NREmulatorTrackableProvider.UpdateTrackableData<NRTrackablePlane>
  37. (transform.position, transform.rotation, extent, extent, (uint)DatabaseIndex, TrackingState.Tracking);
  38. }
  39. else
  40. {
  41. NREmulatorTrackableProvider.UpdateTrackableData<NRTrackablePlane>
  42. (transform.position, transform.rotation, extent, extent, (uint)DatabaseIndex, TrackingState.Stopped);
  43. }
  44. }
  45. #endif
  46. }
  47. }