Пример #1
0
    public static void DisplayQuick(string[] words, bool silent = false, float delay = 0.4f)
    {
        var lol = new List <OverlayWord>();

        foreach (string w in words)
        {
            OverlayWord W = new OverlayWord(w)
                            .SetAnimationType(TextOverlayAnimationTypes.NoEffect, delay * 2f)
                            .SetFont(TextOverlayFonts.RobotoRegular)
                            .SetSizeScale(0.7f)
                            .SetAudio(defaultWordSound)
                            .ParseCommands();

            if (silent)
            {
                W.MakeSilent();
            }

            lol.Add(W);
        }

        if (lol.Count > 1)
        {
            lol [lol.Count - 1].SetAudio(defaultLastWordSound);
        }

        TextManager.Display(lol.ToArray());
    }
Пример #2
0
    protected GameObject AddTextObject(OverlayWord word, int availableWidth, int availableHeight, int forceFont = -1)
    {
        GameObject go = new GameObject();

        go.transform.parent = this.transform;
        go.name             = "Text";
        go.AddComponent <GUIText> ().alignment = TextAlignment.Center;
        go.GetComponent <GUIText> ().anchor    = TextAnchor.MiddleCenter;
        go.layer = LayerMask.NameToLayer("Text");
        go.AddComponent <MeshRenderer> ().material = TextManager.fonts [(int)word.font].material;
        go.transform.localPosition = new Vector3(0, 0f, 0f);

        GUIText t = go.GetComponent <GUIText>();

        t.color = new Color(word.color.r, word.color.g, word.color.b, TextManager.THIS.currentAlpha);
        t.text  = word.txt;

        Font font;

        font = TextManager.fonts [(int)word.font];

        if (forceFont != -1)
        {
            font = TextManager.fonts [forceFont];
        }


        t.text = word.txt.ToUpper();
        t.font = font;
        t.GetComponent <Renderer>().material = font.material;

        t.fontSize = GetFittingFontSize(t.text, word.font, (int)(availableWidth), (int)(availableHeight));

        //additional adjustment of a font size - so it's actual height matches the available width or height
        if (!string.IsNullOrEmpty(t.text))
        {
            var screenRect = t.GetScreenRect();
            if ((screenRect.width / availableWidth) > (screenRect.height / availableHeight))
            {
                t.fontSize = (int)(t.fontSize * availableWidth / screenRect.width);
            }
            else
            {
                t.fontSize = (int)(t.fontSize * availableHeight / screenRect.height);
            }
        }

        return(go);
    }
Пример #3
0
    public static void DisplayQuickPulsating(string word)
    {
        var lol = new List <OverlayWord>();

        OverlayWord W = new OverlayWord(word)
                        .SetAnimationType(TextOverlayAnimationTypes.Pulsating, 100000f)
                        .SetFont(TextOverlayFonts.RobotoRegular)
                        .SetSizeScale(0.7f)
                        .ParseCommands();

        W.MakeSilent();

        lol.Add(W);

        TextManager.Display(lol.ToArray());
    }
Пример #4
0
 public void ShowNextTextAnimation()
 {
     if (wordStack.Count > 0)
     {
         OverlayWord next = wordStack[0];
         wordStack.RemoveAt(0);
         //if (!SHGUI.current.IsBackgroundOn())
         DisplaySingleWord(next);
     }
     else
     {
         if (OnComplete != null)
         {
             OnComplete();
         }
     }
 }
Пример #5
0
    private void DisplaySingleWord(OverlayWord word)
    {
        GameObject wordObject;

        wordObject = GameObject.Instantiate(emptyTextAnimation) as GameObject;

        wordObject.transform.parent        = TextContainer;
        wordObject.transform.localRotation = Quaternion.identity;
        wordObject.transform.localPosition = Vector3.zero;

        //Enum effect names are converted to strings and used to instantiate a proper class of effect
        string t1 = ((TextOverlayAnimationTypes)word.type).ToString();

        TextAnimation a;

        if (word.type == TextOverlayAnimationTypes.ScrollDown)
        {
            a = wordObject.AddComponent <ScrollDown>();
        }
        else if (word.type == TextOverlayAnimationTypes.ScrollLeft)
        {
            a = wordObject.AddComponent <ScrollLeft>();
        }
        else if (word.type == TextOverlayAnimationTypes.ScrollRight)
        {
            a = wordObject.AddComponent <ScrollRight>();
        }
        else if (word.type == TextOverlayAnimationTypes.ScrollUp)
        {
            a = wordObject.AddComponent <ScrollUp>();
        }
        else
        {
            a = wordObject.AddComponent <NoEffect>();
        }

        a.Setup(word);
        a.Launch();
    }
Пример #6
0
    public static void DisplayQuickSmaller(string[] words, bool silent = false, float durationScale = 0.2f, bool blackFading = false)
    {
        var lol = new List <OverlayWord>();

        foreach (string w in words)
        {
            OverlayWord W = new OverlayWord(w)
                            .SetAnimationType(TextOverlayAnimationTypes.NoEffect, 1f)
                            .SetFont(TextOverlayFonts.RobotoRegular)
                            .SetSizeScale(0.7f)
                            .SetDurationScale(durationScale)
                            .SetBlackFading(blackFading)
                            .ParseCommands();

            if (silent)
            {
                W.MakeSilent();
            }

            lol.Add(W);
        }

        TextManager.Display(lol.ToArray());
    }
