SurfaceObserver is the main API portal for spatial mapping functionality in Unity.

Inheritance: IDisposable
コード例 #1
0
        public bool RequestMeshAsync(SurfaceData dataRequest, SurfaceObserver.SurfaceDataReadyDelegate onDataReady)
        {
            if (onDataReady == null)
            {
                throw new ArgumentNullException("onDataReady");
            }
            if (dataRequest.outputMesh == null)
            {
                throw new ArgumentNullException("dataRequest.outputMesh");
            }
            if (dataRequest.outputAnchor == null)
            {
                throw new ArgumentNullException("dataRequest.outputAnchor");
            }
            if (dataRequest.outputCollider == null && dataRequest.bakeCollider)
            {
                throw new ArgumentException("dataRequest.outputCollider must be non-NULL if dataRequest.bakeCollider is true", "dataRequest.outputCollider");
            }
            if ((double)dataRequest.trianglesPerCubicMeter < 0.0)
            {
                throw new ArgumentException("dataRequest.trianglesPerCubicMeter must be greater than zero", "dataRequest.trianglesPerCubicMeter");
            }
            bool flag = SurfaceObserver.Internal_AddToWorkQueue(this.m_Observer, onDataReady, dataRequest.id.handle, dataRequest.outputMesh, dataRequest.outputAnchor, dataRequest.outputCollider, dataRequest.trianglesPerCubicMeter, dataRequest.bakeCollider);

            if (!flag)
            {
                Debug.LogError("RequestMeshAsync has failed.  Is your surface ID valid?");
            }
            return(flag);
        }
コード例 #2
0
        private IntPtr Internal_Create()
        {
            IntPtr result;

            SurfaceObserver.INTERNAL_CALL_Internal_Create(this, out result);
            return(result);
        }
コード例 #3
0
 public void Update(SurfaceObserver.SurfaceChangedDelegate onSurfaceChanged)
 {
     if (onSurfaceChanged == null)
     {
         throw new ArgumentNullException("onSurfaceChanged");
     }
     SurfaceObserver.Internal_Update(this.m_Observer, onSurfaceChanged);
 }
コード例 #4
0
 public void Dispose()
 {
     if (this.m_Observer != IntPtr.Zero)
     {
         SurfaceObserver.Destroy(this.m_Observer);
         this.m_Observer = IntPtr.Zero;
     }
     GC.SuppressFinalize(this);
 }
コード例 #5
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsAxisAlignedBox(SurfaceObserver self, IntPtr observer, ref Vector3 origin, ref Vector3 extents);
コード例 #6
0
 /// <summary>
 /// Standard initialization method creating our properties
 /// </summary>
 protected virtual void Start()
 {
     surfaceObserver = new SurfaceObserver();
     UpdateSurfaceObserverPosition();
     StartCoroutine(UpdateLoop());
     bounds = new Bounds(transform.position, Extents);
 }
コード例 #7
0
 private static extern void INTERNAL_CALL_Internal_Create(SurfaceObserver self, out IntPtr value);
コード例 #8
0
        /// <summary>
        /// Starts the Surface Observer.
        /// </summary>
        public void StartObserving()
        {
            if (observer == null)
            {
                observer = new SurfaceObserver();
                observer.SetVolumeAsAxisAlignedBox(Vector3.zero, Extents);
            }

            if (ObserverState != ObserverStates.Running)
            {
                Debug.Log("Starting the observer.");
                ObserverState = ObserverStates.Running;

                // We want the first update immediately.
                updateTime = 0;
            }
        }
