/// <summary> /// Removes the augmented reality anchor, if any. /// </summary> /// <param name="source">The source.</param> /// <exception cref="System.ArgumentNullException">source</exception> public static void RemoveARAnchor(this GameObject source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } #if UNITY_IOS UnityARUserAnchorComponent unityARUserAnchorComponent = source.GetComponent <UnityARUserAnchorComponent>(); if (unityARUserAnchorComponent != null) { GameObject.DestroyImmediate(unityARUserAnchorComponent); } #elif UNITY_ANDROID UnityARCoreWorldAnchorComponent anchorComponent = source.GetComponent <UnityARCoreWorldAnchorComponent>(); if (anchorComponent != null) { GameObject.DestroyImmediate(anchorComponent); } #elif WINDOWS_UWP WorldAnchor worldAnchor = source.GetComponent <WorldAnchor>(); if (worldAnchor != null) { GameObject.DestroyImmediate(worldAnchor); } #else throw new PlatformNotSupportedException("Unable to remove the anchor. The platform is not supported."); #endif }
/// <summary> /// Gets the native anchor pointer. /// </summary> /// <param name="source">The source.</param> /// <returns>The native anchor <see cref="IntPtr" />.</returns> /// <exception cref="System.ArgumentNullException">source</exception> /// <exception cref="System.NullReferenceException"></exception> public static IntPtr GetNativeAnchorPointer(this GameObject source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } IntPtr retval = IntPtr.Zero; #if UNITY_IOS UnityARUserAnchorComponent unityARUserAnchorComponent = source.GetComponent <UnityARUserAnchorComponent>(); if (unityARUserAnchorComponent != null) { Debug.LogFormat("User anchor {0}", unityARUserAnchorComponent.AnchorId); retval = unityARUserAnchorComponent.GetAnchorPointer(); } #elif UNITY_ANDROID UnityARCoreWorldAnchorComponent anchorComponent = source.GetComponent <UnityARCoreWorldAnchorComponent>(); if (anchorComponent != null) { Debug.LogFormat("User anchor {0}", anchorComponent.WorldAnchor.m_NativeHandle); retval = anchorComponent.WorldAnchor.m_NativeHandle; } #elif WINDOWS_UWP WorldAnchor worldAnchor = source.GetComponent <WorldAnchor>(); if (worldAnchor != null) { retval = worldAnchor.GetNativeSpatialAnchorPtr(); } #else throw new PlatformNotSupportedException("Unable to retrieve the native anchor pointer. The platform is not supported."); #endif if (retval == IntPtr.Zero) { Debug.LogError("Didn't find AR anchor on gameobject"); } return(retval); }