示例#1
0
    //提示窗口字符格式化
    private int TipsFormat(string tips_message)
    {
        string tempStr  = "";
        int    rowCount = 0;

        for (int i = 0; i < tips_message.Length; i++)
        {
            tempStr      += tips_message[i].ToString();
            tipsText.text = tempStr;
            if (tipsText.GetScreenRect().width > 220f)              //超过了一行
            {
                rowCount++;
                tempStr = "";
            }
        }
        if (tempStr != "")
        {
            rowCount++;
        }
        if (rowCount < 2)
        {
            tipsRect.height = ORIGIN_HEIGHT;
            tipsText.text   = displayString;
            tipsRect.width  = (19f * 2f + tipsText.GetScreenRect().width);
        }
        else
        {
            tipsRect.height = ORIGIN_HEIGHT + (rowCount - 2) * LINT_HEIGHT + 20f;
            tipsRect.width  = 263f;
        }
        return(rowCount);
    }
示例#2
0
    void setPromptCenterXY()
    {
        //CENTER PROMPT TEXT
        float promptTextWidth     = promptText.GetScreenRect().width;
        float halfPromptTextWidth = promptTextWidth / 2;

        centerPromptTextPositionX = halfScreenCenterX - halfPromptTextWidth;
        centerPromptTextPositionY = (halfScreenCenterY - promptText.GetScreenRect().height * 2) - padding50;
    }
示例#3
0
    void SplitSingle()
    {
        int refx = 0;// (int) winrect.x;
        int refz = 30;

        foreach (BaseGroup gb in grplist)
        {
            gb.Split();
            if (gb.type == (int)ENUM_TPMIX_GROUPTYPE.GROUP_TEXT)
            {
                GroupStr gptxt = (GroupStr)gb;
                for (int i = 0; i < gptxt.txt_info.Length; i++)
                {
                    BaseChar p = new BaseChar();
                    p.txt       = gptxt.txt_info.Substring(i, 1);
                    guitxt.text = p.txt;
                    int fw = (int)guitxt.GetScreenRect().width;
                    int fz = (int)guitxt.GetScreenRect().height + row * 2;
                    //refz += fz;
                    p.pr = new Rect(refx, refz, fw, fz);
                    gptxt.objlist.Add(p);

                    if (refx + fw >= winrect.x + winrect.width - 5)
                    {
                        refx  = 0;
                        refz += Mathf.Max(fz, linehei);
                    }
                    else
                    {
                        refx += fw;
                    }
                }
            }
            else if (gb.type == (int)ENUM_TPMIX_GROUPTYPE.GROUP_PIC)
            {
                GroupIco    gico = (GroupIco)gb;
                BasePicture p    = new BasePicture();
                gb.objlist.Add(p);
                string imgidx = gico.txt_info.Substring(1, gico.txt_info.Length - 2);
                p.ico = image[int.Parse(imgidx) % image.Length];
                int fw = p.ico.width;
                int fz = p.ico.height;
                p.pr = new Rect(refx, refz, fw, fz);
                if (refx + fw >= winrect.x + winrect.width - 5)
                {
                    refx  = 0;
                    refz += Mathf.Max(fz, linehei);
                }
                else
                {
                    refx += fw;
                }
            }
        }
    }
