Exemplo n.º 1
0
        // Down
        override protected void OnPointerDownBasic(PointerEventData tPointer, bool tFromScrollView)
        {
            base.OnPointerDownBasic(tPointer, tFromScrollView);

            m_PointerId = tPointer.pointerId;

            m_BasePosition = GetLocalPosition(tPointer);

            frame.SetPosition(m_BasePosition);
            frame.SetSize(frameWidth, frameWidth);

            m_Volume        = 0;
            m_Direction     = Vector2.zero;
            m_DeltaPosition = Vector2.zero;

            float thumbWidth = frameWidth * thumbScale;

            thumb.SetPosition(0, 0);
            thumb.SetSize(thumbWidth, thumbWidth);

            frame.SetActive(true);

            if (m_OnValueChangedAction != null)
            {
                m_OnValueChangedAction(Identity, this, m_Volume, m_Direction);
            }
        }
Exemplo n.º 2
0
        //---------------------------------------------

        // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        override protected void OnBuild(string option = "")
        {
            Toggle toggle = _toggle;

            if (toggle == null)
            {
                toggle = gameObject.AddComponent <Toggle>();
            }
            if (toggle == null)
            {
                // 異常
                return;
            }

            //-------------------------

            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                SetSize(tSize.y * 0.25f, tSize.y * 0.05f);
            }

            // Background
            background = AddView <UIImage>("Background");
            background.SetAnchorToLeftMiddle();
            background.SetPosition(_h * 0.5f, 0);
            background.SetSize(_h, _h);
            background.sprite     = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame");
            background.type       = Image.Type.Sliced;
            background.fillCenter = true;

            background.raycastTarget = true;                    // 必須

            if (isCanvasOverlay == true)
            {
                background.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            toggle.targetGraphic = background._image;

            // Checkmark
            checkmark = background.AddView <UIImage>("Checkmark");
            checkmark.SetAnchorToCenter();
            checkmark.SetSize(_h, _h);
            checkmark.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultCheck");

            if (isCanvasOverlay == true)
            {
                checkmark.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            toggle.graphic = checkmark._image;

            // Label
            label = AddView <UIText>("Label");
            label.SetAnchorToLeftMiddle();
            label.SetPosition(_h * 1.2f, 0);
            label.SetPivot(0, 0.5f);
            //		label.text = "Toggle" ;
            label.fontSize = ( int )(_h * 0.75f);

            if (isCanvasOverlay == true)
            {
                label.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            //----------------------------------------

            // 親にグループがアタッチされていればグループとみなす
            ToggleGroup toggleGroup = GetComponentInParent <ToggleGroup>();

            if (toggleGroup != null)
            {
                toggle.group = toggleGroup;
            }

            //----------------------------------------

            ResetRectTransform();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        /// </summary>
        /// <param name="tOption"></param>
        override protected void OnBuild(string tOption = "")
        {
            Dropdown tDropdown = _dropdown;

            if (tDropdown == null)
            {
                tDropdown = gameObject.AddComponent <Dropdown>();
            }
            if (tDropdown == null)
            {
                // 異常
                return;
            }

            Image tImage = _image;

            //------------------------------------------

            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                SetSize(tSize.y * 0.28f, tSize.y * 0.05f);
            }

            ColorBlock tColorBlock = tDropdown.colors;

            tColorBlock.fadeDuration = 0.1f;
            tDropdown.colors         = tColorBlock;

            tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton");
            tImage.color  = Color.white;
            tImage.type   = Image.Type.Sliced;

            // 初期のオプションを追加する
            Dropdown.OptionData tDataA = new Dropdown.OptionData();
            tDataA.text = "Option A";
            tDropdown.options.Add(tDataA);
            Dropdown.OptionData tDataB = new Dropdown.OptionData();
            tDataB.text = "Option B";
            tDropdown.options.Add(tDataB);
            Dropdown.OptionData tDataC = new Dropdown.OptionData();
            tDataC.text = "Option C";
            tDropdown.options.Add(tDataC);

            // Label
            UIText tLabel = AddView <UIText>("Label", "FitOff");

            tLabel.text = tDropdown.options[0].text;
            tLabel.SetAnchorToStretch();
            tLabel.SetMargin(10, 25, 7, 6);
            tLabel._text.alignment = TextAnchor.MiddleLeft;
//			tLabel._text.fontSize = 0 ;
            tLabel._text.color = new Color32(50, 50, 50, 255);

            tDropdown.captionText = tLabel._text;


            // Arrow
            UIImage tArrow = AddView <UIImage>("Arrow");

            tArrow.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultArrowDown");
            tArrow.color  = Color.white;
            tArrow.type   = Image.Type.Sliced;

            tArrow.SetAnchorToRightMiddle();
            tArrow.SetPosition(-18, 0);
            float s = _h * 0.6f;

            tArrow.SetSize(s, s);


            // ScrollView
            UIScrollView tScrollView = AddView <UIScrollView>("Template", "Dropdown");

            tScrollView.SetAnchorToStretchBottom();
            tScrollView.SetPosition(0, 2);
            tScrollView.SetSize(0, _h * 5);
            tScrollView.SetPivot(0.5f, 1.0f);
            //		tScrollView.SetColor( 0xFFFFFFFF ) ;
            tScrollView.isVerticalScrollber = true;
            tScrollView._scrollRect.verticalScrollbarSpacing = -2;

            tScrollView.content._h = _h;

            tDropdown.template = tScrollView._rectTransform;

            // テンプレートアイテムを1つ追加する
            tScrollView.dropdownItem._h = _h;

            // 最後に無効化
            tScrollView.SetActive(false);

            ResetRectTransform();
        }