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>()); } }); }
public void Start() { MHS.WaitRun(0.5f, () => { if (!preventAutomaticFadeIn) { MHSFader.FadeIn(0.75f); } }); preventAutomaticFadeIn = false; }
public static void FadeTo(float o, float t, System.Action callback = null) { float c = 0; float beginO = instance.opacity; MHS.RunUntil(new RunningObject(() => { return(c >= t); }, () => { instance.opacity = beginO + ((o - beginO) * c / t); c += Time.deltaTime; }, () => { instance.opacity = o; if (callback != null) { callback(); } })); }
public void WriteText(Action callback = null) { textObject = transform.Find("Text").gameObject; textObject.GetComponent <Text>().text = text; Vector2 size = textObject.GetComponent <RectTransform>().sizeDelta; GetComponent <RectTransform>().sizeDelta = size + padding; if (!writeText) { if (callback != null) { callback(); } } else { GameObject writingTextObject = GameObject.Instantiate(textObject); writingTextObject.transform.SetParent(textObject.transform); ContentSizeFitter csfDestroy = writingTextObject.GetComponent <ContentSizeFitter>(); DestroyImmediate(csfDestroy); writingTextObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); writingTextObject.GetComponent <RectTransform>().sizeDelta = textObject.GetComponent <RectTransform>().sizeDelta; Text writingTextComponent = writingTextObject.GetComponent <Text>(); writingTextComponent.text = ""; Text textComponent = textObject.GetComponent <Text>(); textComponent.color = Color.white * 0; writingTextObject.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, textComponent.transform.localPosition.z); writingTextObject.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); writingTextObject.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); writingTextObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); float i = 0; float textProgress = 0; AudioSource textAudio = AudioManager.instance.PlaySFX("Text", true); MHS.RunUntil(() => { return(writingTextComponent.text == textComponent.text); }, () => { i += (canSpeedUpWrite && Input.GetButton(fireButton)) ? Time.deltaTime * writeTextSpeed * speedUpMultiplier : Time.deltaTime * writeTextSpeed; if (i >= 1) { textProgress += i; if (textProgress > textComponent.text.Length) { textProgress = textComponent.text.Length; } writingTextComponent.text = textComponent.text.Substring(0, Mathf.FloorToInt(textProgress)); i = i - 1; } }, () => { AudioManager.instance.StopAudioSource(textAudio); textComponent.color = Color.white * 1f; DestroyImmediate(writingTextObject); if (callback != null) { callback(); } }); } }