/// <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(); }
//------------------------------------------------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { InputFieldPlus tInputField = _inputField; if (tInputField == null) { tInputField = gameObject.AddComponent <InputFieldPlus>(); } if (tInputField == null) { // 異常 return; } Image tImage = _image; if (tImage != null) { tInputField.targetGraphic = tImage; } //------------------------------- bool tIsMultiLine = false; if (string.IsNullOrEmpty(tOption) == false && tOption.ToLower() == "multiline") { // マルチ tIsMultiLine = true; } Vector2 tSize = GetCanvasSize(); int tFontSize = 16; if (tSize.x > 0 && tSize.y > 0) { if (tIsMultiLine == false) { // シングル SetSize(tSize.y * 0.5f, tSize.y * 0.1f); } else { // マルチ SetSize(tSize.y * 0.5f, tSize.y * 0.5f); } tFontSize = ( int )(tSize.y * 0.1f * 0.6f); } // Image tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame"); tImage.type = Image.Type.Sliced; if (isCanvasOverlay == true) { tImage.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } ResetRectTransform(); // Text UIText tTextComponent = AddView <UIText>("Text", "SIMPLE"); tTextComponent.isContentSizeFitter = false; tTextComponent.fontSize = tFontSize; tTextComponent.supportRichText = false; tTextComponent.color = new Color32(50, 50, 50, 255); tTextComponent.SetAnchorToStretch(); tTextComponent.SetMargin(12, 12, 12, 12); // tText.position = new Vector2( 0, -2 ) ; // tText.SetSize( -24, -28 ) ; // tText.resizeTextForBestFit = true ; tInputField.textComponent = tTextComponent._text; if (tIsMultiLine == false) { tTextComponent.alignment = TextAnchor.MiddleLeft; } else { tTextComponent.alignment = TextAnchor.UpperLeft; } if (isCanvasOverlay == true) { tTextComponent.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } // TextColorModifier tTextComponent.AddComponent <TextColorModifier>(); // Placeholder UIText tPlaceholder = AddView <UIText>("Placeholder", "SIMPLE"); tPlaceholder.fontSize = tFontSize; tPlaceholder.fontStyle = FontStyle.Italic; tPlaceholder.text = "Enter text..."; tPlaceholder.color = new Color32(50, 50, 50, 128); tPlaceholder.SetAnchorToStretch(); tPlaceholder.SetMargin(12, 12, 12, 12); // tPlaceholder.position = new Vector2( 0, -2 ) ; // tPlaceholder.SetSize( -24, -28 ) ; // tPlaceholder.resizeTextForBestFit = true ; tInputField.placeholder = tPlaceholder._text; if (tIsMultiLine == false) { tPlaceholder.alignment = TextAnchor.MiddleLeft; } else { tPlaceholder.alignment = TextAnchor.UpperLeft; } if (isCanvasOverlay == true) { tPlaceholder.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } if (tIsMultiLine == true) { // マルチラインで生成する tInputField.lineType = InputFieldPlus.LineType.MultiLineNewline; tInputField.textComponent.horizontalOverflow = HorizontalWrapMode.Wrap; } tInputField.caretWidth = 4; tInputField.customCaretColor = true; tInputField.caretColor = Color.blue; //---------------------------------------------------------- FontFilter tFontFilter = null; char tFontAlternateCode = '?'; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tFontFilter = tDS.fontFilter; tFontAlternateCode = tDS.fontAlternateCode; } } #endif if (tFontFilter == null) { } else { fontFilter = tFontFilter; } if (tFontAlternateCode == 0) { fontAlternateCode = '?'; } else { fontAlternateCode = tFontAlternateCode; } }