示例#4
0
    void Awake()
    {
        // "умный" ресайз и репозиционирование элементов татйл скрина (гейм татйтл и пункты меню)
        //титла располагается в верхней трети экрана прямо под его верхней границей
        //пункты меню располагаются в остальных 2/3 окна
        //каждый пункт занимает одинаковую высоту
        //размеры шрифта высчитываются относительно высоыт которую должен занимать текст
        //экран начинается в лвеом нижнем углу (0, 0)
        Rect    txtSize;                                                           // размер татйлы игры в пикселах на экране
        GUIText gameTitle = GameObject.Find("gameTitle").GetComponent <GUIText>(); //получаем татйтлу

        txtSize = gameTitle.GetScreenRect();                                       //потом получаем её размеры
        double fhRatio = (double)(gameTitle.fontSize / txtSize.height);            //расчитываем коэффициент зависимости размера шрифта от реальной высоты в пикселах

        int thirdPartOfScreen = Screen.height / 3;                                 //расчитываем высоту третти экрана (в ней у нас будет титла игры)

        float result      = (float)(thirdPartOfScreen * fhRatio);                  // получаем размер шрифта который заполнит эту высоту полностью, в формате числа с плавающей точкой
        int   aimFontSize = (int)Mathf.Round(result);                              //приводим этот размер к целому формату

        gameTitle.fontSize = aimFontSize;                                          // устанавливаем необходимый шрифт
        txtSize            = gameTitle.GetScreenRect();                            // обновляем размеры после изменения шрифта
        float scrnTop   = Screen.height - txtSize.yMax;                            // вычисляем значение на которое надо сместить титлу вверх экрана что бы она была точно вверху
        float MarginTop = 15;                                                      // отступ сверху для текста

        scrnTop -= MarginTop;                                                      // отступаем на величину отступа от верха экрана
        gameTitle.pixelOffset = new Vector2(0, this.ToEngineCoords(-scrnTop));     // задаём новый оффсет текста ToEngineCoords преобразует координаты в формат движка
        //float endOfGtitle = txtSize.yMin; // сохраняем нижнюю границу титлы для дальнейшей проверки пунктов меню

        float availableTop = Screen.height - thirdPartOfScreen;                              // вычисляем высоту от нуля оставшихся 2/3 экрана в которых будут пункты меню

        availableTop -= MarginTop;                                                           // вычитаем из доступной высоты верхний мэрджин
        float perMenuItemHeight = Mathf.Round(availableTop / 3);                             // считаем высоту одного пункта меню в пикселях в пределах 2/3 экрана

        result      = perMenuItemHeight * (float)(fhRatio);                                  // получаем размер шрифта для пункта меню в виде числа с плавающей точкой
        aimFontSize = (int)Mathf.Round(result);                                              // приводим размер шрифта к целому числу

        GUIText nG = GameObject.Find("newGame").GetComponent <GUIText>();                    // получаем пункт меню новая игра

        nG.fontSize = aimFontSize;                                                           // устанавливаем ему высчитанный размер шрифта
        Rect ngSize = nG.GetScreenRect();                                                    // получаем размеры в пикселях пункта меню новая игра

        GUIText mPlayer = GameObject.Find("multiplayer").GetComponent <GUIText>();           // получаем пункт меню сетевая игра

        mPlayer.fontSize = aimFontSize;                                                      // устанавливаем ему высчитанный размер шрифта
        Rect mpSize = mPlayer.GetScreenRect();                                               // получаем размеры в пикселях пункта меню сетевая игра

        mPlayer.pixelOffset = new Vector2(0, this.ToEngineCoords((mpSize.height)));          // устаналиваем пунтку смещение равное его высоте, что бы избавится от наложения пунктов друг на друга

        GUIText eG = GameObject.Find("exitGame").GetComponent <GUIText>();                   // получаем пункт меню выход из игры

        eG.fontSize = aimFontSize;                                                           // устаналвиваем ему высчитанный размер шрифта
        Rect egSize = eG.GetScreenRect();                                                    // получаем его размеры в пикселях

        eG.pixelOffset = new Vector2(0, this.ToEngineCoords(mpSize.height + egSize.height)); // устанавливаем ему смещение равное высоте предидущего пункта(игра по сети) и его высоте
    }
示例#5
0
    /// <summary>
    /// Breaks a word into multiple lines so that it fits into the given GUIText.
    /// </summary>
    /// <returns>The wrapped string.</returns>
    /// <param name="text">Text. The text to wrap.</param>
    /// <param name="guiText">GUI text. The guiText to wordwrap on.</param>
    /// <param name="maxTextWidth">Max text width. The width of the guiTextBox.</param>
    public static string WordWrappedString(string text, GUIText guiText, float maxTextWidth)
    {
        char[]   delim = { ' ' };
        string[] words = text.Split(delim); //Split the string into seperate words

        if (words.Length == 0)              // empty string
        {
            return("");
        }

        string result = "";

        result = words[0];

        for (var index = 1; index < words.Length; ++index)
        {
            string word = words[index].Trim();

            result      += " " + word;
            guiText.text = result;

            Rect TextSize = guiText.GetScreenRect();

            if (TextSize.width > maxTextWidth)
            {
                result  = result.Substring(0, result.Length - (word.Length));
                result += "\n" + word;
            }
        }

        return(result);
    }
    private void WrapLine(string line)
    {
        string[] words = line.Split(new char[1] {
            ' '
        });
        string res = "";

        for (int i = 0; i < words.Length; ++i)
        {
            string word = words[i].Trim();
            if (i == 0)
            {
                res = words[i];
                _questionField.text = res;
            }
            else
            {
                res += " " + word;
                _questionField.text = res;
            }

            Rect fieldSize = _questionField.GetScreenRect();
            if (fieldSize.width > Screen.width - _sideMargins)
            {
                res  = res.Substring(0, res.Length - word.Length);
                res += "\n" + word;
                _questionField.text = res;
            }
        }
    }
