Ejemplo n.º 1
0
        /// <summary>
        /// Method revealing the text one character at a time.
        /// </summary>
        /// <returns></returns>
        IEnumerator RevealCharacters(TextMeshProUGUI textComponent)
        {
            textComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo = textComponent.textInfo;

            int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object
            int counter = 0;
            int visibleCount = 0;

            while (true)
            {
                visibleCount = counter % (totalVisibleCharacters + 1);

                textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?

                // Once the last character has been revealed, wait 1.0 second and start over.
                if (visibleCount >= totalVisibleCharacters)
                {
                    yield return new WaitForSeconds(1.0f);
                }

                counter += 1;

                yield return new WaitForSeconds(0.0f);
            }
        }
Ejemplo n.º 2
0
    // Animation to typewrite text
    // Returns total time it'll take for this animation to complete
    public Sequence Show(string s, float duration, float delay = 0)
    {
        text.text = s;

        if (duration > 0.011f)
        {
            text.ForceMeshUpdate();
            int count = text.textInfo.characterCount;

            // Create new animation
            showSequence = DOTween.Sequence();
            float puncDelay  = Mathf.Max(duration * 1.5f, MIN_PUNCTUATION_DELAY);
            float charDelays = 0;

            for (var i = 0; i < count; i++)
            {
                var timeOffset   = Mathf.Lerp(0, 1, (i) / (float)(count + 1));
                var charSequence = DOTween.Sequence();
                charSequence.Append(_tweener.DOFade(i, 0, duration * 2f + 0.2f).From().SetEase(Ease.InOutCubic))
                .Join(_tweener.DOScale(i, 0, duration).From().SetEase(Ease.OutBack, 5))
                .SetDelay(charDelays);

                char c = text.textInfo.characterInfo[i].character;
                if (c == '.' || c == ',' || c == ':' || c == ';' || c == '!' || c == '?')
                {
                    charDelays += puncDelay;
                }

                showSequence.Insert(timeOffset, charSequence);
            }

            showSequence.SetDelay(delay).Play();
            return(showSequence);
        }
        return(null);
    }
Ejemplo n.º 3
0
        public override void ShowMessage(ChatManager.IMessage newMessage, RectTransform contentView)
        {
            RectTransform rectTransform = GetComponent <RectTransform>();

            ChatManager.MessageOthersButton messageOthersButton = (ChatManager.MessageOthersButton)newMessage;
            Message = messageOthersButton;

            float messageHeight = rectTransform.sizeDelta.y;

            textMessageSender.text = messageOthersButton.Sender;
            textMessageSender.ForceMeshUpdate();

            TextMeshProUGUI buttonText = button.GetComponentInChildren <TextMeshProUGUI>();

            buttonText.text = messageOthersButton.ButtonText;
            buttonText.ForceMeshUpdate();

            //messageHeight += buttonText.textBounds.size.y;
            //messageHeight += paddingHieght;

            //Vector2 size = rectTransform.sizeDelta;
            //size.y = messageHeight;
            //rectTransform.sizeDelta = size;

            Vector2 contentSize = contentView.sizeDelta;

            contentSize.y        += messageHeight + messageSpace;
            contentView.sizeDelta = contentSize;

            Vector2 messagePos = new Vector2();

            messagePos.y = -contentView.sizeDelta.y + (messageHeight / 2f);
            messagePos.x = rectTransform.sizeDelta.x / 2f;

            rectTransform.anchoredPosition = messagePos;
        }
Ejemplo n.º 4
0
        private IEnumerator TypeDialog(string dialog)
        {
            _textLocalizer.ChangeKey(dialog);
            _dialogText.ForceMeshUpdate();
            int totalVisibleCharacters = _dialogText.textInfo.characterCount;
            var counter = 0;

            while (true)
            {
                int visibleCount = counter % (totalVisibleCharacters + 1);
                _dialogText.maxVisibleCharacters = visibleCount;

                if (visibleCount >= totalVisibleCharacters)
                {
                    // Finished displaying all dialog. Wait until the player has finished reading to break out.
                    yield return(new WaitUntil(() => _interact.triggered));

                    yield break;
                }

                counter += 1;
                yield return(YieldHelper.TypingTime);
            }
        }
    // Scale window and lay out item frames
    public void InitDetailsPanel(int itemIndex, Transform targetParent)
    {
        ItemProfile itemProfile = ItemDatabaseInterface.Instance.items[itemIndex];

        tmpDescription.text = itemProfile.Description;
        tmpValue.text       = itemProfile.Value.ToString() + "C";
        tmpDescription.ForceMeshUpdate();

        float height = tmpDescription.GetRenderedValues().y + 100f;

        tmpTitle.text = itemProfile.Name;
        Vector2 newDims = new Vector2(rectTransform.rect.width, height);

        rectTransform.sizeDelta = newDims;

        UIHelperLibrary.SetPanelTitle(titleBoxRectTransform, tmpTitle, newDims);

        halfDimensions = new Vector3(newDims.x, -newDims.y, 0) / 2.0f;

        transform.position = Input.mousePosition + halfDimensions + new Vector3(0, -titleBoxRectTransform.rect.height, 0);

        selectedObjectVisualizerInstance = Instantiate(selectedObjectPrefab, targetParent);
        selectedObjectVisualizerInstance.transform.localPosition = Vector2.zero;
    }
