Esempio n. 1
0
    /// <summary>
    /// Gets the tracked image anchor by name.
    /// </summary>
    /// <returns>The tracked image anchor.</returns>
    /// <param name="imageAnchorName">Image anchor name.</param>
    public GameObject GetTrackedImageAnchorByName(string imageAnchorName)
    {
        if (arInterface != null)
        {
            return(arInterface.GetTrackedImageAnchorByName(imageAnchorName));
        }

        return(null);
    }
Esempio n. 2
0
    /// <summary>
    /// Gets the image anchor name that is nearest to the AR-camera.
    /// </summary>
    /// <returns>The name of the found image anchor, or empty string.</returns>
    public string GetNearestImageAnchorName()
    {
        if (arInterface != null)
        {
            Camera        mainCamera    = arInterface.GetMainCamera();
            List <string> alAnchorNames = GetTrackedImageAnchorNames();

            if (mainCamera != null && alAnchorNames != null)
            {
                Vector3 cameraPos = mainCamera.transform.position;

                float minDistance      = float.MaxValue;
                int   foundAnchorIndex = -1;

                for (int i = 0; i < alAnchorNames.Count; i++)
                {
                    string     anchorName = alAnchorNames[i];
                    GameObject anchorObj  = arInterface.GetTrackedImageAnchorByName(anchorName);

                    if (anchorObj != null)
                    {
                        Vector3 anchorPos        = anchorObj.transform.position;
                        float   camToAnchorDist2 = (anchorPos - cameraPos).sqrMagnitude;

                        if (camToAnchorDist2 < minDistance)
                        {
                            minDistance      = camToAnchorDist2;
                            foundAnchorIndex = i;
                        }
                    }
                }

                return(foundAnchorIndex >= 0 ? alAnchorNames[foundAnchorIndex] : string.Empty);
            }
        }

        return(string.Empty);
    }