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);
        }
Example #2
0
        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();
                }
            }));
        }
Example #3
0
        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();
                    }
                });
            }
        }