Ejemplo n.º 1
0
        public void OnDrawGizmos()
        {
            for (int i = 0; i < CurrentSearches.Count; i++)
            {
                WidgetSearch w = CurrentSearches [i];
                w.FinalScore        = WidgetSearch.CalculateScore(w);
                CurrentSearches [i] = w;
            }
            CurrentSearches.Sort();

            Gizmos.color = Color.Lerp(Color.magenta, Color.cyan, 0.5f);
            Gizmos.DrawWireCube(LastBrowserBounds.center, LastBrowserBounds.size);

            if (LastDirection == SearchDirection.Left || LastDirection == SearchDirection.Right)
            {
                Gizmos.color = Color.Lerp(Color.red, Color.yellow, 0.5f);
                Gizmos.DrawLine(CurrentSearch.WorldBounds.max + (Vector3.left * 100f), CurrentSearch.WorldBounds.max + (Vector3.right * 100f));
                Gizmos.color = Color.blue;
                Gizmos.DrawLine(CurrentSearch.WorldBounds.min + (Vector3.left * 100f), CurrentSearch.WorldBounds.min + (Vector3.right * 100f));
            }
            else
            {
                Gizmos.color = Color.Lerp(Color.red, Color.yellow, 0.5f);
                Gizmos.DrawLine(CurrentSearch.WorldBounds.max + (Vector3.down * 100f), CurrentSearch.WorldBounds.max + (Vector3.up * 100f));
                Gizmos.color = Color.blue;
                Gizmos.DrawLine(CurrentSearch.WorldBounds.min + (Vector3.down * 100f), CurrentSearch.WorldBounds.min + (Vector3.up * 100f));
            }

            Gizmos.color = Color.yellow;
            Gizmos.DrawSphere(ScreenSearchOrigin, 0.05f);
            Gizmos.color = Color.red;
            Gizmos.DrawSphere(LastMouseCursorResult, 0.05f);
            Gizmos.color = Color.green;
            Gizmos.DrawWireCube(CurrentWidgetBounds.center, CurrentWidgetBounds.size);
            Gizmos.DrawWireCube(CurrentWidgetBounds.center, CurrentWidgetBounds.size * 1.005f);
            Gizmos.color = Color.red;
            Gizmos.DrawWireCube(PreviousSearchBounds.center, PreviousSearchBounds.size);
            Gizmos.color = Color.cyan;
            switch (LastDirection)
            {
            default:
            case SearchDirection.Up:
                DrawArrow.ForGizmo(PreviousSearchBounds.center, Vector3.up * 0.25f);
                break;

            case SearchDirection.Down:
                DrawArrow.ForGizmo(PreviousSearchBounds.center, Vector3.down * 0.25f);
                break;

            case SearchDirection.Left:
                DrawArrow.ForGizmo(PreviousSearchBounds.center, Vector3.left * 0.25f);
                break;

            case SearchDirection.Right:
                DrawArrow.ForGizmo(PreviousSearchBounds.center, Vector3.right * 0.25f);

                break;
            }
            Gizmos.color = Color.magenta;
            if (LastSearchDirection != Vector3.zero)
            {
                DrawArrow.ForGizmo(PreviousSearchBounds.center + Vector3.up * 0.25f, LastSearchDirection * 0.35f, 0.2f, 25f);
            }

            if (CurrentSearches.Count > 0)
            {
                //skip the first one
                Color searchColor = Color.green;
                for (int i = 0; i < CurrentSearches.Count; i++)
                {
                    WidgetSearch s           = CurrentSearches [i];
                    Bounds       worldBounds = s.WorldBounds;
                    if (!s.Widget.IsEmpty)
                    {
                        worldBounds = s.Widget.BoxCollider.bounds;
                    }
                    float normalizedAmount = (float)i / (float)(CurrentSearches.Count);
                    TextGizmo.Draw(SearchCamera, worldBounds.center + Vector3.up * 0.01f, s.Dot.ToString());
                    //TextGizmo.Draw(SearchCamera, s.WorldBounds.center + Vector3.up * 0.01f, Mathf.FloorToInt(s.FinalScore * 1000).ToString());
                    //TextGizmo.Draw(SearchCamera, s.WorldBounds.center + Vector3.up * 0.01f, Mathf.FloorToInt(s.PrimaryOverlap).ToString());
                    if (i == 0)
                    {
                        searchColor  = Color.green;
                        Gizmos.color = searchColor;
                        Gizmos.DrawWireCube(worldBounds.center, worldBounds.size * 0.98f);
                        Gizmos.DrawWireCube(worldBounds.center, worldBounds.size * 1.015f);
                    }
                    else
                    {
                        searchColor = Colors.Alpha(Colors.BlendThree(Color.Lerp(Color.green, Color.yellow, 0.2f), Color.yellow, Color.magenta, normalizedAmount), 0.5f);
                    }
                    Gizmos.color = searchColor;
                    Gizmos.DrawCube(worldBounds.center, worldBounds.size);
                    Gizmos.color = Colors.Alpha(searchColor, 0.5f);
                    Gizmos.DrawWireCube(worldBounds.center, worldBounds.size * 0.99f);
                }
            }
        }