示例#7
0
    //layout never changes
    void positionGUIConstants()
    {
        //pixel inset = x,y,width,height
        //offset = x,y

        //POSITION BODY TEXT COLUMN 1 & 2
        bodyTextCol1Row1.pixelOffset = new Vector2(halfScreenCenterX - (bodyTextWidth + (padding50 * 3 - padding25)), screenYSplit9set3 + padding50);

        //POSITION ICON
        theIcon.pixelInset = new Rect(bodyTextCol1Row1.pixelOffset.x, bodyTextCol1Row1.pixelOffset.y + padding50, 100, 100);
//		Debug.Log("THE ICON Y: " + theIcon.pixelInset.y);
        float halfIconYPos = theIcon.pixelInset.y + (theIcon.pixelInset.height / 2);

        //POSITION TOPIC TEXT
        topicText.pixelOffset = new Vector2(titleText.pixelOffset.x, halfIconYPos + (padding10 / 2));
//		Debug.Log("THE TOPIC Y: " + topicText.pixelOffset.y);

        //POSITION TITLE TEXT
        titleText.pixelOffset = new Vector2(theIcon.pixelInset.x + theIcon.pixelInset.width + padding25, halfIconYPos + padding10);

        //POSITION SWIM PROMPT TEXT
        swimPromptText.pixelOffset = new Vector2(halfScreenCenterX - (swimPromptText.GetScreenRect().width / 2), -((Screen.height / 9) * 8 + padding50));


        //POSITION BACKGROUND DIM
        backgroundGradient.pixelInset = new Rect(0, 0, Screen.width, Screen.height);
    }
示例#8
0
文件: WordWrapText.cs 项目: milam/jga
    /// <summary>
    /// Sets the text, and wraps it; based on the example here:
    /// http://answers.unity3d.com/questions/428389/word-wrapping-guitext.html
    /// </summary>
    public void SetText(string newText)
    {
        if (newText.Length > 0)
        {
            string[] words  = newText.Split(' ');            //Split the string into seperate words
            string   result = "";

            Rect textArea = new Rect();

            for (int i = 0; i < words.Length; i++)
            {
                // set the gui text to the current string including new word
                textObject.text = (result + words[i] + " ");

                // measure it
                textArea = textObject.GetScreenRect();

                // if it didn't fit, put word onto next line, otherwise keep it
                if (textArea.width > wrapAtWidth)
                {
                    result += ("\n" + words[i] + " ");
                }
                else
                {
                    result = textObject.text;
                }
            }

            textObject.text = result;
        }
        else
        {
            textObject.text = "";
        }
    }
示例#9
0
    //Quite horrendous way of word wrapping a guitext
    public static Rect FormatGuiTextArea(GUIText guiText, float maxAreaWidthFraction)
    {
        string[] words    = guiText.text.Split(' ');
        string   result   = "";
        Rect     textArea = new Rect();
        float    maxWidth = maxAreaWidthFraction * Screen.width;

        for (int i = 0; i < words.Length; i++)
        {
            // set the gui text to the current string including new word
            guiText.text = (result + words[i] + " ");

            // measure it
            textArea = guiText.GetScreenRect();

            // if it didn't fit, put word onto next line, otherwise keep it
            if (textArea.width > maxWidth)
            {
                result += ("\n" + words[i] + " ");
            }
            else
            {
                result = guiText.text;
            }
        }
        return(textArea);
    }
