/// <summary> /// Shows an simple list dialog with an optional title, optional icon, and a required scrollable option list. /// <para></para> /// For more customizability, use <see cref="CreateSimpleList"/>. /// </summary> /// <param name="optionDataList">The data to use for the option list.</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(OptionDataList optionDataList, Action <int> onItemClick, string titleText, ImageData icon) { DialogSimpleList dialog = CreateSimpleList(); dialog.Initialize(optionDataList, onItemClick, titleText, icon); dialog.Show(); return(dialog); }
/// <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)); }
public void Initialize(OptionDataList optionDataList, Action <int> onItemClick, string titleText, ImageData icon) { m_TitleSection.SetTitle(titleText, icon); m_OptionDataList = optionDataList; m_SelectionItems = new List <DialogSimpleOption>(); Image imageIcon = m_OptionTemplate.GetChildByName <Image>("Icon"); VectorImage vectorIcon = m_OptionTemplate.GetChildByName <VectorImage>("Icon"); if (m_OptionDataList.options.Count > 0 && m_OptionDataList.options[0].imageData != null) { if (m_OptionDataList.options[0].imageData.imageDataType == ImageDataType.Sprite) { DestroyImmediate(vectorIcon.gameObject); } else { DestroyImmediate(imageIcon.gameObject); } } else { DestroyImmediate(imageIcon.gameObject); } for (int i = 0; i < m_OptionDataList.options.Count; i++) { m_SelectionItems.Add(CreateSelectionItem(i)); } float availableHeight = DialogManager.rectTransform.rect.height; LayoutGroup textAreaRectTransform = m_TitleSection.text.transform.parent.GetComponent <LayoutGroup>(); if (textAreaRectTransform.gameObject.activeSelf) { textAreaRectTransform.CalculateLayoutInputVertical(); availableHeight -= textAreaRectTransform.preferredHeight; } m_ListScrollLayoutElement.maxHeight = availableHeight - 48f; Destroy(m_OptionTemplate); m_OnItemClick = onItemClick; Initialize(); }
public void Initialize(OptionDataList optionDataList, Action<int> onItemClick, string titleText, ImageData icon) { m_TitleSection.SetTitle(titleText, icon); m_OptionDataList = optionDataList; m_SelectionItems = new List<DialogSimpleOption>(); Image imageIcon = m_OptionTemplate.GetChildByName<Image>("Icon"); VectorImage vectorIcon = m_OptionTemplate.GetChildByName<VectorImage>("Icon"); if (m_OptionDataList.options.Count > 0 && m_OptionDataList.options[0].imageData != null) { if (m_OptionDataList.options[0].imageData.imageDataType == ImageDataType.Sprite) { DestroyImmediate(vectorIcon.gameObject); } else { DestroyImmediate(imageIcon.gameObject); } } else { DestroyImmediate(imageIcon.gameObject); } for (int i = 0; i < m_OptionDataList.options.Count; i++) { m_SelectionItems.Add(CreateSelectionItem(i)); } float availableHeight = DialogManager.rectTransform.rect.height; LayoutGroup textAreaRectTransform = m_TitleSection.text.transform.parent.GetComponent<LayoutGroup>(); if (textAreaRectTransform.gameObject.activeSelf) { textAreaRectTransform.CalculateLayoutInputVertical(); availableHeight -= textAreaRectTransform.preferredHeight; } m_ListScrollLayoutElement.maxHeight = availableHeight - 48f; Destroy(m_OptionTemplate); m_OnItemClick = onItemClick; Initialize(); }
/// <summary> /// Shows an simple list dialog with a required scrollable option list. /// <para></para> /// For more customizability, use <see cref="CreateSimpleList"/>. /// </summary> /// <param name="optionDataList">The data to use for the option list.</param> /// <param name="onItemClick">Called when an option is selected.</param> /// <returns>The instance of the initialized, shown dialog.</returns> public static DialogSimpleList ShowSimpleList(OptionDataList optionDataList, Action <int> onItemClick) { return(ShowSimpleList(optionDataList, onItemClick, null, null)); }