Ejemplo n.º 2
0
        protected void DumbSearch(SearchDirection direction)
        {
            if (mDoingSearch)
            {
                return;
            }

            mDoingSearch = true;

            CurrentObjects.Clear();
            //if the cutscene is active, see if there are any cutscene interfaces
            if (Cutscene.IsActive)
            {
                Cutscene.GetActiveInterfaceObjects(CurrentObjects, -1);
            }
            if (VRManager.VRMode && GUIManager.ShowCursor)
            {
                VRManager.Get.GetActiveInterfaceObjects(CurrentObjects, -1);
            }

            CurrentSearches.Clear();
            LastDirection = direction;
            FrontiersInterface.Widget nextObject = new FrontiersInterface.Widget(-1);
            WidgetSearch search;
            Bounds       checkWidgetBounds  = new Bounds();
            Vector3      widgetScreenPos    = Vector3.zero;
            Vector3      widgetWorldPos     = Vector3.zero;
            Vector3      widgetDir          = Vector3.zero;
            Vector3      primaryMax         = SearchCamera.WorldToScreenPoint(CurrentSearch.WorldBounds.max);
            Vector3      primaryMin         = SearchCamera.WorldToScreenPoint(CurrentSearch.WorldBounds.min);
            Vector3      searchMin          = Vector3.zero;
            Vector3      searchMax          = Vector3.zero;
            float        primaryAxis        = 0;
            float        secondaryAxis      = 0;
            float        currentSize        = 0f;
            float        searchSize         = 0f;
            float        smallestProportion = 0f;

            switch (direction)
            {
            default:
            case SearchDirection.Up:
            case SearchDirection.Down:
                primaryAxis   = CurrentSearch.ScreenBounds.center.y;
                secondaryAxis = CurrentSearch.ScreenBounds.center.x;
                currentSize   = primaryMax.x - primaryMin.x;
                break;

            case SearchDirection.Left:
            case SearchDirection.Right:
                primaryAxis   = CurrentSearch.ScreenBounds.center.x;
                secondaryAxis = CurrentSearch.ScreenBounds.center.y;
                currentSize   = primaryMax.y - primaryMin.y;
                break;
            }
            if (CurrentActiveInterface != null)
            {
                CurrentActiveInterface.GetActiveInterfaceObjects(CurrentObjects, -1);
                if (CurrentActiveInterface.Type == InterfaceType.Primary)
                {
                    //hacky thing - get the player status
                    GUIPlayerStatusInterface.Get.GetActiveInterfaceObjects(CurrentObjects, -1);
                }
            }

            for (int i = CurrentObjects.LastIndex(); i >= 0; i--)
            {
                nextObject = CurrentObjects [i];
                if (nextObject.BoxCollider == CurrentSearch.Widget.BoxCollider || nextObject.BoxCollider == null || !nextObject.BoxCollider.enabled)
                {
                    //remove 'dead' objects so we don't have to worry about last-minute search being valid
                    CurrentObjects.RemoveAt(i);
                }
            }

            for (int i = 0; i < CurrentObjects.Count; i++)
            {
                nextObject      = CurrentObjects [i];
                widgetWorldPos  = nextObject.BoxCollider.bounds.center;
                widgetScreenPos = SearchCamera.WorldToScreenPoint(widgetWorldPos);
                if (IsOffScreen(widgetScreenPos))
                {
                    continue;
                }
                //get our search info from the object
                search                     = new WidgetSearch(nextObject);
                search.WorldBounds         = search.Widget.BoxCollider.bounds;
                widgetScreenPos.z          = 0f;
                widgetDir                  = (widgetScreenPos - ScreenSearchOrigin).normalized;
                searchMin                  = SearchCamera.WorldToScreenPoint(search.WorldBounds.min);
                searchMax                  = SearchCamera.WorldToScreenPoint(search.WorldBounds.max);
                search.ScreenBounds.min    = searchMin;
                search.ScreenBounds.max    = searchMax;
                search.ScreenBounds.center = widgetScreenPos;

                switch (direction)
                {
                default:
                case SearchDirection.Up:
                    search.PrimaryAxis = Mathf.Clamp(widgetScreenPos.y - primaryAxis, 0, WidgetSearch.gMaxPrimaryAxis);
                    if (search.PrimaryAxis <= 0)
                    {
                        break;
                    }
                    search.Dot           = Vector3.Dot(Vector3.up, widgetDir) * WidgetSearch.gMaxDot;
                    searchSize           = searchMax.x - searchMin.x;
                    search.SecondaryAxis = widgetScreenPos.x;
                    if (search.SecondaryAxis < secondaryAxis)
                    {
                        search.SecondaryAxis = Mathf.Clamp(secondaryAxis - search.SecondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    else
                    {
                        search.SecondaryAxis = Mathf.Clamp(search.SecondaryAxis - secondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    if (primaryMax.x < searchMin.x || searchMax.x < primaryMin.x)
                    {
                        search.PrimaryOverlap = 0;
                    }
                    else
                    {
                        if (searchSize < currentSize)
                        {
                            smallestProportion = searchSize / currentSize;
                        }
                        else
                        {
                            smallestProportion = currentSize / searchSize;
                        }
                        search.PrimaryOverlap = (Mathf.Clamp(primaryMax.x - searchMin.x, 0, searchSize) / searchSize) * smallestProportion;
                    }
                    search.Distance   = Mathf.Clamp(Vector3.Distance(widgetScreenPos, ScreenSearchOrigin), 0, WidgetSearch.gMaxDist);
                    search.FinalScore = WidgetSearch.CalculateScore(search);
                    CurrentSearches.Add(search);
                    break;

                case SearchDirection.Down:
                    search.PrimaryAxis = Mathf.Clamp(primaryAxis - widgetScreenPos.y, 0, WidgetSearch.gMaxPrimaryAxis);
                    if (search.PrimaryAxis <= 0)
                    {
                        break;
                    }
                    search.Dot           = Vector3.Dot(Vector3.down, widgetDir) * WidgetSearch.gMaxDot;
                    searchSize           = searchMax.x - searchMin.x;
                    search.SecondaryAxis = widgetScreenPos.x;
                    if (search.SecondaryAxis < secondaryAxis)
                    {
                        search.SecondaryAxis = Mathf.Clamp(secondaryAxis - search.SecondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    else
                    {
                        search.SecondaryAxis = Mathf.Clamp(search.SecondaryAxis - secondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    if (primaryMax.x < searchMin.x || searchMax.x < primaryMin.x)
                    {
                        search.PrimaryOverlap = 0;
                    }
                    else
                    {
                        if (searchSize < currentSize)
                        {
                            smallestProportion = searchSize / currentSize;
                        }
                        else
                        {
                            smallestProportion = currentSize / searchSize;
                        }
                        search.PrimaryOverlap = (Mathf.Clamp(primaryMax.x - searchMin.x, 0, searchSize) / searchSize) * smallestProportion;
                    }
                    search.Distance   = Mathf.Clamp(Vector3.Distance(widgetScreenPos, ScreenSearchOrigin), 0, WidgetSearch.gMaxDist);
                    search.FinalScore = WidgetSearch.CalculateScore(search);
                    CurrentSearches.Add(search);
                    break;

                case SearchDirection.Left:
                    search.PrimaryAxis = Mathf.Clamp(primaryAxis - widgetScreenPos.x, 0, WidgetSearch.gMaxPrimaryAxis);
                    if (search.PrimaryAxis <= 0)
                    {
                        break;
                    }
                    search.Dot           = Vector3.Dot(Vector3.left, widgetDir) * WidgetSearch.gMaxDot;
                    searchSize           = searchMax.y - searchMin.y;
                    search.SecondaryAxis = widgetScreenPos.y;
                    if (search.SecondaryAxis < secondaryAxis)
                    {
                        search.SecondaryAxis = Mathf.Clamp(secondaryAxis - search.SecondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    else
                    {
                        search.SecondaryAxis = Mathf.Clamp(search.SecondaryAxis - secondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    if (primaryMax.y < searchMin.y || searchMax.y < primaryMin.y)
                    {
                        search.PrimaryOverlap = 0;
                    }
                    else
                    {
                        if (searchSize < currentSize)
                        {
                            smallestProportion = searchSize / currentSize;
                        }
                        else
                        {
                            smallestProportion = currentSize / searchSize;
                        }
                        search.PrimaryOverlap = (Mathf.Clamp(primaryMax.y - searchMin.y, 0, searchSize) / searchSize) * smallestProportion;
                    }
                    search.Distance   = Mathf.Clamp(Vector3.Distance(widgetScreenPos, ScreenSearchOrigin), 0, WidgetSearch.gMaxDist);
                    search.FinalScore = WidgetSearch.CalculateScore(search);
                    CurrentSearches.Add(search);
                    break;

                case SearchDirection.Right:
                    search.PrimaryAxis = Mathf.Clamp(widgetScreenPos.x - primaryAxis, 0, WidgetSearch.gMaxPrimaryAxis);
                    if (search.PrimaryAxis <= 0)
                    {
                        break;
                    }
                    search.Dot           = Vector3.Dot(Vector3.right, widgetDir) * WidgetSearch.gMaxDot;
                    searchSize           = searchMax.y - searchMin.y;
                    search.SecondaryAxis = widgetScreenPos.y;
                    if (search.SecondaryAxis < secondaryAxis)
                    {
                        search.SecondaryAxis = Mathf.Clamp(secondaryAxis - search.SecondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    else
                    {
                        search.SecondaryAxis = Mathf.Clamp(search.SecondaryAxis - secondaryAxis, 0, WidgetSearch.gMaxSecondaryAxis);
                    }
                    if (primaryMax.y < searchMin.y || searchMax.y < primaryMin.y)
                    {
                        search.PrimaryOverlap = 0;
                    }
                    else
                    {
                        //overlap is a normalized percentage of overlap multiplied by the proportion of one button size to the other
                        if (searchSize < currentSize)
                        {
                            smallestProportion = searchSize / currentSize;
                        }
                        else
                        {
                            smallestProportion = currentSize / searchSize;
                        }
                        search.PrimaryOverlap = (Mathf.Clamp(primaryMax.y - searchMin.y, 0, searchSize) / searchSize) * smallestProportion;
                    }
                    search.Distance   = Mathf.Clamp(Vector3.Distance(widgetScreenPos, ScreenSearchOrigin), 0, WidgetSearch.gMaxDist);
                    search.FinalScore = WidgetSearch.CalculateScore(search);
                    CurrentSearches.Add(search);
                    break;
                }
            }
            //this will sort them so we can pick the best one
            //best one is at 0, worse one is last
            //we keep the rest for debugging purposes
            CurrentSearches.Sort();
            if (CurrentSearches.Count == 0 && CurrentObjects.Count > 0)
            {
                //just pick the first one
                search              = new WidgetSearch(CurrentObjects [0]);
                search.Widget       = CurrentObjects [0];
                search.WorldBounds  = search.Widget.BoxCollider.bounds;
                search.ScreenBounds = new Bounds(search.Widget.SearchCamera.WorldToScreenPoint(search.WorldBounds.center), Vector3.one);
                CurrentSearches.Add(search);
            }
            mDoingSearch = false;
        }