/// <summary> /// Get the most recent light estimate. /// </summary> /// <returns></returns> public LightEstimate GetLatestLightEstimate() { // Maintain frame consistency. if (Time.frameCount == m_latestLightEstimateFrame) { return(m_latestLightEstimate); } m_latestLightEstimateFrame = Time.frameCount; UnityTango.NativeImage nativeImage = new UnityTango.NativeImage(); if (!UnityTango.Device.TryAcquireLatestImageBuffer(ref nativeImage)) { Debug.LogError("Unable to acquire image buffer."); return(m_latestLightEstimate); } // The Y plane is always the first one. var yPlaneInfo = nativeImage.planeInfos[0]; IntPtr yPlaneStart = new IntPtr(nativeImage.planeData.ToInt64() + yPlaneInfo.offset); float intensity; ApiServiceErrorStatus status = TangoClientApi.TangoService_getPixelIntensity( yPlaneStart, (int)nativeImage.width, (int)nativeImage.height, nativeImage.planeInfos[0].rowStride, out intensity); if (status != ApiServiceErrorStatus.Success) { Debug.LogErrorFormat("Call to getPixelIntensity failed: {0}.", status); return(m_latestLightEstimate); } m_latestLightEstimate = new LightEstimate(intensity); UnityTango.Device.ReleaseImageBuffer(nativeImage); return(m_latestLightEstimate); }
/// <summary> /// Connects an ARSession. Note that if user permissions are needed they will be requested and thus this is an /// asynchronous method. /// </summary> /// <param name="sessionConfig">The session configuration.</param> /// <returns>An <c>AsyncTask</c> that completes when the connection has been made or failed. </returns> public AsyncTask <SessionConnectionState> Connect(SessionConfig sessionConfig) { const string ANDROID_CAMERA_PERMISSION_NAME = "android.permission.CAMERA"; if (sessionConfig == null) { ARDebug.LogError("Unable to connect ARSession session due to missing ARSessionConfig."); SessionManager.ConnectionState = SessionConnectionState.MissingConfiguration; return(new AsyncTask <SessionConnectionState>(SessionManager.ConnectionState)); } bool isSupported; ApiServiceErrorStatus status = TangoClientApi.TangoService_IsSupported(out isSupported); if (status.IsTangoFailure()) { ARDebug.LogError("There was an error accessing the ARCore API."); SessionManager.ConnectionState = SessionConnectionState.ConnectToServiceFailed; return(new AsyncTask <SessionConnectionState>(SessionManager.ConnectionState)); } if (!isSupported) { ARDebug.LogError("Device does not support ARCore."); SessionManager.ConnectionState = SessionConnectionState.DeviceNotSupported; return(new AsyncTask <SessionConnectionState>(SessionManager.ConnectionState)); } // We have already connected at least once. if (SessionManager.ConnectionState != SessionConnectionState.Uninitialized) { ARDebug.LogError("Multiple attempts to connect to the ARSession. Note that the ARSession connection " + "spans the lifetime of the application and cannot be reconfigured. This will change in future " + "versions of ARCore."); return(new AsyncTask <SessionConnectionState>(SessionManager.ConnectionState)); } // Create an asynchronous task for the potential permissions flow and service connection. Action <SessionConnectionState> onTaskComplete; var returnTask = new AsyncTask <SessionConnectionState>(out onTaskComplete); // Attempt service connection immediately if permissions are granted. if (AndroidPermissionsManager.IsPermissionGranted(ANDROID_CAMERA_PERMISSION_NAME)) { _ConnectToService(sessionConfig, onTaskComplete); return(returnTask); } // Request needed permissions and attempt service connection if granted. var permissionsArray = new string[] { ANDROID_CAMERA_PERMISSION_NAME }; AndroidPermissionsManager.RequestPermission(permissionsArray).ThenAction((requestResult) => { if (requestResult.IsAllGranted) { _ConnectToService(sessionConfig, onTaskComplete); } else { ARDebug.LogError("ARCore connection failed because a needed permission was rejected."); SessionManager.ConnectionState = SessionConnectionState.UserRejectedNeededPermission; onTaskComplete(SessionManager.ConnectionState); } }); return(returnTask); }
/// <summary> /// Checks if an integer is NOT equal to TANGO_SUCCESS. /// </summary> /// <param name="status">The status integer.</param> /// <returns><c>true</c> if the calling integer is NOT TANGO_SUCCESS, otherwise <c>false</c>.</returns> public static bool IsTangoFailure(this ApiServiceErrorStatus status) { return(status != ApiServiceErrorStatus.Success); }
/// <summary> /// Checks if an integer is equal to TANGO_SUCCESS. /// </summary> /// <param name="status">The status integer.</param> /// <returns><c>true</c> if the calling integer is TANGO_SUCCESS, otherwise <c>false</c>.</returns> public static bool IsTangoSuccess(this ApiServiceErrorStatus status) { return(status == ApiServiceErrorStatus.Success); }