Ejemplo n.º 6
0
    // update the display with the current message lines
    void UpdateDisplay()
    {
        var playerData = DataController.m_instance.m_playerData;

        m_messagesUI.text = "";

        for (var i = 0; i < playerData.m_general.m_messageList.Count; i++)
        {
            if (i != 0)
            {
                m_messagesUI.text += "\n<line-height=25%>\n</line-height>";
            }

            m_messagesUI.text += playerData.m_general.m_messageList[i];
        }

        m_messagesUI.ForceMeshUpdate();

        RectTransform rectTransform = GetComponent <RectTransform>();

        var rectHeight = rectTransform.rect.height;

        m_messagesUI.alignment = (m_messagesUI.renderedHeight > rectHeight) ? TextAlignmentOptions.BottomLeft : TextAlignmentOptions.TopLeft;
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Method revealing the text one word at a time.
        /// </summary>
        /// <returns></returns>
        IEnumerator RevealWords(TextMeshProUGUI textComponent)
        {
            textComponent.ForceMeshUpdate();

            int totalWordCount = textComponent.textInfo.wordCount;
            int totalVisibleCharacters = textComponent.textInfo.characterCount; // Get # of Visible Character in text object
            int counter = 0;
            int currentWord = 0;
            int visibleCount = 0;

            while (true)
            {
                currentWord = counter % (totalWordCount + 1);

                // Get last character index for the current word.
                if (currentWord == 0) // Display no words.
                    visibleCount = 0;
                else if (currentWord < totalWordCount) // Display all other words with the exception of the last one.
                    visibleCount = textComponent.textInfo.wordInfo[currentWord - 1].lastCharacterIndex + 1;
                else if (currentWord == totalWordCount) // Display last word and all remaining characters.
                    visibleCount = totalVisibleCharacters;

                textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?

                // Once the last character has been revealed, wait 1.0 second and start over.
                if (visibleCount >= totalVisibleCharacters)
                {
                    yield return new WaitForSeconds(1.0f);
                }

                counter += 1;

                yield return new WaitForSeconds(0.1f);
            }
        }
Ejemplo n.º 8
0
    public void BundAnimation()
    {
        //speed+=0.01f;

        startTime = Time.time;
        text.ForceMeshUpdate();

        if (text.textInfo.characterCount == 0)
        {
            return;
        }

        cachedMeshInfo = text.textInfo.CopyMeshInfoVertexData();

        for (int i = 0; i < text.textInfo.characterCount; i++)
        {
            var charInfo = text.textInfo.characterInfo[i];
            if (!charInfo.isVisible)
            {
                continue;
            }

            int materialIndex = charInfo.materialReferenceIndex;
            int vertexIndex   = charInfo.vertexIndex;

            sourceVertices = cachedMeshInfo[materialIndex].vertices;
            verts          = text.textInfo.meshInfo[materialIndex].vertices;
            centerVec      = (sourceVertices[vertexIndex + 1] + sourceVertices[vertexIndex + 2]) / 2;

            x = ((velocity * speed) - (i * delay * 9.8f / (speed + 0.001f) * (speed + 0.0001f)) / 2) / frame;

            anim    = curve.Evaluate(x) * 3.0f;
            scale.x = scaleAnimationX.Evaluate(x);
            scale.y = scaleAnimationY.Evaluate(x);
            scale.z = 1.0f;
            rot.z   = rotateAnimation.Evaluate(x);

            verts[vertexIndex + 0] += -centerVec;
            verts[vertexIndex + 1] += -centerVec;
            verts[vertexIndex + 2] += -centerVec;
            verts[vertexIndex + 3] += -centerVec;

            matrix = Matrix4x4.TRS(Vector3.up * anim, Quaternion.Euler(0, 0, rot.z), scale);

            verts[vertexIndex + 0] = matrix.MultiplyPoint3x4(verts[vertexIndex + 0]);
            verts[vertexIndex + 1] = matrix.MultiplyPoint3x4(verts[vertexIndex + 1]);
            verts[vertexIndex + 2] = matrix.MultiplyPoint3x4(verts[vertexIndex + 2]);
            verts[vertexIndex + 3] = matrix.MultiplyPoint3x4(verts[vertexIndex + 3]);

            verts[vertexIndex + 0] += centerVec;
            verts[vertexIndex + 1] += centerVec;
            verts[vertexIndex + 2] += centerVec;
            verts[vertexIndex + 3] += centerVec;
        }

        for (int i = 0; i < text.textInfo.materialCount; i++)
        {
            if (text.textInfo.meshInfo[i].mesh == null)
            {
                continue;
            }
            text.textInfo.meshInfo[i].mesh.vertices = text.textInfo.meshInfo[i].vertices;
            text.UpdateGeometry(text.textInfo.meshInfo[i].mesh, i);
        }
    }
Ejemplo n.º 9
0
        public IEnumerator FadeInEffect(string text, float duration, bool isAdditive)
        {
            isTextTransitioning = true;
            if (duration > Mathf.Epsilon)
            {
                if (isAdditive)
                {
                    contentText.ForceMeshUpdate();
                    var textInfo = contentText.textInfo;

                    int lastIndex = textInfo.characterCount;
                    contentText.text += text;

                    contentText.ForceMeshUpdate();
                    int textLength = textInfo.characterCount;

                    Color32[] newVertexColors;
                    float     timeLapsed = 0f;


                    while (timeLapsed < duration)
                    {
                        for (int i = lastIndex; i < textLength; i++)
                        {
                            // Get the index of the material used by the current character.
                            int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;

                            // Get the vertex colors of the mesh used by this text element (character or sprite).
                            newVertexColors = textInfo.meshInfo[materialIndex].colors32;

                            // Get the index of the first vertex used by this text element.
                            int vertexIndex = textInfo.characterInfo[i].vertexIndex;

                            if (textInfo.characterInfo[i].isVisible)
                            {
                                byte alpha = (byte)Mathf.Clamp((timeLapsed / duration) * 255, 0, 255);

                                newVertexColors[vertexIndex + 0].a = alpha;
                                newVertexColors[vertexIndex + 1].a = alpha;
                                newVertexColors[vertexIndex + 2].a = alpha;
                                newVertexColors[vertexIndex + 3].a = alpha;

                                // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
                                contentText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                                // This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
                                // These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
                            }
                        }
                        timeLapsed += Time.deltaTime;
                        yield return(null);
                    }
                }
                else
                {
                    contentText.text  = text;
                    contentText.color = new Color(contentText.color.r, contentText.color.g, contentText.color.b, 0f);
                    float timeLapsed = 0f;
                    while (timeLapsed < duration)
                    {
                        timeLapsed       += Time.deltaTime;
                        contentText.color = new Color(contentText.color.r, contentText.color.g, contentText.color.b, timeLapsed / duration);
                        yield return(null);
                    }
                }
            }
            else
            {
                if (isAdditive)
                {
                    contentText.text += text;
                }
                else
                {
                    contentText.text = text;
                }
            }
            SetContentText(contentText.text);
            if (completeBubble != null)
            {
                completeBubble.gameObject.SetActive(true);
            }
            contentText.color   = new Color(contentText.color.r, contentText.color.g, contentText.color.b, 1f);
            isTextTransitioning = false;
        }
Ejemplo n.º 10
0
    void Update()
    {
        if (available && !canva.activeSelf && triggered)
        {
            player.isControlled = false;
            triggered           = false;
            available           = false;
            canva.SetActive(true);
            FindObjectOfType <Transition>().OpenPanel();
            SetUpCanva();
            started     = true;
            frequency   = dl.wordsFrequency;
            currentText = dl.dia[currentPar];
            while (currentText.Contains("<"))
            {
                currentText = us.RemoveSub(currentText, currentText.IndexOf("<"), currentText.IndexOf(">"));
            }
        }
        else if (canva.activeSelf && CI.talk && txt.text.Length >= currentText.Length && currentPar != fAcc)
        {
            currentLetter = 0;
            frequency     = dl.wordsFrequency;
            txt.text      = "";
            shake         = false;

            currentPar += 1;
            started     = true;
            currentText = dl.dia[currentPar];
            while (currentText.Contains("<"))
            {
                currentText = us.RemoveSub(currentText, currentText.IndexOf("<"), currentText.IndexOf(">"));
            }
        }
        else if (canva.activeSelf && CI.talk && txt.text.Length >= currentText.Length && currentPar == fAcc)
        {
            FindObjectOfType <Transition>().ClosePanel();
            StartCoroutine(close());
        }
        if (started)
        {
            if (txt.text.Length < currentText.Length) //It's meant to start coroutine and to write gradully the text, started is modified in coroutine
            {
                if ((currentLetter + frequency) <= currentText.Length)
                {
                    frequency = dl.wordsFrequency;
                }
                else
                {
                    frequency = currentText.Length - currentLetter;
                }
                StartCoroutine(talk(currentLetter));
                currentLetter += frequency;
            }
            else
            { //In the end rich text is applied and word shaking start
                var unwantedIndex = "<shake>".Length;
                txt.text = dl.dia[currentPar];
                var txt1 = "";
                if (txt.text.IndexOf("<shake>") != -1)
                {
                    txt1 = txt.text.Substring(0, txt.text.IndexOf("<shake>"));
                }
                var last1  = "";
                var count1 = 0;
                while (txt1.Contains("<")) //Rich text make problem of index that's why i'm doing this now
                {                          //Find 'true' index of first word to shake
                    last1   = txt1;
                    txt1    = us.RemoveSub(txt1, txt1.IndexOf("<"), txt1.IndexOf(">"));
                    count1 += last1.Length - txt1.Length;
                }
                shakeStartIndex = txt.text.IndexOf("<shake>") - count1;

                txt1 = "";
                if (txt.text.IndexOf("<stopShake>") != -1)  //txt.IndexOf will return -1 if there no <Shake>
                {
                    txt1 = txt.text.Substring(0, txt.text.IndexOf("<stopShake>"));
                }
                last1  = "";
                count1 = 0;
                while (txt1.Contains("<"))
                { //Find 'true' index of Last word to shake
                    last1   = txt1;
                    txt1    = us.RemoveSub(txt1, txt1.IndexOf("<"), txt1.IndexOf(">"));
                    count1 += last1.Length - txt1.Length;
                }
                shakeEndIndex = txt.text.IndexOf("<stopShake>") - count1;
                txt.text      = txt.text.Replace("<shake>", "");
                txt.text      = txt.text.Replace("<stopShake>", "");
                shake         = true;
            }
            started = false;
        }


        if (shake)
        {
            txt.ForceMeshUpdate();
            var Info = txt.textInfo;
            for (int i = shakeStartIndex; i < shakeEndIndex; i++) // To update mesh position
            {
                var charInfo = Info.characterInfo[i];
                if (!charInfo.isVisible)
                {
                    continue;
                }
                var verts = Info.meshInfo[charInfo.materialReferenceIndex].vertices;
                for (int j = 0; j < 4; j++)
                {
                    var orig = verts[charInfo.vertexIndex + j];
                    verts[charInfo.vertexIndex + j] = orig + new Vector3(0, Mathf.Cos(Time.time * cosFrequency + orig.x * 0.01f) * cosMul + Mathf.Sin(Time.time * sinFrequency + orig.x * 0.01f) * sinMul, 0);
                }
            }
            for (int i = 0; i < Info.meshInfo.Length; i++) //To apply it on actual vertices
            {
                var meshInfo = Info.meshInfo[i];
                meshInfo.mesh.vertices = meshInfo.vertices;
                txt.UpdateGeometry(meshInfo.mesh, i);
            }
        }
    }
Ejemplo n.º 11
0
        /// <summary>
        /// 頂点を変化させる
        /// </summary>
        /// <param name="modifiers"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public bool SetModifiers(Modifier[] modifiers, int offset = 0, int length = 0)
        {
            TextMeshProUGUI textMesh = _textMesh;

            if (textMesh == null || modifiers == null || modifiers.Length == 0)
            {
                return(false);
            }

            // メッシュ情報を一新する
            textMesh.ForceMeshUpdate();

            //----------------------------------------------------------

            TMP_TextInfo textInfo = textMesh.textInfo;

            if (textInfo == null || textInfo.characterCount == 0)
            {
                // 文字が存在しない
                return(true);
            }

            //--------------

            if (length <= 0)
            {
                length = modifiers.Length;
            }

            if (offset < 0)
            {
                length += offset;
                offset  = 0;
            }

            if (length <= 0 || offset >= modifiers.Length || offset >= textInfo.characterCount)
            {
                // 結果として変化は無い
                return(true);
            }

            if ((offset + length) > modifiers.Length)
            {
                length = modifiers.Length - offset;
            }

            if ((offset + length) > textInfo.characterCount)
            {
                length = textInfo.characterCount - offset;
            }

            //----------------------------------------------------------

            int vertexIndex;
            int materialIndex = 0;

            Vector3[] baseVertices;
            Color32[] baseColors;

            Modifier modifier;

            Vector3[] replaceVertices;
            Vector2   center;

            Color32 replaceColor;

            float dx, dy, vx, vy;
            float cv, sv;

            int i, j, p;

            for (i = 0; i < length; i++)
            {
                p = offset + i;

                if (textInfo.characterInfo[p].isVisible == true)
                {
                    modifier = modifiers[p];

                    if (modifier != null)
                    {
                        vertexIndex = textInfo.characterInfo[p].vertexIndex;

                        materialIndex = textInfo.characterInfo[p].materialReferenceIndex;

                        baseVertices = textInfo.meshInfo[materialIndex].vertices;
                        baseColors   = textInfo.meshInfo[materialIndex].colors32;

                        // Vertices
                        replaceVertices = new Vector3[4];
                        center          = Vector2.zero;
                        for (j = 0; j < 4; j++)
                        {
                            // Vertex
                            replaceVertices[j] = new Vector3
                                                 (
                                baseVertices[vertexIndex + j].x,
                                baseVertices[vertexIndex + j].y,
                                baseVertices[vertexIndex + j].z
                                                 );

                            center.x += replaceVertices[j].x;
                            center.y += replaceVertices[j].y;
                        }

                        center.x = center.x / 4f;
                        center.y = center.y / 4f;

                        // 回転→拡縮→移動
                        cv = Mathf.Cos(2.0f * Mathf.PI * modifier.rotation / 360f);
                        sv = Mathf.Sin(2.0f * Mathf.PI * modifier.rotation / 360f);

                        for (j = 0; j < 4; j++)
                        {
                            // 回転
                            dx = replaceVertices[j].x - center.x;
                            dy = replaceVertices[j].y - center.y;

                            vx = (dx * cv) - (dy * sv);
                            vy = (dx * sv) + (dy * cv);

                            // 拡縮
                            vx *= modifier.scale.x;
                            vy *= modifier.scale.y;

                            // 移動
                            vx += modifier.position.x;
                            vy += modifier.position.y;

                            replaceVertices[j].x = vx + center.x;
                            replaceVertices[j].y = vy + center.y;
                        }

                        for (j = 0; j < 4; j++)
                        {
                            baseVertices[vertexIndex + j] = replaceVertices[j];
                        }

                        // Color
                        for (j = 0; j < 4; j++)
                        {
                            // Color
                            replaceColor = new Color32
                                           (
                                baseColors[vertexIndex + j].r,
                                baseColors[vertexIndex + j].g,
                                baseColors[vertexIndex + j].b,
                                baseColors[vertexIndex + j].a
                                           );

                            if (modifier.gamma != 1)
                            {
                                replaceColor.r = ( byte )Math.Round(( float )replaceColor.r * modifier.gamma);
                                replaceColor.g = ( byte )Math.Round(( float )replaceColor.g * modifier.gamma);
                                replaceColor.b = ( byte )Math.Round(( float )replaceColor.b * modifier.gamma);
                            }

                            if (modifier.alpha != 1)
                            {
                                replaceColor.a = ( byte )Math.Round(( float )replaceColor.a * modifier.alpha);
                            }

                            baseColors[vertexIndex + j] = replaceColor;
                        }
                    }
                }
            }

            textMesh.UpdateVertexData(TMP_VertexDataUpdateFlags.Vertices | TMP_VertexDataUpdateFlags.Colors32);

            //----------------------------------------------------------

            return(true);
        }
    void UpdateMoveDescription()
    {
        descriptionSequence.Complete(true);

        descriptionSequence = DOTween.Sequence();

        bool isUnlocked = playerMoves[currentPlayer][currentMove].IsUnlocked();

        PlayerMove move = playerMoves[currentPlayer][currentMove];

        descriptionSequence.Insert(0f, moveLock.DOFade(0f, encounterConstants.descriptionTransition / 3));
        descriptionSequence.Insert(0f, moveImage.DOFade(0f, encounterConstants.descriptionTransition / 3));
        descriptionSequence.Insert(0f, lockCounter.DOFade(0f, encounterConstants.descriptionTransition / 3));
        descriptionSequence.Insert(0f, moveTitle.DOFade(0f, encounterConstants.descriptionTransition / 3));
        descriptionSequence.Insert(0f, moveDescription.DOFade(0f, encounterConstants.descriptionTransition / 3));

        descriptionSequence.Insert(0.2f, moveCanvas.DOFade(0f, encounterConstants.descriptionTransition / 3)
                                   .OnComplete(() => {
            // Update Values
            string descString = move.description +
                                "\n\n Crowd Gain: " + move.score +
                                "\n Hype Gain: " + move.hypeRate + "%\n" +
                                (move.turnLock > 0 ? ("Locks For: " + move.turnLock + " turns") : "Infinite Use");
            moveDescription.text = descString;
            moveTitle.text       = playerMoves[currentPlayer][currentMove].name;

            moveDescription.ForceMeshUpdate();
            moveTitle.ForceMeshUpdate();

            Color moveColor = move.moveColor;

            if (isUnlocked)
            {
                moveTitle.color       = encounterConstants.PlayerColors[currentPlayer];
                moveDescription.color = encounterConstants.moveUnlockedTextColour;
            }
            else
            {
                moveColor = encounterConstants.moveLockColor;
                descriptionSequence.Insert(encounterConstants.descriptionTransition / 2, moveLock.DOFade(1f, 1f));
                descriptionSequence.Insert(encounterConstants.descriptionTransition / 2, lockCounter.DOFade(1f, 1f));


                moveDescription.color = encounterConstants.moveLockTextColor;
                lockCounter.text      = playerMoves[currentPlayer][currentMove].currentLock + " turns";
                lockCounter.ForceMeshUpdate();

                moveLock.color    = moveColor;
                lockCounter.color = moveColor;
            }
            if (move.effect != MoveEffects.None)
            {
                switch (move.effect)
                {
                case MoveEffects.Amplifier:
                    moveImage.sprite = gameManager.AmplifierSprite;
                    break;

                case MoveEffects.CrazyStand:
                    moveImage.sprite = gameManager.CrazyStandSprite;
                    break;

                case MoveEffects.Rhythm:
                    moveImage.sprite = gameManager.RythmSprite;
                    break;

                case MoveEffects.Stomp:
                    moveImage.sprite = gameManager.StompSprite;
                    break;
                }

                descriptionSequence.Insert(encounterConstants.descriptionTransition / 2,
                                           moveImage.DOColor(Color.white, encounterConstants.descriptionTransition / 2));
                //moveImage.DOColor(moveColor, encounterConstants.descriptionTransition / 2));
            }
            else
            {
                descriptionSequence.Insert(encounterConstants.descriptionTransition / 2,
                                           moveImage.DOFade(0f, encounterConstants.descriptionTransition / 2).OnComplete(() => {
                    moveImage.sprite = null;
                }));
            }

            moveCanvas.GetComponent <Image>().color = moveColor;

            Vector2 descPos = knobControl.moveLabels.GetComponentsInChildren <Image>(true)[3].GetComponent <RectTransform>().anchoredPosition + encounterConstants.descriptionOffset;

            descriptionSequence.Insert(encounterConstants.descriptionTransition / 2,
                                       moveCanvas.GetComponent <RectTransform>().DOAnchorPos(descPos, encounterConstants.descriptionTransition / 2));

            descriptionSequence.Insert(encounterConstants.descriptionTransition / 2, moveCanvas.DOFade(1f, encounterConstants.descriptionTransition / 2));
            descriptionSequence.Insert(encounterConstants.descriptionTransition / 2, moveTitle.DOFade(1f, encounterConstants.descriptionTransition / 2));
            descriptionSequence.Insert(encounterConstants.descriptionTransition / 2, moveDescription.DOFade(1f, encounterConstants.descriptionTransition / 2));
        }));
    }
    public IEnumerator shakeText(int wordPosition)
    {
        int firstCharacter = textObject.textInfo.wordInfo[wordPosition].firstCharacterIndex;
        int lastCharacter  = textObject.textInfo.wordInfo[wordPosition].lastCharacterIndex;

        textObject = gameObject.GetComponent <TextMeshProUGUI>();
        textObject.ForceMeshUpdate();

        int   shakeDirection = 1;
        float shakeOffset    = 0;
        float maxOffset      = 6f;


        int materialIndex = textObject.textInfo.characterInfo[firstCharacter].materialReferenceIndex;

        Vector3[] startPositions = (Vector3[])(textObject.textInfo.meshInfo[materialIndex].vertices.Clone());

        yield return(new WaitForSeconds(0.3f));

        if (!GameManager.muted)
        {
            shakeSound.Play();
        }

        while (maxOffset > 3f)
        {
            textObject.ForceMeshUpdate();

            Vector3 movement = new Vector3(4f * shakeDirection, 0, 0);

            for (int charPos = firstCharacter; charPos <= lastCharacter; charPos++)
            {
                TMP_CharacterInfo charInfo = textObject.textInfo.characterInfo[charPos];

                if (!charInfo.isVisible)
                {
                    continue;
                }

                materialIndex = charInfo.materialReferenceIndex;
                int vertexIndex = charInfo.vertexIndex;

                for (int i = 0; i < 4; i++)
                {
                    textObject.textInfo.meshInfo[materialIndex].vertices[vertexIndex + i] += movement;
                }
            }
            shakeOffset += movement.x;

            if (shakeOffset * shakeDirection > maxOffset)
            {
                shakeDirection *= -1;
                maxOffset      *= 0.9f;
            }



            textObject.UpdateVertexData();
            yield return(new WaitForSeconds(0.02f));
        }

        for (int charPos = firstCharacter; charPos <= lastCharacter; charPos++)
        {
            TMP_CharacterInfo charInfo = textObject.textInfo.characterInfo[charPos];

            if (!charInfo.isVisible)
            {
                continue;
            }

            int vertexIndex = charInfo.vertexIndex;

            for (int i = 0; i < 4; i++)
            {
                textObject.textInfo.meshInfo[materialIndex].vertices[vertexIndex + i] = startPositions[vertexIndex + i];
            }
        }

        shakeSound.Stop();

        textObject.UpdateVertexData();
    }
Ejemplo n.º 14
0
        void LateUpdate()
        {
            //Edit Mesh on TextMeshPro component
            if (tmp != null)
            {
                if (tmp.havePropertiesChanged)
                {
                    tesselationRequired = true;
                    // Debug.Log("prop changed");
                }
                else if (savedSize != (transform as RectTransform).rect.size)
                {
                    tesselationRequired = true;
                    //Debug.Log("size changed");
                }
                else if (!savedPos.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position)))
                {
                    curvingRequired = true;
                    // Debug.Log("pos changed");
                }
                else if (!savedUp.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up)))
                {
                    curvingRequired = true;
                    // Debug.Log("up changed");
                }


                if (Dirty || tesselationRequired || savedMesh == null || vh == null || (curvingRequired && !Application.isPlaying))
                {
                    //Debug.Log("meshing TMP");
                    tmp.renderMode = TMPro.TextRenderFlags.Render;
                    tmp.ForceMeshUpdate();
                    vh = new VertexHelper(tmp.mesh);
                    crvdVE.TesselationRequired = true;

#if UNITY_5_1
                    crvdVE.ModifyMesh(vh.GetUIVertexStream);
#else
                    crvdVE.ModifyMesh(vh);
#endif

                    savedMesh = new Mesh();
                    vh.FillMesh(savedMesh);

                    tmp.renderMode = TMPro.TextRenderFlags.DontRender;

                    tesselationRequired = false;
                    Dirty     = false;
                    savedSize = (transform as RectTransform).rect.size;
                    savedUp   = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up);
                    savedPos  = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);
                }


                if (curvingRequired)
                {
                    // Debug.Log("curving TMP");
                    crvdVE.TesselationRequired = false;
                    crvdVE.CurvingRequired     = true;

#if UNITY_5_1
                    crvdVE.ModifyMesh(vh.GetUIVertexStream);
#else
                    crvdVE.ModifyMesh(vh);
#endif

                    vh.FillMesh(savedMesh);

                    curvingRequired = false;
                    savedSize       = (transform as RectTransform).rect.size;
                    savedUp         = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up);
                    savedPos        = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);
                }

                tmp.canvasRenderer.SetMesh(savedMesh);
            }
            else
            {
                DiscoverTMP();
            }
        }
