예제 #1
0
    /// <summary>
    /// The Unity Update method.
    /// </summary>
    public void Update()
    {
        _UpdateApplicationLifecycle();

        // Check that motion tracking is tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }

        // Get updated augmented images for this frame.
        Session.GetTrackables <AugmentedImage> (m_TempAugmentedImages, TrackableQueryFilter.Updated);

        // create objects on each augmented image
        foreach (var image in m_TempAugmentedImages)
        {
            ARInteractable visualizer = null;
            m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
            if (image.TrackingState == TrackingState.Tracking && visualizer == null)
            {
                // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                Anchor anchor = image.CreateAnchor(image.CenterPose);
                Prefabs.TryGetValue(image.Name, out currentObj);

                visualizer = (ARInteractable)Instantiate(currentObj, anchor.transform);
                var targetPosition = Camera.main.transform.position;
                targetPosition.y = visualizer.transform.position.y;
                visualizer.transform.LookAt(targetPosition);
                visualizer.Image = image;

                m_Visualizers.Add(image.DatabaseIndex, visualizer);
            }
            else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
            {
                m_Visualizers.Remove(image.DatabaseIndex);
                GameObject.Destroy(visualizer.gameObject);
            }
        }

        // Show the fit-to-scan overlay if there are no images that are Tracking.
        foreach (var visualizer in m_Visualizers.Values)
        {
            if (visualizer.Image.TrackingState == TrackingState.Tracking)
            {
                FitToScanOverlay.SetActive(false);
                return;
            }
        }

        FitToScanOverlay.SetActive(true);
    }
예제 #2
0
    public bool SpawnItemByType(ItemType typeToSpawn, Vector3 spawnPosition, Quaternion spawnRotation = default(Quaternion), Transform parent = null, bool ignoreRaycast = true)
    {
        if (!_prefabDictionary.TryGetValue(typeToSpawn, out var prefab))
        {
            return(false);
        }

        _overlapResults[0] = null;
        if (!ignoreRaycast)
        {
            Physics.OverlapSphereNonAlloc(spawnPosition, OVERLAP_RADIUS, _overlapResults, GroundlessLayerMask);
            if (_overlapResults[0])
            {
                return(false);
            }
        }
        Instantiate(prefab, spawnPosition, spawnRotation, parent);
        return(true);
    }