示例#10
0
        void Start()
        {
            coins        = GameObject.Find(@"coins").GetComponent <SpriteRenderer>();
            background   = GameObject.Find(@"background").GetComponent <SpriteRenderer>();
            complete     = GameObject.Find(@"complete").GetComponent <SpriteRenderer>();
            coinsCounter = GameObject.Find(@"coinsCounter").GetComponent <GUIText>();
            level1       = GameObject.Find(@"level1").GetComponent <SpriteRenderer>();
            level2       = GameObject.Find(@"level2").GetComponent <SpriteRenderer>();
            unityadslogo = GameObject.Find(@"unityads-logo").GetComponent <SpriteRenderer>();
            playButton   = GameObject.Find(@"playButton").GetComponent <SpriteRenderer>();

            worldScreenHeight = Camera.main.orthographicSize * 2;
            worldScreenWidth  = worldScreenHeight / Screen.height * Screen.width;

            float x           = background.sprite.bounds.size.x;
            float y           = background.sprite.bounds.size.y;
            float aspect      = (float)x / (float)y;
            float finalHeight = (float)worldScreenWidth / (float)aspect;

            coins.transform.position = new Vector3(worldScreenWidth / 2 - coins.bounds.size.x,
                                                   worldScreenHeight / 2 - coins.bounds.size.y,
                                                   coins.transform.position.z);
            background.transform.localScale = new Vector3(worldScreenWidth / x, finalHeight / y, 1);
            unityadslogo.transform.position = new Vector3(0, worldScreenHeight / 2 - unityadslogo.bounds.size.y * 2, unityadslogo.transform.position.z);
            level1.transform.position       = new Vector3(0, unityadslogo.transform.position.y - unityadslogo.bounds.size.y, level1.transform.position.z);
            level2.transform.position       = new Vector3(0, unityadslogo.transform.position.y - unityadslogo.bounds.size.y, level2.transform.position.z);
            complete.transform.position     = new Vector3(0, level1.transform.position.y - level1.bounds.size.y * 1.5f, complete.transform.position.z);
            playButton.transform.position   = new Vector3(0, -y / 2 + playButton.bounds.size.y / 2, complete.transform.position.z);

            coinsCounter.text = SharedData.coinsCount.ToString();
            coinsCounter.transform.position = new Vector3(1 - coinsCounter.GetScreenRect().width / Screen.width - 0.06f,
                                                          0.98f,
                                                          0);
        }
示例#11
0
    public string Format(string text, int lineLength)
    {
        newString = "";
        words     = text.Split(" "[0]);

        for (int i = 0; i < words.Length; i++)
        {
            string word = words[i].Trim();

            if (i == 0)
            {
                newString   = words[i] + " ";
                holder.text = newString;
            }

            if (i > 0)
            {
                newString  += word + " ";
                holder.text = newString;
            }

            textWidth = holder.GetScreenRect();

            if (textWidth.width > lineLength)
            {
                newString   = newString.Substring(0, newString.Length - (word.Length + 1));
                newString  += "\n" + word + " ";
                holder.text = newString;
            }
        }

        return(newString);
    }
示例#12
0
    void Warnning(int WindowID)
    {
        scrollPosition = GUI.BeginScrollView(new Rect(20, 20, 320, 200), scrollPosition, new Rect(0, 0, 300, 14 * height + 14));
        string s1  = "";
        int    len = object_description.Length;


        //	object_tips_rect.height=60;
        char[] myChars = object_description.ToCharArray();
        height = 1;

        for (int i = 0; i < len; i++)
        {
            s1    += myChars[i];
            s.text = s1;
            if (s.GetScreenRect().width > 260)
            {
                height += 1;
                s1      = "" + myChars[i];
                s.text  = s1;
            }
            if (myChars[i] == '\n')
            {
                height += 1;
                s1      = "" + myChars[i];
                s.text  = s1;
            }
        }
        //	object_tips_rect.height=height*22+44;

        GUI.Label(new Rect(0, 0, 260, 16 * height + 16), object_description);

        GUI.EndScrollView();
    }
示例#13
0
    public void SetIntro()
    {
        bodyText.enabled  = false;
        titleText.enabled = false;

        topicText.text = "Intro";
//		topicText.text = currentKDrop.topic;
        //		topicText.text = "asdkfaldkfasdlfkasdlfkjasdlfkjajhsdlfkasjdflkasjd;flaksjdf;laksjdf;laksdjf;alksdjfa;lskdj";

        float newX = -margin - background.width / 2 - topicText.GetScreenRect().width / 2;
        float newY = -margin - topicText.GetScreenRect().height / 2;

        topTextPosition = new Vector2(newX, newY);

        topicText.pixelOffset = topTextPosition;

        factReady = true;
    }
示例#14
0
 public void SetPosition(int column)
 {
     m_Width              = m_Texture.GetScreenRect().width;
     m_Height             = m_Texture.GetScreenRect().height;
     m_HeightOffset       = -m_Height;
     m_WidthOffset        = -m_Parent.GetComponent <GUITexture>().GetScreenRect().width / 2;
     m_WidthOffset       -= m_Number.GetScreenRect().width / 2;
     m_WidthOffset       += 100 + 100 * column;
     m_Texture.pixelInset = new Rect(m_WidthOffset, m_HeightOffset, m_Width, m_Height);
 }