Ejemplo n.º 15
0
        private IEnumerator Play_Private(string message, float duration, int fadeWidth, Func <bool> onFinished, UIView.MovableState state)
        {
            TextMeshProUGUI textMesh = _textMesh;

            textMesh.text = message;

            int   i, j, l = message.Length;
            float t, f;

            Modifier[] m = new Modifier[l];
            for (i = 0; i < l; i++)
            {
                m[i]       = new Modifier();
                m[i].alpha = 0;
            }

            SetModifiers(m);

            //----------------------------------

            if (duration <= 0)
            {
                duration = 0.05f;
            }

            if (fadeWidth <= 0)
            {
                // アルファフェードインを使わずに1文字ずつ表示する(時間は0.1)
                t = 0;
                for (i = 0; i < l; i++)
                {
                    while (t < duration)
                    {
                        t += Time.unscaledDeltaTime;

                        if (t >= duration)
                        {
                            m[i].alpha = 1;
                        }

                        SetModifiers(m, i, l - i);

                        if (t >= duration)
                        {
                            t -= duration;
                            break;
                        }

                        if (onFinished != null)
                        {
                            if (onFinished() == true)
                            {
                                break;                                  // 強制終了
                            }
                        }

                        yield return(null);
                    }
                }
            }
            else
            {
                // アルファフェードインを使い1文字ずつ表示する

                float wait = duration * fadeWidth;

                t = 0;
                for (i = 0; i < l; i++)
                {
                    while (t < wait)
                    {
                        t += Time.unscaledDeltaTime;

                        for (j = 0; j < fadeWidth; j++)
                        {
                            f = t - (duration * j);

                            if (f >= wait)
                            {
                                f = wait;
                            }
                            if (f < 0)
                            {
                                f = 0;
                            }

                            if (((i + j) < l) && f > 0)
                            {
                                m[i + j].alpha = (f / wait);
                            }
                        }

                        SetModifiers(m, i, l - i);

                        if (t >= wait)
                        {
                            t -= duration;

                            break;
                        }

                        if (onFinished != null)
                        {
                            if (onFinished() == true)
                            {
                                break;                                  // 強制終了
                            }
                        }

                        yield return(null);
                    }
                }
            }

            // 元の状態に戻す
            textMesh.ForceMeshUpdate();

            state.isDone = true;
        }
 [HarmonyAfter(new string[] { Plugin.SongCoreHarmonyId })] // SongCore patches the same method so we want to make sure our's is applied after.
 static void Postfix(LevelListTableCell __instance, ref IPreviewBeatmapLevel level, ref TextMeshProUGUI ____authorText)
 {
     ____authorText.text = $"({Plugin.Name}) {____authorText.text}";
     ____authorText.ForceMeshUpdate();
     Logger.log.Warn($"Changed: {____authorText.text}");
 }