コード例 #9
0
        /// <summary>
        /// Cleans up all memory and objects associated with the observer.
        /// </summary>
        public void CleanupObserver()
        {
            if (observer != null)
            {
                StopObserving();

                // Clear out all memory allocated the observer
                observer.Dispose();
                observer = null;

                foreach (KeyValuePair<int, GameObject> surfaceRef in surfaces)
                {
                    CleanupSurface(surfaceRef.Value);
                }

                // Get all valid mesh filters for observed surfaces and destroy them
                List<MeshFilter> meshFilters = GetMeshFilters();
                for (int i = 0; i < meshFilters.Count; i++)
                {
                    Destroy(meshFilters[i].sharedMesh);
                }
                meshFilters.Clear();

                // Cleanup all available surfaces
                foreach (GameObject availableSurface in availableSurfaces)
                {
                    Destroy(availableSurface);
                }
                availableSurfaces.Clear();
                surfaces.Clear();
            }
        }
コード例 #10
0
 private void Internal_SetVolumeAsOrientedBox(IntPtr observer, Vector3 origin, Vector3 extents, Quaternion orientation)
 {
     SurfaceObserver.INTERNAL_CALL_Internal_SetVolumeAsOrientedBox(this, observer, ref origin, ref extents, ref orientation);
 }
コード例 #11
0
 private void Internal_SetVolumeAsSphere(IntPtr observer, Vector3 origin, float radiusMeters)
 {
     SurfaceObserver.INTERNAL_CALL_Internal_SetVolumeAsSphere(this, observer, ref origin, radiusMeters);
 }
コード例 #12
0
        /// <summary>
        /// Starts the Surface Observer.
        /// </summary>
        public void StartObserving()
        {
            if (ObserverState != ObserverStates.Running)
            {
                Debug.Log("Starting the observer.");
                // on device, this isn't necessary, but sometimes in the emulator the observer 
                // won't realize that it hasn't already sent you the surfaces, and since the surfaces
                // don't really get updated in the emulator you'll end up getting no surfaces at all.
                if (surfaces.Count == 0)
                {
                    if (observer != null)
                    {
                        observer.Dispose();
                        observer = null;
                    }

                    observer = new SurfaceObserver();
                }

                ObserverState = ObserverStates.Running;

                // We want the first update immediately.
                updateTime = 0;
            }
        }
コード例 #13
0
 private void Internal_SetVolumeAsAxisAlignedBox(IntPtr observer, Vector3 origin, Vector3 extents)
 {
     SurfaceObserver.INTERNAL_CALL_Internal_SetVolumeAsAxisAlignedBox(this, observer, ref origin, ref extents);
 }
コード例 #14
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsSphere(SurfaceObserver self, IntPtr observer, ref Vector3 origin, float radiusMeters);
コード例 #15
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsOrientedBox(SurfaceObserver self, IntPtr observer, ref Vector3 origin, ref Vector3 extents, ref Quaternion orientation);
コード例 #16
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsOrientedBox(SurfaceObserver self, IntPtr observer, ref Vector3 origin, ref Vector3 extents, ref Quaternion orientation);
コード例 #17
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsAxisAlignedBox(SurfaceObserver self, IntPtr observer, ref Vector3 origin, ref Vector3 extents);
コード例 #18
0
 private static extern void INTERNAL_CALL_Internal_Create(SurfaceObserver self, out IntPtr value);
コード例 #19
0
        /// <summary>
        /// Called when the GameObject is unloaded.
        /// </summary>
        private void OnDestroy()
        {
            // Stop the observer.
            StopObserving();

            observer.Dispose();
            observer = null;

            // Clear our surface mesh collection.
            surfaces.Clear();
        }
コード例 #20
0
 private void Awake()
 {
     observer = new SurfaceObserver();
     ObserverState = ObserverStates.Stopped;
 }
コード例 #21
0
 private static extern void INTERNAL_CALL_Internal_SetVolumeAsSphere(SurfaceObserver self, IntPtr observer, ref Vector3 origin, float radiusMeters);
コード例 #22
0
        protected override void Awake()
        {
            base.Awake();

            observer = new SurfaceObserver();
            ObserverState = ObserverStates.Stopped;
            observerOrigin = Vector3.zero;
        }