示例#15
0
        /// <summary>
        /// Texts the wrap.
        /// </summary>
        /// <param name="guiText">Unity text block.</param>
        /// <param name="lineWidth">Width of the line.</param>
        public static void TextWrap(GUIText guiText, int lineWidth)
        {
            string text = guiText.text;

            // This will check if text wrapping is necessary or if it is supported.
            var textSize = guiText.GetScreenRect();

            if (textSize.width <= lineWidth || !text.Contains(" "))
            {
                guiText.text = text;
                return;
            }

            // Split the string into separate words
            var words = text.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            var result = words[0] + " ";

            for (int i = 1; i < words.Length; ++i)
            {
                // Temporary store text with current word.
                var    word      = words[i];
                string tempSting = result + word + " ";

                // Calculate new size for GUI text component.
                guiText.text = tempSting;
                textSize     = guiText.GetScreenRect();

                // Use temporary text if it fits otherwise add a new line before current word.
                if (textSize.width > lineWidth)
                {
                    result += "\n" + word + " ";
                }
                else
                {
                    result = tempSting;
                }
            }

            // Show result on screen
            guiText.text = result;
        }
示例#16
0
    public static Rect FormatGuiTextArea(GUIText guiText)
    {
        string[] words    = guiText.text.Split(' ');
        string   result   = "";
        Rect     textArea = new Rect();

        for (int i = 0; i < words.Length; i++)
        {
            guiText.text = (result + words[i] + "\n");
            textArea     = guiText.GetScreenRect();
            result      += (words[i] + "\n");
        }
        return(textArea);
    }
示例#17
0
    public static Rect FormatGuiTextArea(GUIText guiText)
    {
        string[] words = guiText.text.Split(' ');
        string result = "";
        Rect textArea = new Rect();

        for(int i = 0; i < words.Length; i++)
        {
            guiText.text = (result + words[i] + "\n");
            textArea = guiText.GetScreenRect();
            result += (words[i] + "\n");
        }
        return textArea;
    }
示例#18
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);
    }
示例#19
0
//
//	void fword(int WindowID)
//	{
//		scrollPosition2 = GUI.BeginScrollView(new Rect(10, 300, 100, 100), scrollPosition2, new Rect(0, 0, 220, 200));
//		GUI.Button(new Rect(0, 0, 100, 20), "Top-left");
//		GUI.Button(new Rect(120, 0, 100, 20), "Top-right");
//		GUI.Button(new Rect(0, 180, 100, 20), "Bottom-left");
//		GUI.Button(new Rect(120, 180, 100, 20), "Bottom-right");
//		GUI.EndScrollView();
//
//	}

    void DoMyWindow5(int windowID)
    {
        if (GUI.Button(new Rect(40, 250, 100, 30), "清除"))
        {
            object_description = "";
        }

        if (GUI.Button(new Rect(200, 250, 100, 30), "关闭"))
        {
            motion_start = true;
        }

        scrollPosition = GUI.BeginScrollView(new Rect(20, 20, 320, 200), scrollPosition, new Rect(0, 0, 300, 14 * height + 14));
        string s1  = "";
        int    len = object_description.Length;

        char[] myChars = object_description.ToCharArray();
        height = 1;

        for (int i = 0; i < len; i++)
        {
            s1    += myChars[i];
            s.text = s1;
            if (s.GetScreenRect().width > 260)
            {
                height += 1;
                s1      = "" + myChars[i];
                s.text  = s1;
            }
            if (myChars[i] == '\n')
            {
                height += 1;
                s1      = "" + myChars[i];
                s.text  = s1;
            }
        }

        GUI.Label(new Rect(0, 0, 260, 16 * height + 16), object_description);

        GUI.EndScrollView();
    }
        void Start()
        {
            coins         = GameObject.Find(@"coins").GetComponent <SpriteRenderer>();
            background    = GameObject.Find(@"background").GetComponent <SpriteRenderer>();
            spriteadsLogo = GameObject.Find(@"spaceads-logo").GetComponent <SpriteRenderer>();
            coinsCounter  = GameObject.Find(@"coinsCounter").GetComponent <GUIText>();
            unityadslogo  = GameObject.Find(@"unityadslogo").GetComponent <SpriteRenderer>();
            startButton   = GameObject.Find(@"startButton").GetComponent <SpriteRenderer>();

            worldScreenHeight                = Camera.main.orthographicSize * 2;
            worldScreenWidth                 = worldScreenHeight / Screen.height * Screen.width;
            coins.transform.position         = new Vector3(worldScreenWidth / 2 - coins.bounds.size.x, worldScreenHeight / 2 - coins.bounds.size.y, coins.transform.position.z);
            unityadslogo.transform.position  = new Vector3(0, worldScreenHeight / 2 - unityadslogo.bounds.size.y, unityadslogo.transform.position.z);
            spriteadsLogo.transform.position = new Vector3(0, unityadslogo.transform.position.y - unityadslogo.bounds.size.y, spriteadsLogo.transform.position.z);
            startButton.transform.position   = new Vector3(0, spriteadsLogo.transform.position.y - spriteadsLogo.bounds.size.y * 2, startButton.transform.position.z);
            SharedData.coinsCount            = 0;
            coinsCounter.text                = SharedData.coinsCount.ToString();
            coinsCounter.transform.position  = new Vector3(1 - coinsCounter.GetScreenRect().width / Screen.width - 0.06f,
                                                           0.98f,
                                                           0);
        }