Ejemplo n.º 17
0
 public void SetSpeechCloud(string text)
 {
     speechCloud.text = text;
     speechCloud.ForceMeshUpdate();
 }
Ejemplo n.º 18
0
    //IEnumerator TypeSentence (string sentence)
    IEnumerator TypeSentence(sent sentence)
    {
        if (sentence.whatsays == "Not me! Hey, little kid, you do it.")
        {
            GameObject.Find("Baby").GetComponent <Animator>().Play("into");
            GameObject.Find("BarsBeginning").GetComponent <Animator>().Play("slide");
        }
        //previousSpeaker.GetComponent<Animator>().SetBool("isTalking", true);
        nameText.text     = sentence.whosays;
        dialogueText.text = "";
        int count = previousSpeaker.GetComponent <NPC>().voiceCount - 1;
        //foreach (char letter in sentence.ToCharArray())

        bool precommand = false;
        bool startc     = false;

        foreach (char letter in sentence.whatsays)
        {
            startc = false;
            if (letter == '{')
            {
                precommand = true;
            }
            if (letter == '@')
            {
                if (precommand == false)
                {
                    precommand = true;
                    startc     = true;
                }
            }
            if (!precommand)
            {
                dialogueText.text += letter;
            }
            if (letter == '@')
            {
                if (precommand == true && !startc)
                {
                    precommand = false;
                }
            }
            if (letter == '}')
            {
                precommand = false;
            }
        }
        int totalVisibleCharacters = dialogueText.textInfo.characterCount;
        int visibleCount           = 0;

        dialogueText.maxVisibleCharacters = 0;
        char[] letterArr = dialogueText.text.ToCharArray();

        //Checking how many lines
        dialogueText.ForceMeshUpdate();
        float lineCount = dialogueText.textInfo.lineCount - 3;

        if (lineCount < 0)
        {
            lineCount = 0;
        }

        //Resetting
        dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition.x, 5.699997f);
        upperBox.GetComponent <RectTransform>().anchoredPosition            = new Vector2(upperBox.GetComponent <RectTransform>().anchoredPosition.x, 39.1f);
        nameText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(nameText.gameObject.GetComponent <RectTransform>().anchoredPosition.x, 110.2f);

        //Resizing
        dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition += new Vector2(0, 57.3f * lineCount);
        upperBox.GetComponent <RectTransform>().anchoredPosition            += new Vector2(0, 57.3f * lineCount);
        nameText.gameObject.GetComponent <RectTransform>().anchoredPosition += new Vector2(0, 57.3f * lineCount);

        foreach (char letter in sentence.whatsays)
        {
            if (letter == '+')
            {
                previousSpeaker.GetComponent <Animator>().SetBool("isTalking", false);
                DisplayNextSentence();
                break;
            }

            if (letter == '*')
            {
                command = !command;
                if (command == false)
                {
                    previousSpeaker.GetComponent <Animator>().Play(commandtext);
                    commandtext = "";
                }
            }

            if (letter == '{')
            {
                command = true;
            }

            if (letter == '}')
            {
                command = false;
                if (commandtext == "shake")
                {
                    //FindObjectOfType<CameraShake>().ShakeDefault();
                }
                if (commandtext.Length > 3)
                {
                    if (commandtext.Substring(0, 2) == "tp")
                    {
                        string coords = commandtext.Substring(3);
                        print(coords);
                        string x  = "";
                        string y  = "";
                        bool   yb = false;
                        foreach (char c in coords)
                        {
                            if (c == ',')
                            {
                                yb = true;
                            }
                            else
                            {
                                if (!yb)
                                {
                                    x += c;
                                }
                                if (yb)
                                {
                                    y += c;
                                }
                            }
                        }
                        previousSpeaker.transform.position = new Vector2(float.Parse(x), float.Parse(y));
                    }
                }

                if (commandtext.Length > 6)
                {
                    if (commandtext.Substring(0, 4) == "anim")
                    {
                        previousSpeaker.GetComponent <Animator>().Play(commandtext.Substring(5));
                    }
                }

                commandtext = "";
            }

            if (letter == '<')
            {
                tag = true;
            }

            if (letter == '@')
            {
                command = !command;
                if (command == false)
                {
                    yield return(new WaitForSeconds(float.Parse(commandtext)));

                    commandtext = "";
                }
            }

            if (letter == '#')
            {
                command = !command;
                if (command == false)
                {
                    previousSpeaker.GetComponent <NPC>().moveToX = float.Parse(commandtext);
                    previousSpeaker.GetComponent <Animator>().SetFloat("speed", 1);
                    commandtext = "";
                }
            }

            if (command == false)
            {
                if (letter != '*' && letter != '#' && letter != '@' && letter != '[' && letter != ']' && letter != '{' && letter != '}')
                {
                    if (!tag)
                    {
                        //if (tagtext != "")
                        //{
                        //    //dialogueText.text += tagtext;
                        //    tagtext = "";
                        //}

                        //New system thingy
                        visibleCount += 1;

                        dialogueText.maxVisibleCharacters = visibleCount;

                        count += 1;


                        //dialogueText.text += letter;
                        previousSpeaker.GetComponent <Animator>().SetBool("isTalking", true);
                        FindObjectOfType <GlobalDialogueManager>().dcp.GetComponentInChildren <Animator>().Play("DialogueBox_Open");
                    }
                }
            }
            if (command == true)
            {
                if (letter != '*' && letter != '#' && letter != '@' && letter != '{' && letter != '}')
                {
                    commandtext += letter;
                }
            }
            if (tag == true)
            {
                //tagtext += letter;
            }


            if (count == previousSpeaker.GetComponent <NPC>().voiceCount)
            {
                if (!command)
                {
                    try
                    {
                        audioManager.Play(previousSpeaker.name);
                    }
                    catch { }
                }
                count = 0;
            }

            if (!command && !tag)
            {
                yield return(new WaitForSeconds(0.02f));

                //wait more if punctuation
                if (letter == '.' || letter == '!')
                {
                    yield return(new WaitForSeconds(0.15f));
                }
            }
            if (letter == '>')
            {
                tag = false;
            }
        }
        previousSpeaker.GetComponent <Animator>().SetBool("isTalking", false);
    }
    public IEnumerator glowText(int wordPosition)
    {
        const float TRANSITION_TIME     = 0.8f;
        const float STEP_SIZE           = TRANSITION_TIME / 20;
        const float HORIZONTAL_INCREASE = 15.0f;
        const float VERTICAL_INCREASE   = 5f;

        textObject = gameObject.GetComponent <TextMeshProUGUI>();
        textObject.ForceMeshUpdate();

        int firstCharacter = textObject.textInfo.wordInfo[wordPosition].firstCharacterIndex;
        int lastCharacter  = textObject.textInfo.wordInfo[wordPosition].lastCharacterIndex;


        Vector3 topRight    = textObject.textInfo.characterInfo[lastCharacter].topRight;
        Vector3 bottomLeft  = textObject.textInfo.characterInfo[firstCharacter].bottomLeft;
        Vector3 centerPoint = (bottomLeft + topRight) / 2;
        Vector3 radius      = topRight - centerPoint;

        Vector3[] vertices;
        Vector3[] initialVertices     = (Vector3[])(textObject.textInfo.meshInfo[textObject.textInfo.characterInfo[firstCharacter].materialReferenceIndex].vertices.Clone());
        Vector3[] transformedVertices = (Vector3[])initialVertices.Clone();



        Color32 glowColour    = new Color32(72, 255, 0, 255);
        Color32 initialColour = textObject.textInfo.characterInfo[firstCharacter].color;

        initialColour = new Color32(initialColour.r, initialColour.g, initialColour.b, initialColour.a);

        Color32[] newVertexColors;

        yield return(new WaitForSeconds(0.3f));

        if (!GameManager.muted)
        {
            glowSound.Play();
        }

        //Calculate the transformed vertices
        for (int charPos = firstCharacter; charPos <= lastCharacter; charPos++)
        {
            TMP_CharacterInfo charInfo = textObject.textInfo.characterInfo[charPos];
            if (!charInfo.isVisible)
            {
                continue;
            }

            int materialIndex = charInfo.materialReferenceIndex;
            int vertexIndex   = charInfo.vertexIndex;

            for (int i = 0; i < 4; i++)
            {
                Vector3 corner      = transformedVertices[vertexIndex + i];
                Vector3 translation = new Vector3(((corner.x - centerPoint.x) / radius.x) * HORIZONTAL_INCREASE, ((corner.y - centerPoint.y) / radius.y) * VERTICAL_INCREASE, 0);
                transformedVertices[vertexIndex + i] += translation;
            }
        }


        float currentTime = 0;

        while (currentTime <= TRANSITION_TIME)
        {
            textObject.ForceMeshUpdate();
            float   interpolatePosition = (TRANSITION_TIME - 2 * Math.Abs(TRANSITION_TIME / 2 - currentTime)) / TRANSITION_TIME;
            Color32 currentColour       = Color32.Lerp(initialColour, glowColour, interpolatePosition);


            for (int charPos = firstCharacter; charPos <= lastCharacter; charPos++)
            {
                TMP_CharacterInfo charInfo = textObject.textInfo.characterInfo[charPos];
                if (!charInfo.isVisible)
                {
                    continue;
                }

                int materialIndex = charInfo.materialReferenceIndex;
                int vertexIndex   = charInfo.vertexIndex;

                newVertexColors = textObject.textInfo.meshInfo[materialIndex].colors32;
                vertices        = textObject.textInfo.meshInfo[materialIndex].vertices;

                for (int i = 0; i < 4; i++)
                {
                    newVertexColors[vertexIndex + i] = currentColour;
                    vertices[vertexIndex + i]        = (1 - interpolatePosition) * initialVertices[vertexIndex + i] + interpolatePosition * transformedVertices[vertexIndex + i];
                }
            }

            currentTime += STEP_SIZE;

            textObject.UpdateVertexData();

            yield return(new WaitForSeconds(STEP_SIZE));
        }

        //Ensure values back to original
        for (int charPos = firstCharacter; charPos <= lastCharacter; charPos++)
        {
            TMP_CharacterInfo charInfo = textObject.textInfo.characterInfo[charPos];
            if (!charInfo.isVisible)
            {
                continue;
            }

            int materialIndex = charInfo.materialReferenceIndex;
            int vertexIndex   = charInfo.vertexIndex;

            newVertexColors = textObject.textInfo.meshInfo[materialIndex].colors32;
            vertices        = textObject.textInfo.meshInfo[materialIndex].vertices;

            for (int i = 0; i < 4; i++)
            {
                newVertexColors[vertexIndex + i] = initialColour;
                vertices[vertexIndex + i]        = initialVertices[vertexIndex + i];
            }
        }

        glowSound.Stop();
    }
