public override void Show(ModalContentBase modalContent, ModalButton[] modalButton) { GenericModalContent content = (GenericModalContent)modalContent; m_Title.text = content.Title; m_Body.text = content.Body; //Activate buttons and populate properties for (int i = 0; i < modalButton.Length; i++) { if (i >= m_Buttons.Length) { Debug.LogError($"Maximum number of buttons of this modal is {m_Buttons.Length}. But {modalButton.Length} ModalButton was given. To display all buttons increase the size of the button array to at least {modalButton.Length}"); return; } m_Buttons[i].gameObject.SetActive(true); m_Buttons[i].GetComponentInChildren <Text>().text = modalButton[i].Text; int index = i; //Closure m_Buttons[i].onClick.AddListener(() => { if (modalButton[index].Callback != null) { modalButton[index].Callback(); } if (modalButton[index].CloseModalOnClick) { Close(); } m_Buttons[index].onClick.RemoveAllListeners(); }); } }
/// <summary> /// Shows a generic (default) modal /// </summary> /// <param name="identifier">The identifier of the modal to show</param> /// <param name="modalContent">The content to show in the modal</param> /// <param name="modalButton">Modal button properties</param> /// <returns>The modal instantiated</returns> private Modal InternalShow(string identifier, ModalContentBase modalContent, ModalButton[] modalButton) { GameObject modalObj = m_ModalDatabase.GetModal(identifier); if (modalObj == null) { Debug.LogError("Error! Failed to get a modal prefab with the identifier: " + identifier + ". Ensure that the identifier matches the one in the database"); return(null); } GameObject clone = Instantiate(modalObj, transform); var modal = clone.GetComponent <Modal>(); modal.Show(modalContent, modalButton); return(modal); }
public override void Show(ModalContentBase modalContent, ModalButton[] modalButton) { GenericModalContent content = (GenericModalContent)modalContent; m_Title.text = content.Title; m_Body.text = content.Body; //Activate buttons and populate properties for (int i = 0; i < modalButton.Length; i++) { if (i >= m_Buttons.Length) { Debug.LogError($"Maximum number of buttons of this modal is {m_Buttons.Length}. But {modalButton.Length} ModalButton was given. To display all buttons increase the size of the button array to at least {modalButton.Length}"); return; } m_Buttons[i].gameObject.SetActive(true); m_Buttons[i].GetComponentInChildren <TextMeshProUGUI> ().text = modalButton[i].Text; int index = i; //Closure m_Buttons[i].onClick.AddListener(() => { if (modalButton[index].Callback != null) { modalButton[index].Callback(); } if (modalButton[index].CloseModalOnClick) { Close(); } m_Buttons[index].onClick.RemoveAllListeners(); }); } // modalbackを表示する(modal以外押せないようにするため) _modalBack.enabled = true; // 表示時のアニメーション this.transform.DOScale(new Vector3(0.1f, 0.1f, 0.1f), 0f); this.transform.DOScale(new Vector3(1f, 1f, 1f), 0.3f); }
/// <summary> /// Shows the modal with the given content /// </summary> /// <param name="modalContent">Content to show</param> /// <param name="modalButton">Button properties</param> public abstract void Show(ModalContentBase modalContent, ModalButton[] modalButton);
/// <summary> /// Shows a modal with the specified identifier /// </summary> /// <param name="identifier">The identifier of the modal to show</param> /// <param name="modalContent">The content to show in the modal</param> /// <param name="modalButton">Modal button properties</param> /// <returns>The modal instantiated</returns> public static Modal Show(string identifier, ModalContentBase modalContent, ModalButton[] modalButton) { return(Instance.InternalShow(identifier, modalContent, modalButton)); }
/// <summary> /// Sets the title of the modal content. /// </summary> /// <param name="modalContentBase">The modal content instance that this method extends.</param> /// <param name="title">The color of the modal.</param> /// <returns>Current component.</returns> public static ModalContentBase Title(this ModalContentBase modalContentBase, string title) { modalContentBase.AddChild(string.Format("<div class=\"modal-title\">{0}</div>", title), int.MinValue + 101); return(modalContentBase); }