/// <summary>
        /// The Unity OnEnable() method.
        /// </summary>
        public void OnEnable()
        {
            _timeSinceStart   = 0.0f;
            _isReturning      = false;
            _anchor           = null;
            _qualityIndicator = null;
            _pendingCloudAnchors.Clear();
            _cachedCloudAnchors.Clear();

            InstructionBar.SetActive(true);
            NamePanel.SetActive(false);
            InputFieldWarning.SetActive(false);
            ShareButton.gameObject.SetActive(false);
            UpdatePlaneVisibility(true);

            switch (Controller.Mode)
            {
            case PersistentCloudAnchorsController.ApplicationMode.Ready:
                ReturnToHomePage("Invalid application mode, returning to home page...");
                break;

            case PersistentCloudAnchorsController.ApplicationMode.Hosting:
            case PersistentCloudAnchorsController.ApplicationMode.Resolving:
                InstructionText.text = "Detecting flat surface...";
                DebugText.text       = "ARCore is preparing for " + Controller.Mode;
                break;
            }
        }
Beispiel #2
0
        private void PerformHitTest(Vector2 touchPos)
        {
            List <ARRaycastHit> hitResults = new List <ARRaycastHit>();

            Controller.RaycastManager.Raycast(
                touchPos, hitResults, TrackableType.PlaneWithinPolygon);

            // If there was an anchor placed, then instantiate the corresponding object.
            var planeType = PlaneAlignment.HorizontalUp;

            if (hitResults.Count > 0)
            {
                ARPlane plane = Controller.PlaneManager.GetPlane(hitResults[0].trackableId);
                if (plane == null)
                {
                    Debug.LogWarningFormat("Failed to find the ARPlane with TrackableId {0}",
                                           hitResults[0].trackableId);
                    return;
                }

                planeType = plane.alignment;
                var hitPose = hitResults[0].pose;
                if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    // Point the hitPose rotation roughly away from the raycast/camera
                    // to match ARCore.
                    hitPose.rotation.eulerAngles =
                        new Vector3(0.0f, Controller.MainCamera.transform.eulerAngles.y, 0.0f);
                }

#pragma warning disable CS0618 // TODO(b/181068602): Modify the way of adding anchor.
                _anchor = Controller.AnchorManager.AddAnchor(hitPose);
#pragma warning restore CS0618
            }

            if (_anchor != null)
            {
                Instantiate(CloudAnchorPrefab, _anchor.transform);

                // Attach map quality indicator to this anchor.
                var indicatorGO =
                    Instantiate(MapQualityIndicatorPrefab, _anchor.transform);
                _qualityIndicator = indicatorGO.GetComponent <MapQualityIndicator>();
                _qualityIndicator.DrawIndicator(planeType, Controller.MainCamera);

                InstructionText.text = " To save this location, walk around the object to " +
                                       "capture it from different angles";
                DebugText.text = "Waiting for sufficient mapping quaility...";

                // Hide plane generator so users can focus on the object they placed.
                UpdatePlaneVisibility(false);
            }
        }
        /// <summary>
        /// The Unity OnDisable() method.
        /// </summary>
        public void OnDisable()
        {
            if (_qualityIndicator != null)
            {
                Destroy(_qualityIndicator.gameObject);
                _qualityIndicator = null;
            }

            if (_anchor != null)
            {
                Destroy(_anchor.gameObject);
                _anchor = null;
            }

            if (_pendingCloudAnchors.Count > 0)
            {
                foreach (var anchor in _pendingCloudAnchors)
                {
                    Destroy(anchor.gameObject);
                }

                _pendingCloudAnchors.Clear();
            }

            if (_cachedCloudAnchors.Count > 0)
            {
                foreach (var anchor in _cachedCloudAnchors)
                {
                    Destroy(anchor.gameObject);
                }

                _cachedCloudAnchors.Clear();
            }

            UpdatePlaneVisibility(false);
        }