Ejemplo n.º 20
0
 private void HideText(int numToShow = 0)
 {
     textField.firstVisibleCharacter = 0;
     textField.maxVisibleCharacters  = numToShow;
     textField.ForceMeshUpdate();
 }
 private void Awake()
 {
     textObject = gameObject.GetComponent <TextMeshProUGUI>();
     textObject.ForceMeshUpdate();
 }
Ejemplo n.º 22
0
        void LateUpdate()
        {
            //if we're missing stuff, find it
            if (!tmpText)
            {
                FindTMP();
            }

            if (mySettings == null)
            {
                return;
            }

            //Edit Mesh on TextMeshPro component
            if (tmpText && !quitting)
            {
                if (ShouldTesselate())
                {
                    tesselationRequired = true;
                }

                if (Dirty || tesselationRequired || (curvingRequired && !Application.isPlaying))
                {
                    if (mySettings == null)
                    {
                        enabled = false;
                        return;
                    }

                    //Get the flat vertices from TMP object.
                    //store a copy of flat UIVertices for later so we dont have to retrieve the Mesh every framee.
                    tmpText.renderMode = TMPro.TextRenderFlags.Render;
                    tmpText.ForceMeshUpdate(true);
                    CreateUIVertexList(tmpText.mesh);

                    //Tesselate and Curve the flat UIVertices stored in Vertex Helper
                    crvdVE.ModifyTMPMesh(ref m_UIVerts);

                    //fill curved vertices back to TMP mesh
                    FillMeshWithUIVertexList(tmpText.mesh, m_UIVerts);

                    //cleanup
                    tmpText.renderMode = TMPro.TextRenderFlags.DontRender;

                    //save current data
                    savedLocalScale  = mySettings.transform.localScale;
                    savedGlobalScale = mySettings.transform.lossyScale;
                    savedSize        = (transform as RectTransform).rect.size;
                    savedUp          = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up);
                    savedPos         = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);

                    //reset flags
                    tesselationRequired = false;
                    curvingRequired     = false;
                    Dirty = false;

                    //prompt submeshes to update
                    FindSubmeshes();
                    foreach (CurvedUITMPSubmesh mesh in subMeshes)
                    {
                        mesh.UpdateSubmesh(true, false);
                    }
                }

                //Upload mesh to TMP Object's renderer
                tmpText.canvasRenderer.SetMesh(tmpText.mesh);
            }
        }