示例#21
0
    void Update()
    {
        if (GuiText.text.Length == 0)
        {
            return;
        }

        Vector3 ray = TransTarget.position - Player.position;

        ray           += Quaternion.Euler(Player.rotation.eulerAngles) * TransTargetOffset;
        Trans.position = Cam.WorldToViewportPoint(ray + Player.position);

        // fontSize is just integer -> value is jumping :(
        //GuiText.fontSize = FontBaseSize / (TransTarget.position - Player.position).magnitude;

        if (Background)
        {
            Rect rect = GuiText.GetScreenRect(Cam);
            BackgroundTransform.localScale = Vector3.zero; // should be done, dont know why

            Background.pixelInset = new Rect((-rect.width / 2) - BackgroundSpacing.x,
                                             (-rect.height / 2) - BackgroundSpacing.y,
                                             rect.width + 2 * BackgroundSpacing.x,
                                             rect.height + 2 * BackgroundSpacing.y);
        }

        TimeLeft = TimeStart + FadeDuration - Time.time;
        if (Status == FadeState.FadeIn)
        {
            Fade(true);
        }
        else if (Status == FadeState.FadeOut)
        {
            Fade(false);
        }
    }
示例#22
0
    public void setMessage(string message)
    {
        text.text = wrap(message);

        var textRect = text.GetScreenRect(Camera.main);

        expandBackgroundToSizeOf(textRect);

        leftBorder.setScreenPosition(textRect.xMin - halfThickness - paddingX, textRect.yMin - halfThickness - paddingY);
        rightBorder.setScreenPosition(textRect.xMax + halfThickness + paddingX, textRect.yMin - halfThickness - paddingY);

        var verticalBorderScale = new Vector3(1f, (textRect.height + borderThickness + paddingY * 2 + 2f) / messageBorder.height, 1f);

        leftBorder.transform.localScale  = verticalBorderScale;
        rightBorder.transform.localScale = verticalBorderScale;

        topBorder.setScreenPosition(textRect.xMin - halfThickness - paddingX, textRect.yMax + halfThickness + paddingY);
        bottomBorder.setScreenPosition(textRect.xMin - halfThickness - paddingX, textRect.yMin - halfThickness - paddingY);

        var horizontalBorderScale = new Vector3((textRect.width + borderThickness + paddingX * 2 + 2f) / messageBorder.width, 1f, 1f);

        topBorder.transform.localScale    = horizontalBorderScale;
        bottomBorder.transform.localScale = horizontalBorderScale;
    }
示例#23
0
 void Start()
 {
     tipsText.text    = "四";
     singleCharLength = tipsText.GetScreenRect().width;
 }
示例#24
0
 //col1row1 followed by col2row1 - imagecol2 (text-text-image)
 void layout2()
 {
     bodyTextCol2Row1.pixelOffset = new Vector2(halfScreenCenterX + (padding50), bodyTextCol1Row1.pixelOffset.y);
     bodyImageCol2.pixelInset     = new Rect(bodyTextCol2Row1.pixelOffset.x, bodyTextCol2Row1.pixelOffset.y - bodyTextCol2Row1.GetScreenRect().height - imageHeight - (padding10), imageWidth, imageHeight);
 }
