private DialogSimpleOption CreateSelectionItem(int i)
        {
            DialogSimpleOption option = Instantiate(m_OptionTemplate).GetComponent <DialogSimpleOption>();

            option.rectTransform.SetParent(m_OptionTemplate.transform.parent);
            option.rectTransform.localScale       = Vector3.one;
            option.rectTransform.localEulerAngles = Vector3.zero;
            option.rectTransform.localPosition    = new Vector3(option.rectTransform.localPosition.x, option.rectTransform.localPosition.y, 0f);

            OptionData data = m_OptionDataList.options[i];

            Text    text    = option.gameObject.GetChildByName <Text>("Text");
            Graphic graphic = option.gameObject.GetChildByName <Graphic>("Icon");

            text.text = data.text;

            if (data.imageData == null)
            {
                text.rectTransform.sizeDelta        = new Vector2(-48f, 0f);
                text.rectTransform.anchoredPosition = new Vector2(0f, 0f);
                Destroy(graphic.gameObject);
            }
            else
            {
                graphic.SetImage(data.imageData);
            }

            option.index          = i;
            option.onClickAction += OnItemClick;

            return(option);
        }
        /// <summary>
        /// Shows an simple list dialog with an optional title, optional icon, and a required scrollable option list (label-only).
        /// <para></para>
        /// For more customizability, use <see cref="CreateSimpleList"/>.
        /// </summary>
        /// <param name="options">The strings to use for the list item labels.</param>
        /// <param name="onItemClick">Called when an option is selected.</param>
        /// <param name="titleText">The title text. Make null for no title.</param>
        /// <param name="icon">The icon next to the title. Make null for no icon.</param>
        /// <returns>The instance of the initialized, shown dialog.</returns>
        public static DialogSimpleList ShowSimpleList(string[] options, Action <int> onItemClick, string titleText, ImageData icon)
        {
            OptionDataList optionDataList = new OptionDataList();

            for (int i = 0; i < options.Length; i++)
            {
                OptionData optionData = new OptionData(options[i], null);
                optionDataList.options.Add(optionData);
            }

            return(ShowSimpleList(optionDataList, onItemClick, titleText, icon));
        }
Example #3
0
        /// <summary>
        /// Removes an OptionData from the dropdown data list.
        /// Will not remove the item from the scene if the dropdown is open, so it's recommended to only call this while the list is closed.
        /// </summary>
        /// <param name="data">The data to remove from the list.</param>
        public void RemoveData(OptionData data)
        {
            m_OptionDataList.options.Remove(data);

            m_CurrentlySelected = Mathf.Clamp(m_CurrentlySelected, 0, m_OptionDataList.options.Count - 1);
        }
Example #4
0
 /// <summary>
 /// Adds an OptionData to the dropdown data list.
 /// Will not add an item to the scene if the dropdown is already expanded, but will add the item upon next expansion.
 /// </summary>
 /// <param name="data">The data to add to the list.</param>
 public void AddData(OptionData data)
 {
     m_OptionDataList.options.Add(data);
 }
Example #5
0
        /// <summary>
        /// Creates a single dropdown item and adds it to the dropdown list object in the scene.
        /// </summary>
        /// <param name="data">The data of the item.</param>
        /// <param name="index">The index of the item.</param>
        /// <returns>The instantiated DropdownListItem.</returns>
        private DropdownListItem CreateItem(OptionData data, int index)
        {
            DropdownListItem item = new DropdownListItem();

            GameObject itemGameObject = Instantiate(m_ListItemTemplate.rectTransform.gameObject);

            item.rectTransform = itemGameObject.GetComponent <RectTransform>();

            item.rectTransform.SetParent(m_ListItemTemplate.rectTransform.parent);
            item.rectTransform.localScale         = Vector3.one;
            item.rectTransform.localEulerAngles   = Vector3.zero;
            item.rectTransform.anchoredPosition3D = Vector3.zero;

            item.canvasGroup = item.rectTransform.GetComponent <CanvasGroup>();
            item.text        = item.rectTransform.GetChildByName <Text>("Text");

            if (m_OptionDataList.imageType == ImageDataType.Sprite)
            {
                item.image = item.rectTransform.GetChildByName <Image>("Icon");
                Destroy(item.rectTransform.GetChildByName <VectorImage>("Icon").gameObject);
            }
            else
            {
                item.image = item.rectTransform.GetChildByName <VectorImage>("Icon");
                Destroy(item.rectTransform.GetChildByName <Image>("Icon").gameObject);
            }

            DropdownTrigger trigger = itemGameObject.GetComponent <DropdownTrigger>();

            trigger.index    = index;
            trigger.dropdown = this;

            if (!string.IsNullOrEmpty(data.text))
            {
                item.text.text = data.text;
            }
            else
            {
                Destroy(item.text.gameObject);
            }

            if (data.imageData != null && data.imageData.ContainsData(true))
            {
                item.image.SetImage(data.imageData);
            }
            else
            {
                Destroy(item.image.gameObject);
            }

            itemGameObject.GetComponent <MaterialRipple>().rippleData = m_ItemRippleData.Copy();

            if (m_HighlightCurrentlySelected && index == m_CurrentlySelected)
            {
                itemGameObject.GetComponent <Image>().color = m_ItemRippleData.Color.WithAlpha(m_ItemRippleData.EndAlpha);
            }

            item.text.color  = m_ItemTextColor;
            item.image.color = m_ItemIconColor;

            item.canvasGroup.alpha = 0f;

            return(item);
        }