Ejemplo n.º 23
0
    public void ChangePosition()
    {
        // ESTA VERSION SIRVE PARA CUANDO ESTAN LOS ANCHORS JUNTOS

        // 1 - INSTANCIAMOS EL OBJETO Y SETEAMOS TODAS SUS PROPIEDADES PARA DARLE EL TAMANO CORRECTO FINAL
        // EL OBJETIVO DE ESTO ES QUE EL OBJETO TENGA EL TAMANO REAL QUE SE VA A MOSTRAR PARA OBTENER SUS LIMITES
        infoTextMesh.SetText(txtToSet);
        // FORZAMOS EL UPDATEO YA QUE SI NO EL CALCULO RECIEN DEBERIA HACERSE EN EL "SIGUIENTE FRAME" CUANDO TENGA EL TAMAÑO REAL
        infoTextMesh.ForceMeshUpdate();

        Vector2 textSize    = infoTextMesh.GetRenderedValues(false);
        Vector2 paddingSize = new Vector2(8, 8);

        uiToTestRectTransform.sizeDelta = textSize + paddingSize;
        infoTextMesh.ForceMeshUpdate();



        // 4 - NECESITAMOS LA POSICION DEL OBJETO QUE ESTAMOS SOBRE.... uiMouseOverTest
        Vector2 anchoredPos = uiMouseOverTest.anchoredPosition;

        float anchorMinXUIMouseOver = uiMouseOverTest.anchorMin.x;
        float anchorManXUIMouseOver = uiMouseOverTest.anchorMax.x;
        float anchorMinYUIMouseOver = uiMouseOverTest.anchorMin.y;
        float anchorManYUIMouseOver = uiMouseOverTest.anchorMax.y;
        // convertir esos anchor viewport to screen point
        Vector3 origin = Camera.main.ViewportToScreenPoint(new Vector3(anchorMinXUIMouseOver, anchorMinYUIMouseOver, 0));

        //Vector3 extent = Camera.main.ViewportToScreenPoint(new Vector3(anchorManXUIMouseOver, anchorManYUIMouseOver, 0));

        // DE ESTA PUTA MANERA HORRIBLE, OBTENEMOS LA POSICION EN SCREEN POINT DE LOS ANCHORS DE LA UI MOUSE OVER CORRECTAMENTE
        origin = origin / canvas.scaleFactor;

        // ESTAS SON LAS POSICION EN SCREEN POINT FINALES DEL OBJETO DE LA UI SOBRE EL CUAL TENEMOS EL MOUSE OVER PARA MOSTRAR LA INFORMACION
        float diferenceBetweenAnchorAndUIPositionX = (origin.x) - (-1 * anchoredPos.x);
        float diferenceBetweenAnchorAndUIPositionY = (origin.y) - (-1 * anchoredPos.y);


        // 5 - NECESITAMOS EL TAMANO DEL OBJETO SOBRE EL CUAL TENEMOS EL MOUSE OVER
        float mouseOverTotalWidth  = uiMouseOverTest.rect.size.x;
        float mouseOverTotalHeight = uiMouseOverTest.rect.size.y;

        // ACA DEPENDE DE QUE LADO DE LA PANTALLA ESTE IZQUIERDA O DERECHA, VAMOS A POSICIONAR EL CARTEL DE INFORMACION DEL LADO CONTRARIO
        // POR ENDE, SI ESTAMOS DEL LADO IZQUIERDO DE LA PANTALLA NUESTRO CARTEL SE VA A POSICIONAR A LA DERECHA DEL OBJETO QUE ESTAMOS SOBRE
        // SI ESTAMOS DEL LADO DERECHO DE LA PANTALLA, NUESTRO CARTEL SE VA A POSICIONAR A LA IZQUIERDA DEL OBJETO QUE ESTAMOS SOBRE
        float posXRepositionFromUIObject = diferenceBetweenAnchorAndUIPositionX + (mouseOverTotalWidth / 2);
        //float posYRepositionFromUIObject = diferenceBetweenAnchorAndUIPositionY + (mouseOverTotalHeight / 2);


        // SEGUN EL LADO DE LA PANTALLA QUE ESTEMOS LO INSTANCIAMOS A LA IZQUIERDA O LA DERECHA
        float finalPosX = diferenceBetweenAnchorAndUIPositionX + (mouseOverTotalWidth / 2) + (uiToTestRectTransform.rect.size.x / 2);

        if (diferenceBetweenAnchorAndUIPositionX > (canvasScaler.referenceResolution.x / 2))
        {
            finalPosX = diferenceBetweenAnchorAndUIPositionX - (mouseOverTotalWidth / 2) - (uiToTestRectTransform.rect.size.x / 2);
        }

        // centrado al objeto que estamos sobre en la altura
        float finalPosY = diferenceBetweenAnchorAndUIPositionY;

        // OBTENEMOS EL TAMANO ACTUAL DEL RECT DEL CANVAS
        float CanvasWidth  = canvasTransform.rect.width;
        float CanvasHeight = canvasTransform.rect.height;


        // 6 - OBTENGO EL TAMANO MIN/MAX DE POSICIONAMIENTO EN LA PANTALLA
        // ESTO SE OBTIENE SEGUN EL TAMANO DEL OBJETO QUE QUEREMOS POSICIONAR Y LA RESOLUCION DEL SCALER
        float minX = (uiToTestRectTransform.rect.size.x / 2);
        /*float maxX = (canvasScaler.referenceResolution.x - minX);*/ // ESTO SIEMPRE VA A TRABAJAR CON UNA RESOLUCION DE REFERENCIA... LO QUE NECESITAMOS ES LA ACTUAL RESOLUTION
        float maxX = (CanvasWidth - minX);

        float minY = (uiToTestRectTransform.rect.size.y * 0.5f);
        //float maxY = (canvasScaler.referenceResolution.y - minY);
        float maxY = (CanvasHeight - minY);
        // DE ESTA MANERA GARANTIZAMOS QUE EL OBJETO NO SE VAYA DEL MAXIMO DE LA PANTALLA
        Vector3 posToReturn = new Vector3(Mathf.Clamp(finalPosX, minX, maxX), Mathf.Clamp(finalPosY, minY, maxY));

        uiToTestRectTransform.anchoredPosition = posToReturn;
    }
    IEnumerator AnimateVertexColors(byte toAlpha)
    {
        // Need to force the text object to be generated so we have valid data to work with right from the start.
        ChildTextMeshPro.ForceMeshUpdate();

        TMP_TextInfo textInfo = ChildTextMeshPro.textInfo;

        Color32[] newVertexColors;

        int  currentCharacter       = 0;
        int  startingCharacterRange = currentCharacter;
        bool isRangeMax             = false;

        while (!isRangeMax)
        {
            for (int i = startingCharacterRange; i < currentCharacter + 1; i++)
            {
                int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int  vertexIndex = textInfo.characterInfo[i].vertexIndex;
                byte newAlpha    = newVertexColors[vertexIndex].a;
                if (toAlpha > newAlpha)
                {
                    newAlpha = (byte)Mathf.Clamp(newAlpha + (byte)AnimateSpeed, 0, 255);
                }
                else if (toAlpha < newAlpha)
                {
                    newAlpha = (byte)Mathf.Clamp(newAlpha - (byte)AnimateSpeed, 0, 255);
                }
                for (var vc = 0; vc < newVertexColors.Length; vc++)
                {
                    newVertexColors[vc].a = newAlpha;
                }
                if (newAlpha == toAlpha)
                {
                    startingCharacterRange += 1;

                    if (startingCharacterRange == textInfo.characterCount)
                    {
                        yield return(new WaitForSeconds(1.0f));

                        ChildTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                        currentCharacter       = 0;
                        startingCharacterRange = 0;
                        isRangeMax             = true;
                    }
                }
            }

            // Upload the changed vertex colors to the Mesh.
            ChildTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

            if (currentCharacter + 1 < textInfo.characterCount)
            {
                currentCharacter += 1;
            }
            yield return(new WaitForSeconds(0.05f));
        }
        if (LoopAnimation)
        {
            if (toAlpha == 0)
            {
                AnimateFadeIn();
            }
            else
            {
                AnimateFadeIn();
            }
        }
    }
Ejemplo n.º 25
0
        public static UISlider Create(CreateArgs input)
        {
            GameObject go = new GameObject(input.widgetName);

            go.tag = "UICollider";

            // Find the anchor of the parent if it is a UIElement
            Vector3 parentAnchor = Vector3.zero;

            if (input.parent)
            {
                UIElement elem = input.parent.gameObject.GetComponent <UIElement>();
                if (elem)
                {
                    parentAnchor = elem.Anchor;
                }
            }

            UISlider uiSlider = go.AddComponent <UISlider>(); // NOTE: also creates the MeshFilter, MeshRenderer and Collider components

            uiSlider.relativeLocation        = input.relativeLocation;
            uiSlider.transform.parent        = input.parent;
            uiSlider.transform.localPosition = parentAnchor + input.relativeLocation;
            uiSlider.transform.localRotation = Quaternion.identity;
            uiSlider.transform.localScale    = Vector3.one;
            uiSlider.width                     = input.width;
            uiSlider.height                    = input.height;
            uiSlider.margin                    = input.margin;
            uiSlider.thickness                 = input.thickness;
            uiSlider.sliderPositionBegin       = input.sliderBegin;
            uiSlider.sliderPositionEnd         = input.sliderEnd;
            uiSlider.railMargin                = input.railMargin;
            uiSlider.railThickness             = input.railThickness;
            uiSlider.knobRadius                = input.knobRadius;
            uiSlider.knobDepth                 = input.knobDepth;
            uiSlider.dataSource                = input.dataSource;
            uiSlider.minValue                  = input.minValue;
            uiSlider.maxValue                  = input.maxValue;
            uiSlider.currentValue              = input.currentValue;
            uiSlider.textContent               = input.caption;
            uiSlider.sourceMaterial            = input.material;
            uiSlider.sourceRailMaterial        = input.railMaterial;
            uiSlider.sourceKnobMaterial        = input.knobMaterial;
            uiSlider.baseColor.useConstant     = false;
            uiSlider.baseColor.reference       = input.color;
            uiSlider.textColor.useConstant     = false;
            uiSlider.textColor.reference       = input.textColor;
            uiSlider.pushedColor.useConstant   = false;
            uiSlider.pushedColor.reference     = input.pushedColor;
            uiSlider.selectedColor.useConstant = false;
            uiSlider.selectedColor.reference   = input.selectedColor;

            // Setup the Meshfilter
            MeshFilter meshFilter = go.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshFilter.sharedMesh = UIUtils.BuildRoundedBox(input.width, input.height, input.margin, input.thickness);
                uiSlider.Anchor       = Vector3.zero;
                BoxCollider coll = go.GetComponent <BoxCollider>();
                if (coll != null)
                {
                    Vector3 initColliderCenter = meshFilter.sharedMesh.bounds.center;
                    Vector3 initColliderSize   = meshFilter.sharedMesh.bounds.size;
                    if (initColliderSize.z < UIElement.collider_min_depth_shallow)
                    {
                        coll.center = new Vector3(initColliderCenter.x, initColliderCenter.y, UIElement.collider_min_depth_shallow / 2.0f);
                        coll.size   = new Vector3(initColliderSize.x, initColliderSize.y, UIElement.collider_min_depth_shallow);
                    }
                    else
                    {
                        coll.center = initColliderCenter;
                        coll.size   = initColliderSize;
                    }
                    coll.isTrigger = true;
                }
            }

            // Setup the MeshRenderer
            MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>();

            if (meshRenderer != null && input.material != null)
            {
                // Clone the material.
                meshRenderer.sharedMaterial = Instantiate(input.material);

                meshRenderer.shadowCastingMode  = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.renderingLayerMask = 2; // "LightLayer 1"

                uiSlider.SetColor(input.color.value);
            }

            //
            // RAIL
            //

            float   railWidth     = (input.width - 2 * input.margin) * (input.sliderEnd - input.sliderBegin);
            float   railHeight    = 3 * uiSlider.railMargin; // TODO: see if we can tie this to another variable, like height.
            float   railThickness = uiSlider.railThickness;
            float   railMargin    = uiSlider.railMargin;
            Vector3 railPosition  = new Vector3(input.margin + (input.width - 2 * input.margin) * input.sliderBegin, -input.height / 2, -railThickness); // put z = 0 back

            uiSlider.rail = UISliderRail.Create(
                new UISliderRail.CreateArgs
            {
                parent           = go.transform,
                widgetName       = "Rail",
                relativeLocation = railPosition,
                width            = railWidth,
                height           = railHeight,
                thickness        = railThickness,
                margin           = railMargin,
                material         = input.railMaterial,
                c = input.railColor
            }
                );

            // KNOB
            float newKnobRadius = uiSlider.knobRadius;
            float newKnobDepth  = uiSlider.knobDepth;

            float pct = (uiSlider.currentValue - uiSlider.minValue) / (uiSlider.maxValue - uiSlider.minValue);

            float widthWithoutMargins = input.width - 2.0f * input.margin;
            float startX = input.margin + widthWithoutMargins * uiSlider.sliderPositionBegin + railMargin;
            float endX   = input.margin + widthWithoutMargins * uiSlider.sliderPositionEnd - railMargin;
            float posX   = startX + pct * (endX - startX);

            Vector3 knobPosition = new Vector3(posX - uiSlider.knobRadius, uiSlider.knobRadius - (uiSlider.height / 2.0f), -uiSlider.knobDepth);

            uiSlider.knob = UISliderKnob.Create(
                new UISliderKnob.CreateArgs
            {
                widgetName       = "Knob",
                parent           = go.transform,
                relativeLocation = knobPosition,
                radius           = newKnobRadius,
                depth            = newKnobDepth,
                material         = input.knobMaterial,
                c = input.knobColor
            }
                );

            //
            // CANVAS (to hold the 2 texts)
            //

            GameObject canvas = new GameObject("Canvas");

            canvas.transform.parent = uiSlider.transform;

            Canvas c = canvas.AddComponent <Canvas>();

            c.renderMode = RenderMode.WorldSpace;

            RectTransform rt = canvas.GetComponent <RectTransform>(); // auto added when adding Canvas

            rt.localScale    = Vector3.one;
            rt.localRotation = Quaternion.identity;
            rt.anchorMin     = new Vector2(0, 1);
            rt.anchorMax     = new Vector2(0, 1);
            rt.pivot         = new Vector2(0, 1); // top left
            rt.sizeDelta     = new Vector2(uiSlider.width, uiSlider.height);
            rt.localPosition = Vector3.zero;

            CanvasScaler cs = canvas.AddComponent <CanvasScaler>();

            cs.dynamicPixelsPerUnit   = 300; // 300 dpi, sharp font
            cs.referencePixelsPerUnit = 100; // default?

            // Add a Text under the Canvas
            if (input.caption.Length > 0)
            {
                GameObject text = new GameObject("Text");
                text.transform.parent = canvas.transform;

                TextMeshProUGUI t = text.AddComponent <TextMeshProUGUI>();
                t.text             = input.caption;
                t.enableAutoSizing = true;
                t.fontSizeMin      = 1;
                t.fontSizeMax      = 500;
                t.fontStyle        = FontStyles.Normal;
                t.alignment        = TextAlignmentOptions.Left;
                t.color            = input.textColor.value;
                t.ForceMeshUpdate();

                RectTransform trt = t.GetComponent <RectTransform>();
                trt.localScale    = 0.01f * Vector3.one;
                trt.localRotation = Quaternion.identity;
                trt.anchorMin     = new Vector2(0, 1);
                trt.anchorMax     = new Vector2(0, 1);
                trt.pivot         = new Vector2(0, 1); // top left
                trt.sizeDelta     = new Vector2((uiSlider.width - 2 * uiSlider.margin) * uiSlider.sliderPositionBegin * 100.0f, (input.height - 2.0f * input.margin) * 100.0f);
                float textPosLeft = uiSlider.margin;
                trt.localPosition = new Vector3(textPosLeft, -uiSlider.margin, -0.002f);
            }

            // Text VALUE
            //if (caption.Length > 0)
            {
                GameObject text = new GameObject("TextValue");
                text.transform.parent = canvas.transform;

                TextMeshProUGUI t = text.AddComponent <TextMeshProUGUI>();
                t.text             = input.currentValue.ToString("#0.00");
                t.enableAutoSizing = true;
                t.fontSizeMin      = 1;
                t.fontSizeMax      = 500;
                t.fontSize         = 1.85f;
                t.fontStyle        = FontStyles.Normal;
                t.alignment        = TextAlignmentOptions.Right;
                t.color            = input.textColor.value;

                RectTransform trt = t.GetComponent <RectTransform>();
                trt.localScale    = 0.01f * Vector3.one;
                trt.localRotation = Quaternion.identity;
                trt.anchorMin     = new Vector2(0, 1);
                trt.anchorMax     = new Vector2(0, 1);
                trt.pivot         = new Vector2(1, 1); // top right?
                trt.sizeDelta     = new Vector2((uiSlider.width - 2 * uiSlider.margin) * (1 - uiSlider.sliderPositionEnd) * 100.0f, (input.height - 2.0f * input.margin) * 100.0f);
                float textPosRight = uiSlider.width - uiSlider.margin;
                trt.localPosition = new Vector3(textPosRight, -uiSlider.margin, -0.002f);
            }

            UIUtils.SetRecursiveLayer(go, "CameraHidden");

            return(uiSlider);
        }
