A game about forced loneliness, made by TACStudios
at master 2.4 kB view raw
1using System.Collections.Generic; 2 3using UnityEditor; 4using UnityEngine; 5 6namespace Unity.PlasticSCM.Editor.UI 7{ 8 internal static class DropDownTextField 9 { 10 internal static string DoDropDownTextField( 11 string text, 12 string controlName, 13 List<string> dropDownOptions, 14 GenericMenu.MenuFunction2 optionSelected, 15 params GUILayoutOption[] options) 16 { 17 GUIContent textContent = new GUIContent(text); 18 19 Rect textFieldRect = GUILayoutUtility.GetRect( 20 textContent, 21 EditorStyles.textField, 22 options); 23 24 return DoDropDownTextField( 25 text, 26 controlName, 27 dropDownOptions, 28 optionSelected, 29 textFieldRect); 30 } 31 32 internal static string DoDropDownTextField( 33 string text, 34 string controlName, 35 List<string> dropDownOptions, 36 GenericMenu.MenuFunction2 optionSelected, 37 Rect textFieldRect) 38 { 39 Texture popupIcon = Images.GetDropDownIcon(); 40 41 Rect popupButtonRect = new Rect( 42 textFieldRect.x + textFieldRect.width - BUTTON_WIDTH, 43 textFieldRect.y, 44 BUTTON_WIDTH, 45 textFieldRect.height); 46 47 if (GUI.Button(popupButtonRect, string.Empty, EditorStyles.label)) 48 { 49 GenericMenu menu = new GenericMenu(); 50 foreach (string option in dropDownOptions) 51 { 52 menu.AddItem( 53 new GUIContent(UnityMenuItem.EscapedText(option)), 54 false, 55 optionSelected, 56 option); 57 } 58 59 menu.DropDown(textFieldRect); 60 } 61 62 Rect popupIconRect = new Rect( 63 popupButtonRect.x, 64 popupButtonRect.y + UnityConstants.DROPDOWN_ICON_Y_OFFSET, 65 popupButtonRect.width, 66 popupButtonRect.height); 67 68 GUI.SetNextControlName(controlName); 69 string result = GUI.TextField(textFieldRect, text); 70 71 GUI.Label(popupIconRect, popupIcon); 72 73 return result; 74 } 75 76 const int BUTTON_WIDTH = 16; 77 } 78}