示例#25
0
    public static void BuildCreateMenu()
    {
        Deconstruct();
        #region createmenu onnodig voor nu
        List<GUIText> textList = new List<GUIText>();
        List<GameObject> textObjectList = new List<GameObject>();
        textList.Clear();
        textObjectList.Clear();
        //Creating Scene Buttons
        settingsIcon = new GameObject("Settings_Icon");
        fireIcon = new GameObject("Fire_Icon");
        plusIcon = new GameObject("Plus_Icon");
        saveIcon = new GameObject("Save_Icon");
        backIcon = new GameObject("Back_Icon");

        settingsCollider = settingsIcon.AddComponent<BoxCollider2D>();
        fireCollider = fireIcon.AddComponent<BoxCollider2D>();
        plusCollider = plusIcon.AddComponent<BoxCollider2D>();
        saveCollider = saveIcon.AddComponent<BoxCollider2D>();
        backCollider = backIcon.AddComponent<BoxCollider2D>();

        settingsIconSprite = Resources.Load<Sprite>("Sprites/Create_Icons/SettingsIcon");
        fireIconSprite = Resources.Load<Sprite>("Sprites/Create_Icons/FireIcon");
        plusIconSprite = Resources.Load<Sprite>("Sprites/Create_Icons/PlusIcon");
        saveIconSprite = Resources.Load<Sprite>("Sprites/Create_Icons/SaveIcon");
        backIconSprite = Resources.Load<Sprite>("Sprites/Create_Icons/Crossicon");

        settingsTitleObject = new GameObject("Settings_Text");
        fireTitleObject = new GameObject("Fire_Text");
        plusTitleObject = new GameObject("Plus_Text");
        saveTitleObject = new GameObject("Save_Text");

        createdSceneObjectHolder = new GameObject("createdSceneObjectHolder");
        createMenuScriptHolder = new GameObject("CreateMenuScriptHolder");
        createMenuScriptHolder.AddComponent<TopBar_Script>();

        Objects.AddMany(settingsIcon, fireIcon, plusIcon, saveIcon, backIcon, settingsTitleObject, fireTitleObject, plusTitleObject, saveTitleObject);

        settingsIconRenderer = settingsIcon.AddComponent<SpriteRenderer>();
        fireIconRenderer = fireIcon.AddComponent<SpriteRenderer>();
        plusIconRenderer = plusIcon.AddComponent<SpriteRenderer>();
        saveIconRenderer = saveIcon.AddComponent<SpriteRenderer>();
        backIconRenderer = backIcon.AddComponent<SpriteRenderer>();

        settingsIconRenderer.sprite = settingsIconSprite;
        fireIconRenderer.sprite = fireIconSprite;
        plusIconRenderer.sprite = plusIconSprite;
        saveIconRenderer.sprite = saveIconSprite;
        backIconRenderer.sprite = backIconSprite;

        settingsTitle = settingsTitleObject.AddComponent<GUIText>();
        fireTitle = fireTitleObject.AddComponent<GUIText>();
        plusTitle = plusTitleObject.AddComponent<GUIText>();
        saveTitle = saveTitleObject.AddComponent<GUIText>();

        settingsTitle.text = "SETTINGS";
        fireTitle.text = "FIRE";
        plusTitle.text = "BACKGROUND";
        saveTitle.text = "SAVE";

        textList.AddMany(settingsTitle, fireTitle, plusTitle, saveTitle);

        //Background
        backgroundImage = Resources.Load("Backgrounds/MenuBackgrounds/Yellow") as Texture2D;
        backgroundTexture.texture = backgroundImage;

        //Scale

        float xSize = settingsIconSprite.bounds.size.x;
        float ySize = settingsIconSprite.bounds.size.y;
        float width;
        float height;

        if (screenDPI > 0)
        {
            width = 76 * screenDPI;
            height = 86 * screenDPI;
        }
        else
        {
            width = 76;
            height = 86;
        }

        float worldwidth = (camera.orthographicSize * 2 / Screen.height * width) / xSize;
        float worldHeight = (camera.orthographicSize * 2 / Screen.height * height) / ySize;

        settingsIcon.transform.localScale = new Vector3(worldwidth, worldHeight, 1);
        plusIcon.transform.localScale = new Vector3(worldwidth, worldHeight, 1);
        fireIcon.transform.localScale = new Vector3(worldwidth, worldHeight, 1);
        backIcon.transform.localScale = new Vector3(worldwidth, worldHeight, 1);
        saveIcon.transform.localScale = new Vector3(worldwidth, worldHeight, 1);

        //position
        float x = camera.ScreenToWorldPoint(new Vector3((Screen.width / 2), 0, 0)).x;
        float y = camera.ScreenToWorldPoint(new Vector3(0, 50, 0)).y;
        Vector3 position = new Vector3(x, y, -1);

        //Left 2
        plusIcon.transform.position = new Vector3(position.x - (plusIconSprite.bounds.size.x * 1.1f * 2) * settingsIcon.transform.localScale.x, position.y + (plusIconSprite.bounds.size.y / 2), 1);
        //Left 1
        fireIcon.transform.position = new Vector3(position.x - (fireIconSprite.bounds.size.x * 1.1f) * settingsIcon.transform.localScale.x, position.y + (fireIconSprite.bounds.size.y / 2), 1);
        //Midle
        settingsIcon.transform.position = new Vector3(position.x, position.y + (settingsIconSprite.bounds.size.y / 2), 1);
        //Right 1
        saveIcon.transform.position = new Vector3(position.x + (saveIconSprite.bounds.size.x * 1.1f) * settingsIcon.transform.localScale.x, position.y + (saveIconSprite.bounds.size.y / 2), 1);
        //Right 2
        backIcon.transform.position = new Vector3(position.x + (backIconSprite.bounds.size.x * 1.1f * 2) * settingsIcon.transform.localScale.x, position.y + (backIconSprite.bounds.size.y / 2), 1);

        plusTitle.pixelOffset = new Vector2(50, (Screen.height - 65));
        settingsTitle.pixelOffset = new Vector2(50, (Screen.height - 132));
        fireTitle.pixelOffset = new Vector2(50, (Screen.height - 200));
        saveTitle.pixelOffset = new Vector2(50, (Screen.height - 265));

        foreach (GUIText item in textList)
        {
            item.anchor = TextAnchor.MiddleLeft;
            item.color = Color.black;
            item.font = menuFont;
            item.fontStyle = FontStyle.Normal;
            item.fontSize = fontSize;
        }

        //Rect
        //PlusIcon
        plusTextRect = new Rect(50,
            (Screen.height - plusTitle.GetScreenRect().yMax + 14),
            plusTitle.GetScreenRect().width,
            fontSize - 20);

        //FireIcon
        fireTextRect = new Rect(50,
            (Screen.height - fireTitle.GetScreenRect().yMax + 14),
            fireTitle.GetScreenRect().width,
            fontSize - 20);

        //SettingsIcon
        settingsTextRect = new Rect(50,
            (Screen.height - settingsTitle.GetScreenRect().yMax + 14),
            settingsTitle.GetScreenRect().width,
            fontSize - 20);

        //SaveIcon
        saveTextRect = new Rect(50,
            (Screen.height - saveTitle.GetScreenRect().yMax + 14),
            saveTitle.GetScreenRect().width,
            fontSize - 20);
        //Left Top Width Height
        #endregion
    }
