Example #1
0
        /// <summary>
        /// A drop down list that contains values.
        /// Note: Only one value can be selected at a time.
        /// </summary>
        /// <param name="selectedValue">The currently selected value in the drop down list.</param>
        /// <param name="list">The list of values that populates the drop down list.</param>
        /// <param name="title">The title for the drop-down list.</param>
        /// <returns>The selection in the drop-down list.</returns>
        public static int DropDownList(int selectedValue, Fields.DropDownValues list, string title)
        {
            // exit early if list is null or empty
            if (list.items == null || list.items.Length == 0)
            {
                return(0);
            }

            // if the selected value is out of range, set it to 0
            if (selectedValue > list.items.Length)
            {
                selectedValue = 0;
            }

            int result = EditorGUILayout.IntPopup(title, selectedValue, list.items, list.ids);

            return(result);
        }
Example #2
0
        // -----------------------------------------------------------
        // Drop-Down List Field
        // -----------------------------------------------------------

        /// <summary>
        /// A drop-down list that contains values.
        /// Note: Only one value can be selected at a time.
        /// </summary>
        /// <param name="selectedValue">The currently selected value in the drop down list.</param>
        /// <param name="list">The list of values that populates the drop down list.</param>
        /// <param name="titleWidth">The width of the title assigned to the drop down list. If set to 0, the title is hidden.</param>
        /// <param name="fieldWidth">The width of the drop-down list.</param>
        /// <returns>The selection in the drop-down list.</returns>
        public static int DropDownList(int selectedValue, Fields.DropDownValues list, int titleWidth, int fieldWidth = 0, bool lenIsListID = false)
        {
            if (titleWidth == 0)
            {
                titleWidth = -3;
            }

            // exit early if list is null or empty
            if (list.items == null || list.items.Length == 0)
            {
                BeginHorizontal();
                Label("[No Items in List]");
                EndHorizontal();
                return(0);
            }

            // get the length of the list
            int listLength = list.ids.Length;

            // if size of list does not represent all list.ids, get the id of the last item in list
            if (lenIsListID)
            {
                listLength = list.ids[listLength - 1];
            }

            // if the selected value is out of range, set it to 0
            if (selectedValue > listLength)
            {
                selectedValue = 0;
            }

            BeginHorizontal();
            Label(list.name, titleWidth);

            int result = EditorGUILayout.IntPopup(selectedValue, list.items, list.ids, GetFieldWidth(fieldWidth));

            EndHorizontal();
            return(result);
        }