/// <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(); }