Example #1
0
 public void RemoveTarget(IsNavigationTarget target)
 {
     if (m_NavigationTargets.Contains(target))
     {
         m_NavigationTargets.Remove(target);
     }
 }
Example #2
0
 public void AddTarget(IsNavigationTarget target)
 {
     if (!m_NavigationTargets.Contains(target))
     {
         m_NavigationTargets.Add(target);
     }
 }
Example #3
0
        public void InitializeNavigation(NavigationTargetListButton button)
        {
            if (!m_managerInitialized)
            {
                Debug.LogWarning("NavigationManager: Navigation Manager not properly initialized.");
                return;
            }

            m_targetTransform  = button.targetObject.transform;
            m_NavigationTarget = button.targetObject.GetComponent <IsNavigationTarget>();
            TryToFindPath(m_NavigationTarget);
        }
Example #4
0
        public void GenerateButtons()
        {
            if (m_Buttons.Count > 0)
            {
                DestroyButtons();
            }

            // loops through all navigation categories
            foreach (KeyValuePair <NavigationTargets.NavigationCategory, List <GameObject> > entry in NavigationTargets.NavigationTargetsDict)
            {
                // loops through all targets in each category
                foreach (GameObject go in entry.Value)
                {
                    IsNavigationTarget isNavigationTarget = go.GetComponent <IsNavigationTarget>();
                    string             targetName         = isNavigationTarget.targetName;
                    Sprite             icon = isNavigationTarget.icon;

                    GameObject button = Instantiate(m_ButtonTemplate, m_ContentParent);
                    m_Buttons.Add(button);
                    button.SetActive(true);
                    button.name = "button " + targetName;

                    NavigationTargetListButton navigationTargetListButton = button.GetComponent <NavigationTargetListButton>();
                    navigationTargetListButton.SetText(targetName);
                    navigationTargetListButton.SetIcon(icon);
                    navigationTargetListButton.SetTarget(go);
                }
            }

            // calculate lists RectTransform size
            float         x             = m_ButtonTemplate.GetComponent <RectTransform>().sizeDelta.x;
            float         y             = m_ButtonTemplate.GetComponent <RectTransform>().sizeDelta.y *Mathf.Min(m_Buttons.Count, m_MaxButtonsOnScreen);
            RectTransform rectTransform = GetComponent <RectTransform>();

            rectTransform.sizeDelta = new Vector2(x, y);

            ScrollToTop();
        }
Example #5
0
        public void TryToFindPath(IsNavigationTarget navigationTarget)
        {
            List <Vector3> corners;

            // Convert to Unity's world space coordinates to use NavMesh
            Vector3 startPosition  = m_playerTransform.position;
            Vector3 targetPosition = navigationTarget.position;

            Vector3 delta            = targetPosition - startPosition;
            float   distanceToTarget = new Vector3(delta.x, delta.y, delta.z).magnitude;

            if (distanceToTarget < m_ArrivedDistanceThreshold)
            {
                m_navigationActive = false;

                m_navigationState = NavigationState.NotNavigating;
                UpdateNavigationUI(m_navigationState);

                DisplayArrivedNotification();
                return;
            }

            switch (m_navigationMode)
            {
            case NavigationMode.NavMesh:

                startPosition  = ARSpaceToUnity(m_arSpace.transform, m_arSpace.initialOffset, startPosition);
                targetPosition = ARSpaceToUnity(m_arSpace.transform, m_arSpace.initialOffset, targetPosition);

                corners = FindPathNavMesh(startPosition, targetPosition);
                if (corners.Count >= 2)
                {
                    m_navigationActive = true;

                    m_navigationState = NavigationState.Navigating;
                    UpdateNavigationUI(m_navigationState);

                    m_navigationPath.GeneratePath(corners, m_arSpace.transform.up);
                    m_navigationPath.pathWidth = m_pathWidth;
                }
                else
                {
                    Mapping.NotificationManager.Instance.GenerateNotification("Path to target not found.");
                    UpdateNavigationUI(m_navigationState);
                }
                break;

            case NavigationMode.Graph:

                corners = m_NavigationGraphManager.FindPath(startPosition, targetPosition);

                if (corners.Count >= 2)
                {
                    m_navigationActive = true;

                    m_navigationState = NavigationState.Navigating;
                    UpdateNavigationUI(m_navigationState);

                    m_navigationPath.GeneratePath(corners, m_arSpace.transform.up);
                    m_navigationPath.pathWidth = m_pathWidth;
                }
                else
                {
                    Mapping.NotificationManager.Instance.GenerateNotification("Path to target not found.");
                    UpdateNavigationUI(m_navigationState);
                }
                break;
            }
        }