private void Awake() { panel = transform.GetChild(0).GetComponent <Image>(); for (int i = 1; i < transform.childCount; i++) { AdviceBox newAdv = new AdviceBox(); newAdv.obj = transform.GetChild(i).gameObject; //newAdv.size = i; newAdv.txtTitle = newAdv.obj.transform.GetChild(1).gameObject.GetComponent <Text>(); newAdv.txtAdvice = newAdv.obj.transform.GetChild(2).gameObject.GetComponent <Text>(); newAdv.buttonOk = newAdv.obj.transform.GetChild(3).gameObject.GetComponent <Button>(); newAdv.buttonYes = newAdv.obj.transform.GetChild(4).gameObject.GetComponent <Button>(); newAdv.buttonNo = newAdv.obj.transform.GetChild(5).gameObject.GetComponent <Button>(); adviceBoxList.Add(newAdv); } }
/// <summary> /// /// </summary> /// <param name="title">Advice Title</param> /// <param name="text">The message of the advice.</param> /// <param name="size">(1-3) Defaults to 0.</param> /// <param name="actionConfrim">Action when clicking Ok/Yes.</param> /// <param name="actionDeny">Action when clicking No. Will force a double button to appear instead of only the button Ok.</param> /// public void CreateAdvice(string title, string text, int size = 0, ButtonConfirm actionConfirm = null, ButtonDeny actionDeny = null) { //Determinar el tamaño de la caja de mensaje adviceComp.panel.gameObject.SetActive(true); AdviceBox usedBox = adviceComp.adviceBoxList[size]; usedBox.txtTitle.text = title; usedBox.txtAdvice.text = text; functionConfirm = actionConfirm; functionDeny = actionDeny; if (actionConfirm == null) { usedBox.buttonYes.gameObject.SetActive(false); usedBox.buttonNo.gameObject.SetActive(false); usedBox.buttonOk.gameObject.SetActive(true); } else { usedBox.buttonYes.gameObject.SetActive(true); usedBox.buttonNo.gameObject.SetActive(true); usedBox.buttonOk.gameObject.SetActive(false); } usedBox.buttonOk.onClick.RemoveAllListeners(); usedBox.buttonYes.onClick.RemoveAllListeners(); usedBox.buttonNo.onClick.RemoveAllListeners(); if (actionConfirm == null) { functionConfirm = () => { } } ; if (actionDeny == null) { functionDeny = () => { } } ; usedBox.buttonOk.onClick.AddListener(ButtonDoConfirm); usedBox.buttonYes.onClick.AddListener(ButtonDoConfirm); usedBox.buttonNo.onClick.AddListener(ButtonDoDeny); usedBox.obj.SetActive(true); }