Ejemplo n.º 1
0
        private void Select(int index)
        {
            m_CurrentIndex = (int)Mathf.Repeat(index, m_Pieces.Length);

            m_HighlightedPiece = m_Pieces[m_CurrentIndex];

            for (int i = 0; i < m_Pieces.Length; i++)
            {
                if (m_Pieces[i] == m_HighlightedPiece)
                {
                    m_Pieces[i].transform.localScale = m_SelectionScale * Vector3.one;
                    m_Pieces[i].SetCustomColor(new Color(0f, 1f, 0f, 0.85f));
                }
                else
                {
                    m_Pieces[i].transform.localScale = Vector3.one;
                    m_Pieces[i].SetDefaultColor();
                }
            }
        }
Ejemplo n.º 2
0
        private void Update()
        {
            if (!m_Window.IsOpen)
            {
                return;
            }

            float scrollValue = Player.ScrollValue.Get();

            if (m_SelectedCategory != null)
            {
                // If we're currently choosing a piece from a category, show the highlighted piece's name.
                if (m_ChoosingPiece && m_HighlightedPiece != null)
                {
                    if (!m_PieceName.enabled)
                    {
                        m_PieceName.enabled = true;
                    }

                    m_PieceName.text = m_HighlightedPiece.PieceName;
                }
                // Otherwise show the selected piece's name, if we have one selected.
                else if (!m_ChoosingPiece)
                {
                    if (!m_PieceName.enabled)
                    {
                        m_PieceName.enabled = true;
                    }

                    m_PieceName.text = m_SelectedPiece == null ? "" : m_SelectedPiece.PieceName;
                }

                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    // Close the wheel if we clicked on the None category.
                    if (m_SelectedCategory.CategoryName == "None")
                    {
                        Player.SelectedBuildable.Set(null);
                        Player.SelectBuildable.TryStop();

                        m_PieceName.enabled = false;

                        return;
                    }

                    // If we're choosing a piece, select the highlighted piece.
                    if (m_ChoosingPiece)
                    {
                        m_SelectedPiece = m_HighlightedPiece;

                        Player.SelectedBuildable.Set(m_SelectedPiece.BuildableObject);

                        m_SelectPieceAudio.Play2D();
                    }

                    m_ChoosingPiece = !m_ChoosingPiece;
                }

                if (m_ChoosingPiece)
                {
                    if (!m_SelectedCategory.ShowPieces)
                    {
                        m_SelectedCategory.ShowPieces = true;
                        m_PieceScrollPos = 0f;

                        m_HighlightedPiece = m_SelectedCategory.SelectFirst();
                    }

                    else
                    {
                        m_PieceScrollPos += scrollValue;
                        m_PieceScrollPos  = Mathf.Clamp(m_PieceScrollPos, -m_ScrollThreeshold, m_ScrollThreeshold);

                        if (Mathf.Abs(m_PieceScrollPos - m_ScrollThreeshold * Mathf.Sign(scrollValue)) < Mathf.Epsilon)
                        {
                            m_PieceScrollPos = 0f;

                            if (scrollValue > 0f)
                            {
                                m_HighlightedPiece = m_SelectedCategory.SelectNext();
                            }
                            else
                            {
                                m_HighlightedPiece = m_SelectedCategory.SelectPrevious();
                            }
                        }
                    }

                    return;
                }
                else if (m_SelectedCategory.ShowPieces)
                {
                    m_SelectedCategory.ShowPieces = false;
                }
            }

            m_CategoryScrollPos += scrollValue;
            m_CategoryScrollPos  = Mathf.Clamp(m_CategoryScrollPos, -m_ScrollThreeshold, m_ScrollThreeshold);

            var lastSelectedCateg = m_SelectedCategory;

            if (Mathf.Abs(m_CategoryScrollPos - m_ScrollThreeshold * Mathf.Sign(scrollValue)) < Mathf.Epsilon)
            {
                m_CategoryScrollPos = 0f;

                m_CategoryIndex    = (int)Mathf.Repeat(m_CategoryIndex + (scrollValue > 0f ? 1 : -1), m_Categories.Length);
                m_SelectedCategory = m_Categories[m_CategoryIndex];
            }

            if (lastSelectedCateg != m_SelectedCategory)
            {
                m_Window.Refresh();
                m_RefreshAudio.Play2D();

                m_CategoryName.text = m_SelectedCategory.CategoryName;
            }

            if (m_SelectedCategory != null)
            {
                float angle = Offset + Spacing * m_CategoryIndex;
                m_SelectionHighlight.localPosition = (Quaternion.Euler(Vector3.back * angle) * Vector3.up) * Distance;
                m_SelectionHighlight.localRotation = Quaternion.Euler(Vector3.back * angle);
            }
        }