示例#26
0
        void Update()
        {
            if (Advertisement.isReady(@"incentivizedZone"))
            {
                if (!getMoreCoinsAnimationPlayed)
                {
                    GameObject.Find(@"getMoreCoins").animation.Play();
                    getMoreCoinsAnimationPlayed = true;
                }
            }
            else
            {
                getMoreCoinsAnimationPlayed = false;
                if (getMoreCoinsRenderer.color.a != 0)
                {
                    getMoreCoinsRenderer.color = new Color(getMoreCoinsRenderer.color.r, getMoreCoinsRenderer.color.g, getMoreCoinsRenderer.color.b, 0);
                }
            }

            if (Advertisement.isReady("gameStartZone") && !showedStartAd)
            {
                showedStartAd = true;
                Advertisement.Show(@"gameStartZone", new ShowOptions {
                    pause = true, resultCallback = null
                });
            }

            if (Input.GetMouseButtonDown(0) && !Advertisement.isShowing)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.collider.name == @"startButton")
                    {
                        loadLevelAnimationStarted = true;
                    }

                    if (hit.collider.name == @"getMoreCoins" && !adsShowing)
                    {
                        adsShowing = true;
                        Advertisement.Show(@"incentivizedZone", new ShowOptions {
                            pause          = true,
                            resultCallback = result => {
                                adsShowing = false;
                                if (result == ShowResult.Finished)
                                {
                                    SharedData.coinsCount     += 10;
                                    GUIText guiText            = GameObject.Find(@"coinsCounter").GetComponent <GUIText>();
                                    guiText.text               = SharedData.coinsCount.ToString();
                                    guiText.transform.position = new Vector3(1 - guiText.GetScreenRect().width / Screen.width - 0.06f,
                                                                             0.98f,
                                                                             0);
                                }
                            }
                        });
                    }
                }
            }
            if (loadLevelAnimationStarted)
            {
                coinsCounter.color = new Color(coinsCounter.color.r, coinsCounter.color.g, coinsCounter.color.b, coinsCounter.color.a - Time.deltaTime);
                foreach (SpriteRenderer renderer in objects)
                {
                    if (renderer.animation)
                    {
                        renderer.animation.Stop();
                    }
                    renderer.color = new Color(renderer.color.r, renderer.color.g, renderer.color.b, renderer.color.a - Time.deltaTime);
                    if (renderer.name == @"coins" && renderer.color.a < 0.01f)
                    {
                        Application.LoadLevel("DemoAppLevel");
                    }
                }
            }
        }
示例#27
0
 void updateTutTextPos()
 {
     feedback.pixelOffset = new Vector2(Screen.width / 2 - (feedback.GetScreenRect().width / 2), -(Screen.height - feedback.GetScreenRect().height - padding50));
 }