Ejemplo n.º 26
0
        protected void UpdateVertices()
        {
            if (TextWarpFunction == null || !TextMeshProUGUI)
            {
                return;
            }
            m_forceUpdate = false;

            //during the loop, vertices represents the 4 vertices of a single character we're analyzing,
            //while matrix is the roto-translation matrix that will rotate and scale the characters so that they will
            //follow the curve
            Vector3[] vertices;
            Matrix4x4 matrix;

            //Generate the mesh and get information about the text and the characters
            TextMeshProUGUI.ForceMeshUpdate();

            TMP_TextInfo textInfo = TextMeshProUGUI.textInfo;

            if (textInfo == null)
            {
                return;
            }
            int characterCount = textInfo.characterCount;

            //if the string is empty, no need to waste time
            if (characterCount == 0)
            {
                return;
            }

            //gets the bounds of the rectangle that contains the text
            float boundsMinX = TextMeshProUGUI.bounds.min.x;
            float boundsMaxX = TextMeshProUGUI.bounds.max.x;

            //for each character
            for (int i = 0; i < characterCount; i++)
            {
                //skip if it is invisible
                if (!textInfo.characterInfo[i].isVisible)
                {
                    continue;
                }

                //Get the index of the mesh used by this character, then the one of the material... and use all this data to get
                //the 4 vertices of the rect that encloses this character. Store them in vertices
                int vertexIndex   = textInfo.characterInfo[i].vertexIndex;
                int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
                vertices = textInfo.meshInfo[materialIndex].vertices;

                //Compute the baseline mid point for each character. This is the central point of the character.
                //we will use this as the point representing this character for the geometry transformations
                Vector3 charMidBaselinePos =
                    new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);

                //remove the central point from the vertices point. After this operation, every one of the four vertices
                //will just have as coordinates the offset from the central position. This will come handy when will deal with the rotations
                vertices[vertexIndex + 0] += -charMidBaselinePos;
                vertices[vertexIndex + 1] += -charMidBaselinePos;
                vertices[vertexIndex + 2] += -charMidBaselinePos;
                vertices[vertexIndex + 3] += -charMidBaselinePos;

                //compute the horizontal position of the character relative to the bounds of the box, in a range [0, 1]
                //where 0 is the left border of the text and 1 is the right border
                float zeroToOnePos = (charMidBaselinePos.x - boundsMinX) / (boundsMaxX - boundsMinX);

                //get the transformation matrix, that maps the vertices, seen as offset from the central character point, to their final
                //position that follows the curve
                matrix = TextWarpFunction.ComputeTransformationMatrix(charMidBaselinePos, zeroToOnePos, textInfo, i);

                //apply the transformation, and obtain the final position and orientation of the 4 vertices representing this char
                vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
                vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
                vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
                vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
            }

            //Upload the mesh with the revised information
            TextMeshProUGUI.UpdateVertexData();
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Set the text based on the linkId provided
 /// </summary>
 /// <param name="startingCountForLinkID"></param>
 public void SetText(int startingCountForLinkID)
 {
     _textFieldTMP      = textFieldObject.GetComponent <TextMeshProUGUI>();
     _textFieldTMP.text = HtmlIfyString(discrepancyField, startingCountForLinkID);
     _textFieldTMP.ForceMeshUpdate();
 }
Ejemplo n.º 28
0
        //---------------------------------------------------------------------------

        // ルビフリ方法
        // http://baba-s.hatenablog.com/entry/2019/01/10/122500

        /// <summary>
        /// 文字単位で色を設定する
        /// </summary>
        /// <param name="colors"></param>
        public bool SetColors(Color32[] colors, int offset = 0, int length = 0)
        {
            TextMeshProUGUI textMesh = _textMesh;

            if (textMesh == null || colors == null || colors.Length == 0)
            {
                return(false);
            }

            textMesh.ForceMeshUpdate();

            //----------------------------------------------------------

            TMP_TextInfo textInfo = textMesh.textInfo;

            if (textInfo == null || textInfo.characterCount == 0)
            {
                // 文字が存在しない
                return(true);
            }

            //--------------

            if (length <= 0)
            {
                length = colors.Length;
            }

            if (offset < 0)
            {
                length += offset;
                offset  = 0;
            }

            if (length <= 0 || offset >= colors.Length || offset >= textInfo.characterCount)
            {
                // 結果として変化は無い
                return(true);
            }

            if ((offset + length) > colors.Length)
            {
                length = colors.Length - offset;
            }

            if ((offset + length) > textInfo.characterCount)
            {
                length = textInfo.characterCount - offset;
            }

            //----------------------------------------------------------

            int vertexIndex;
            int materialIndex = 0;

            Color32[] baseColors;

            Color32 replaceColor;

            int i, j, p;

            for (i = 0; i < length; i++)
            {
                p = offset + i;

                if (textInfo.characterInfo[p].isVisible == true)
                {
                    if (textInfo.characterInfo[p].isVisible == true)
                    {
                        vertexIndex = textInfo.characterInfo[p].vertexIndex;

                        materialIndex = textInfo.characterInfo[p].materialReferenceIndex;

                        baseColors = textInfo.meshInfo[materialIndex].colors32;

                        replaceColor = new Color32
                                       (
                            colors[p].r,
                            colors[p].g,
                            colors[p].b,
                            colors[p].a
                                       );

                        for (j = 0; j < 4; j++)
                        {
                            baseColors[vertexIndex + j] = replaceColor;
                        }
                    }
                }
            }

            //----------------------------------------------------------

            textMesh.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

            return(true);
        }
    private IEnumerator ReadLine()
    {
        audioSource.pitch = dialogue1.interlocutor.pitch;
        foreach (string stringLine in dialogue1.lines)
        {
            m_TextMeshPro.text = stringLine;
            int totalVisibleCharacters = m_TextMeshPro.textInfo.characterCount;
            m_TextMeshPro.maxVisibleCharacters = 0;
            m_TextMeshPro.ForceMeshUpdate();
            char[] line = RemoveAccents(m_TextMeshPro.GetParsedText().ToLower()).ToCharArray();

            for (int i = 0; i < line.Length; i++)
            {
                m_TextMeshPro.maxVisibleCharacters = i + 1;

                if (line[i] != ' ' && line[i] != ',' && line[i] != '\'')
                {
                    if (line[i] == 'y')
                    {
                        line[i] = 'i';
                    }
                    if (isVoyelle(line[i]))
                    {
                        audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i]]);
                    }
                    else if (isConsonne(line[i]))
                    {
                        if (i + 1 < line.Length)
                        {
                            if (isComplex(line[i]) && line[i + 1] == 'h')
                            {
                                if (i + 2 < line.Length && isVoyelle(line[i + 2]))
                                {
                                    audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i] + line[i + 1] + line[i + 2]]);
                                }
                                else
                                {
                                    audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i] + line[i + 1] + ('e')]);
                                }
                                i++;
                            }
                            else
                            {
                                if (line[i] == 'y')
                                {
                                    line[i] = 'i';
                                }
                                if (isVoyelle(line[i + 1]))
                                {
                                    audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i] + line[i + 1]]);
                                }
                                else
                                {
                                    audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i] + ('e')]);
                                }
                            }
                        }
                        else
                        {
                            audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["" + line[i] + ('e')]);
                        }
                    }
                    else
                    {
                        audioSource.PlayOneShot(values[dialogue1.interlocutor.name]["_punctuation"]);
                    }
                }

                yield return(new WaitForSecondsRealtime((faster == true) ? 0.01f : 0.06f));
            }
            nextLine = false;
            faster   = false;
            yield return(new WaitUntil(() => nextLine == true));
        }
        nextDialogue      = true;
        dialogueMustStart = false;
    }