Пример #7
0
    public void Setup(OverlayWord word)
    {
        this.word         = word;
        this.doTextFading = word.doFading;
        durationScale     = word.durationScale;

        textGameObjects = new List <GameObject> ();

        float marginFractionX;
        float marginFractionY;

        string[] words = word.txt.Split(';');

        //single words behave a bit differently. we don't want them to fill all the screen (by just a bit).
        //multiple words need to be scaled upwards.
        //also: don't fill the whole screen with a word. Always leave some margins.
        if (words.Length == 1)
        {
            marginFractionX = 0.9f;
            marginFractionY = marginFractionX * 1.5f;
        }
        else
        {
            marginFractionX = 0.9f;
            marginFractionY = marginFractionX * 1.4f;
        }

        marginFractionX *= word.sizeScale;
        marginFractionY *= word.sizeScale;

        foreach (string w in words)
        {
            int forcefont = -1;
            word.txt = w;
            float sizeScaleAdditional = 1f;

            if (w.Length > 0)
            {
                if (w [0] == '\\')
                {
                    word.txt  = w.Substring(1);
                    forcefont = (int)TextOverlayFonts.RobotoThin;
                }
                else if (w [0] == '/')
                {
                    word.txt  = w.Substring(1);
                    forcefont = (int)TextOverlayFonts.RobotoBold;
                }
                else if (w [0] == '#')
                {
                    word.txt            = w.Substring(1);
                    sizeScaleAdditional = 2f;
                }
            }

            textGameObjects.Add(AddTextObject(word, (int)(TextManager.THIS.ScreenSize.x * marginFractionX * sizeScaleAdditional), (int)(TextManager.THIS.ScreenSize.y * marginFractionY * sizeScaleAdditional), forcefont));
        }


        //magical parameter that represents distance between anchor of a guiText and upper/lower edge of a glyph.
        //I figured it should be 0.5. It isn;t
        float magic = 0.35f;


        //laying out the texts one below the other.
        float lasty     = 0;
        float heightsum = 0;
        float maxwidth  = 0;

        for (int i = 0; i < textGameObjects.Count; ++i)
        {
            var screenRect = textGameObjects[i].GetComponent <GUIText>().GetScreenRect();

            heightsum += screenRect.height;
            if (screenRect.width > maxwidth)
            {
                maxwidth = screenRect.width;
            }

            if (i != 0)
            {
                lasty -= (textGameObjects[i - 1].GetComponent <GUIText>().GetScreenRect().height / TextManager.THIS.ScreenSize.y * magic);
                lasty -= (screenRect.height / TextManager.THIS.ScreenSize.y * magic);
            }
            textGameObjects[i].transform.localPosition = new Vector3(textGameObjects[i].transform.localPosition.x,
                                                                     lasty,
                                                                     textGameObjects[i].transform.localPosition.z);
        }

        //scaling so text fill the desired space
        float targetScaleWidth  = (TextManager.THIS.ScreenSize.x * marginFractionX) / (maxwidth);
        float targetScaleHeight = (TextManager.THIS.ScreenSize.y * marginFractionY) / (heightsum);

        float targetScale = Mathf.Min(targetScaleHeight, targetScaleWidth);

        if (!float.IsNaN(targetScale) && !float.IsInfinity(targetScale))
        {
            ScaleTextGameObjects(textGameObjects, targetScale);
            heightsum *= targetScale;
        }

        float off = 0;

        //centering.
        off  = -textGameObjects[0].GetComponent <GUIText>().GetScreenRect().height / TextManager.THIS.ScreenSize.y * magic;
        off += heightsum / TextManager.THIS.ScreenSize.y * magic;

        //anchor of a first text is not at the top of a text but in its' center. we offset for that and additional bit.
        this.transform.localPosition = new Vector3(this.transform.localPosition.x,
                                                   this.transform.localPosition.y + off + 0.02f,
                                                   this.transform.localPosition.z);



        /*
         * float maxw = 0;
         * float totalh = 0;
         * Debug.Log ("----------------------");
         * for (int i = 0; i < g.Count; ++i) {
         *      GUIText z = g[i].GetComponent<GUIText>();
         *      Debug.Log (z.text + ": " + z.GetScreenRect().width +", " + z.GetScreenRect().height);
         *      if (z.GetScreenRect().width > maxw) maxw = z.GetScreenRect().width;
         *      totalh += z.GetScreenRect().height;
         *      Debug.Log (" line spacing " + z.lineSpacing);
         * }
         * Debug.Log (" screen.width: " + Screen.width + " screen.height: " + Screen.height);
         * Debug.Log (" max.width: " + maxw + " total.height: " + totalh);
         */
        Manager = TextManager.THIS;
    }