public MessageBoxAwait BuildMessages(params MessageBoxParams[] parameters) { messageBoxList = new List <MessageBoxParams>(parameters); Build(messageBoxList[0], mb => { MHS.RunUntil(() => { return(Input.GetButtonDown(fireButton)); }, () => { }, () => { MHS.RunFor(parameters[0].FadeTime, i => { mb.GetComponent <RectTransform>().localScale = new Vector3(1 - i, 1 - i, 1); mb.GetComponent <CanvasGroup>().alpha = 1 - i; }, () => { DestroyImmediate(mb.gameObject); messageBoxList.RemoveAt(0); if (messageBoxList.Count > 0) { BuildMessages(messageBoxList[0]); } else { Action temp = messageBoxsAwait.callback; messageBoxsAwait = null; if (temp != null) { temp(); } } }); }); }); if (messageBoxsAwait == null) { messageBoxsAwait = new MessageBoxAwait(); } return(messageBoxsAwait); }
public void Build(MessageBoxParams parameters, Action <MessageBox> callback = null) { GameObject go = Instantiate(messageBoxPrefabs[parameters.PrefabIndex], Vector3.zero, Quaternion.identity); go.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 1); go.transform.SetParent(this.transform); go.transform.localPosition = Vector3.zero; go.GetComponent <MessageBox>().fireButton = fireButton; go.GetComponent <MessageBox>().text = parameters.Text; go.GetComponent <MessageBox>().writeTextSpeed = parameters.Speed; go.GetComponent <MessageBox>().writeText = (parameters.Speed > 0); go.GetComponent <MessageBox>().canSpeedUpWrite = (parameters.CanSpeedUpWriteSpeed); go.GetComponent <MessageBox>().speedUpMultiplier = parameters.SpeedUpWriteSpeed; Vector2 pos = Camera.main.WorldToViewportPoint((parameters.Position != null) ? (Vector3)parameters.Position : Camera.main.transform.position); go.GetComponent <RectTransform>().anchorMin = pos; go.GetComponent <RectTransform>().anchorMax = pos; MHS.RunFor(parameters.FadeTime, i => { go.GetComponent <RectTransform>().localScale = new Vector3(i, i, 1); go.GetComponent <CanvasGroup>().alpha = i; }, () => { go.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); go.GetComponent <CanvasGroup>().alpha = 1; }); go.GetComponent <MessageBox>().WriteText(() => { if (callback != null) { callback(go.GetComponent <MessageBox>()); } }); }