Ejemplo n.º 30
0
    void Update()
    {
        // メッシュ更新
        textMeshPro.ForceMeshUpdate();

        //テキストメッシュプロの情報
        var textInfo = textMeshPro.textInfo;

        //テキスト数がゼロであれば表示しない
        if (textInfo.characterCount == 0)
        {
            return;
        }


        //1文字毎にloop
        for (int index = 0; index < textInfo.characterCount; index++)
        {
            //1文字単位の情報
            var charaInfo = textInfo.characterInfo[index];

            //ジオメトリない文字はスキップ
            if (!charaInfo.isVisible)
            {
                continue;
            }

            //Material参照しているindex取得
            int materialIndex = charaInfo.materialReferenceIndex;

            //頂点参照しているindex取得
            int vertexIndex = charaInfo.vertexIndex;

            //テキスト全体の頂点を格納(変数のdestは、destinationの略)
            Vector3[] destVertices = textInfo.meshInfo[materialIndex].vertices;

            //移動する分
            float sinValue = Mathf.Sin(Time.time * animationSpeed + 10 * index);

            Vector3 dic = new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f));

            // メッシュ情報にアニメーション後の頂点情報を入れる

            /*
             * destVertices[vertexIndex + 0] += distanceMove * (Vector3.down * sinValue);
             * destVertices[vertexIndex + 1] += distanceMove * (Vector3.down * sinValue);
             * destVertices[vertexIndex + 2] += distanceMove * (Vector3.down * sinValue);
             * destVertices[vertexIndex + 3] += distanceMove * (Vector3.down * sinValue);
             */


            Vector3[] vertDic = vertAnim();

            destVertices[vertexIndex + 0] += vertDic[0];
            destVertices[vertexIndex + 1] += vertDic[1];
            destVertices[vertexIndex + 2] += vertDic[2];
            destVertices[vertexIndex + 3] += vertDic[3];
        }

        //ジオメトリ更新
        for (int i = 0; i < textInfo.meshInfo.Length; i++)
        {
            //メッシュ情報を、実際のメッシュ頂点へ反映
            textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
            textMeshPro.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
        }
    }
Ejemplo n.º 31
0
        private void _showPopup(string phraseStart, PopupFacingDir dir, DPCameraOverlay dpParent, RectTransform element)
        {
            //Check to see if the user is still hovering on the same element or not
            if (_potentialPopupElement != element)
            {
                return;
            }

            //Debug.Log(offset);

            _popupShouldBeActive = true;


            title.SetText(LeanLocalization.GetTranslationText(phraseStart + "Title"));
            desc.SetText(LeanLocalization.GetTranslationText(phraseStart + "Desc"));

            title.ForceMeshUpdate();
            desc.ForceMeshUpdate();


            //Canvas.ForceUpdateCanvases();
            LayoutRebuilder.ForceRebuildLayoutImmediate(bg);
            bg.gameObject.SetActive(false);
            bg.gameObject.SetActive(true);

            //transform.parent.GetComponent<VerticalLayoutGroup>().enabled = false;
            //transform.parent.GetComponent<VerticalLayoutGroup>().enabled = true;

            //fitter.enabled = false;
            //fitter.enabled = true;


            //Figure out the right location:
            Vector3 spawnOffset;


            switch (dir)
            {
            case PopupFacingDir.Left:
                spawnOffset            = new Vector3(1, 0, 0);
                arrow.anchoredPosition = new Vector2(-123 - 5, ((bg.rect.height + bg.rect.position.y) / 2) + 5);
                arrow.localEulerAngles = new Vector3(0, 0, -90);

                break;

            default:
            case PopupFacingDir.Down:
                spawnOffset            = new Vector3(0, 0.08f, -0.01f);
                arrow.anchoredPosition = new Vector2(0, 0);
                arrow.localEulerAngles = new Vector3(0, 0, 0);

                break;


            case PopupFacingDir.Right:
                spawnOffset            = new Vector3(-1, 0, 0);
                arrow.anchoredPosition = new Vector2(123, ((bg.rect.height + bg.rect.position.y) / 2) + 5);
                arrow.localEulerAngles = new Vector3(0, 0, 90);

                break;

            case PopupFacingDir.TheBar:
                spawnOffset            = new Vector3(0, 0.1f, 0.06f);
                arrow.anchoredPosition = new Vector2(0, 0);
                arrow.localEulerAngles = new Vector3(0, 0, 0);

                break;
            }


            //Vector3 dpPos = dpParent.transform.position;


            Vector3 goodRot = new Vector3(0, dpParent.transform.eulerAngles.y, 0);


            dpParent.SetOtherTransformRelativeToElement(hoverDP.transform, element, spawnOffset);

            hoverDP.SetOverlayPositionWithCurrent(true, false);


            //hoverDP.SetOverlayPosition(goodPos, goodRot, true, false);
            hoverDP.TransitionOverlayOpacity(1f, 0.5f);


            hoverDP.RequestRendering(true);

            _popupIsActive = true;
        }
Ejemplo n.º 32
0
        void LateUpdate()
        {
            //if we're missing stuff, find it
            if (!tmpText)
            {
                FindTMP();
            }


            //Edit Mesh on TextMeshPro component
            if (tmpText)
            {
                //if (!Application.isPlaying)
                //    tesselationRequired = true;


                if (savedSize != (transform as RectTransform).rect.size)
                {
                    tesselationRequired = true;
                    //Debug.Log("size changed");
                }
                else if (savedLocalScale != mySettings.transform.localScale)
                {
                    tesselationRequired = true;
                    //Debug.Log("size changed");
                }
                else if (!savedPos.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position)))
                {
                    curvingRequired = true;
                    // Debug.Log("pos changed");
                }
                else if (!savedUp.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up)))
                {
                    curvingRequired = true;
                    // Debug.Log("up changed");
                }


                if (Dirty || tesselationRequired || m_savedMesh == null || m_vh == null || (curvingRequired && !Application.isPlaying))
                {
                    //Get the mesh from TMP object.
                    tmpText.renderMode = TMPro.TextRenderFlags.Render;
                    tmpText.ForceMeshUpdate();
                    if (m_vh != null)
                    {
                        m_vh.Dispose();
                    }
                    m_vh = new VertexHelper(tmpText.mesh);

                    //store a copy of flat UIVertices for later so we dont have to retrieve the Mesh every framee.
                    m_vh.GetUIVertexStream(m_flatSavedVerts);

                    //Tesselate and Curve the flat UIVertices stored in Vertex Helper
                    crvdVE.TesselationRequired = true;
                    crvdVE.ModifyMesh(m_vh);


                    //fill the mesh with curved UIVertices
                    if (!m_savedMesh)
                    {
                        m_savedMesh = new Mesh();
                    }
                    m_savedMesh.Clear();
                    m_vh.FillMesh(m_savedMesh);
                    tmpText.renderMode = TMPro.TextRenderFlags.DontRender;

                    //reset flags
                    tesselationRequired = false;
                    curvingRequired     = false;
                    Dirty = false;

                    //save current data
                    savedLocalScale = mySettings.transform.localScale;
                    savedSize       = (transform as RectTransform).rect.size;
                    savedUp         = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up);
                    savedPos        = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);

                    //prompt submeshes to update
                    FindSubmeshes();
                    foreach (CurvedUITMPSubmesh mesh in subMeshes)
                    {
                        mesh.UpdateSubmesh(true, false);
                    }
                }


                if (curvingRequired)
                {
                    //fill the VertexHelper with stored flat mesh
                    m_vh.Clear();
                    m_vh.AddUIVertexTriangleStream(m_flatSavedVerts);

                    //curve Mesh stored in VertexHelper with CurvedUIVertexEffect
                    crvdVE.TesselationRequired = false;
                    crvdVE.CurvingRequired     = true;
                    crvdVE.ModifyMesh(m_vh);

                    //Fill the mesh we're going to upload to TMP object with already curved UIVertices
                    m_savedMesh.Clear();
                    m_vh.FillMesh(m_savedMesh);

                    //reset flags
                    curvingRequired = false;

                    //save current data
                    savedLocalScale = mySettings.transform.localScale;
                    savedUp         = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up);
                    savedPos        = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);

                    //prompt submeshes to update
                    foreach (CurvedUITMPSubmesh mesh in subMeshes)
                    {
                        mesh.UpdateSubmesh(false, true);
                    }
                }

                //upload mesh to TMP Object
                tmpText.canvasRenderer.SetMesh(m_savedMesh);
            }
        }