Inheritance: ScriptableObject
Exemple #1
0
        /// <summary>
        /// Connects to the ARCore service.
        /// </summary>
        /// <param name="sessionConfig">The session configuration to connect with.</param>
        /// <param name="onComplete">A callback for when the result of the connection attempt is known.</param>
        private void _ConnectToService(SessionConfig sessionConfig, Action <SessionConnectionState> onComplete)
        {
            // Connect the ARCore session.
            UnityTango.Config tangoConfig = _GetSessionTangoConfiguration(sessionConfig);
            if (!UnityTango.Device.Connect(tangoConfig))
            {
                ARDebug.LogError("Failed to connect the ARSession.");
                SessionManager.ConnectionState = SessionConnectionState.ConnectToServiceFailed;
                onComplete(SessionConnectionState.ConnectToServiceFailed);
                return;
            }

            if (sessionConfig.m_enableARBackground)
            {
                // _SetupVideoOverlay();
            }

            SessionManager.ConnectionState = SessionConnectionState.Connected;
            onComplete(SessionManager.ConnectionState);
        }
Exemple #2
0
        private UnityTango.Config _GetSessionTangoConfiguration(SessionConfig sessionConfig)
        {
            const string DRIFT_CORRECTION_FLAG    = "config_enable_drift_correction";
            const string PLANE_DETECTION_FLAG     = "config_experimental_enable_plane_detection";
            const string POINTCLOUD_FROM_VIO_FLAG = "config_experimental_enable_depth_from_vio";
            const string POINTCLOUD_FLAG          = "config_enable_depth";
            const string POINTCLOUD_TYPE_FLAG     = "config_depth_mode";
            const int    XYZC_POINTCLOUD_MODE     = 0;

            UnityTango.Config tangoConfig = new UnityTango.Config();

            // Set defaults
            tangoConfig.enableMotionTracking = true;
            tangoConfig.enableDepth          = false;
            tangoConfig.enableColorCamera    = sessionConfig.m_enableARBackground;
            tangoConfig.areaLearningMode     = UnityTango.AreaLearningMode.None;
            tangoConfig.AddConfigParameter(DRIFT_CORRECTION_FLAG, true);
            tangoConfig.AddConfigParameter(POINTCLOUD_FROM_VIO_FLAG, sessionConfig.m_enablePointcloud);
            tangoConfig.AddConfigParameter(POINTCLOUD_TYPE_FLAG, XYZC_POINTCLOUD_MODE);
            tangoConfig.AddConfigParameter(POINTCLOUD_FLAG, sessionConfig.m_enablePointcloud);
            tangoConfig.AddConfigParameter(PLANE_DETECTION_FLAG, sessionConfig.m_enablePlaneFinding);

            return(tangoConfig);
        }
Exemple #3
0
        /// <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);
        }