示例#1
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Initilaize the buttons in the array.
        /// </summary>
        private void InitButton()
        {
            JCS_RollSelectorButton currentBtn = null;
            int indexCounter = 0;

            JCS_RollSelectorButton[] buttons = new JCS_RollSelectorButton[mButtons.Length];

            for (int index = 0;
                 index < mButtons.Length;
                 ++index)
            {
                currentBtn = mButtons[index];

                if (currentBtn == null)
                {
                    JCS_Debug.LogError(
                        "Missing jcs_button assign in the inspector...");
                    continue;
                }

                // set to array object to know this handler.
                currentBtn.SetRollSelector(this);


                Vector3 newPos = this.transform.localPosition;

                bool isEven = JCS_Mathf.IsEven(index);

                if (index != 0)
                {
                    currentBtn.SetInteractable(false);
                }
                else
                {
                    // the first one (center)
                    mFocusBtn = currentBtn;
                    JCS_Utility.MoveToTheLastChild(mFocusBtn.transform);
                    currentBtn.SetInteractable(true);
                    mLastScrollIndex = currentBtn.ScrollIndex;
                }

                if (!isEven)
                {
                    ++indexCounter;
                }

                float intervalDistance = mSpacing * indexCounter;

                switch (mDimension)
                {
                case JCS_2DDimensions.VERTICAL:
                {
                    if (mPanelRoot != null)
                    {
                        intervalDistance /= mPanelRoot.PanelDeltaWidthRatio;
                    }

                    if (isEven)
                    {
                        newPos.y += intervalDistance;
                    }
                    else
                    {
                        newPos.y -= intervalDistance;
                    }
                }
                break;

                case JCS_2DDimensions.HORIZONTAL:
                {
                    if (mPanelRoot != null)
                    {
                        intervalDistance /= mPanelRoot.PanelDeltaHeightRatio;
                    }

                    if (isEven)
                    {
                        newPos.x += intervalDistance;
                    }
                    else
                    {
                        newPos.x -= intervalDistance;
                    }
                }
                break;
                }

                currentBtn.GetRectTransfom().localPosition = newPos;

                // set friction.
                currentBtn.SimpleTrackAction.Friction = mScrollFriction;
                // set tracking
                currentBtn.SetTrackPosition();

                // get the correct order
                int correctIndex = 0;

                if (isEven)
                {
                    correctIndex = ((mButtons.Length - 1) - index) / 2;
                }
                else
                {
                    correctIndex = ((mButtons.Length) + index) / 2;
                }

                buttons[correctIndex] = currentBtn;
            }

            mButtons = buttons;

            // initialzie the scroll index.
            for (int index = 0;
                 index < mButtons.Length;
                 ++index)
            {
                currentBtn = mButtons[index];

                // set index.
                currentBtn.ScrollIndex = index;
            }
        }