void ModifyMesh(CurvedUIVertexEffect crvdVE)
        {
#if UNITY_5_1
            crvdVE.ModifyMesh(vh.GetUIVertexStream);
#else
            crvdVE.ModifyMesh(vh);
#endif
        }
Пример #2
0
        public void UpdateSubmesh(bool tesselate, bool curve)
        {
            //find required components
            if (TMPsub == null)
            {
                TMPsub = gameObject.GetComponent <TMP_SubMeshUI>();
            }

            if (TMPsub == null)
            {
                return;
            }

            if (TMPtext == null)
            {
                TMPtext = GetComponentInParent <TextMeshProUGUI>();
            }

            if (crvdVE == null)
            {
                crvdVE = gameObject.AddComponentIfMissing <CurvedUIVertexEffect>();
            }


            //perform tesselatio and curving
            if (tesselate || straightMesh == null || vh == null || (!Application.isPlaying))
            {
                vh = new VertexHelper(TMPsub.mesh);

                //save straight mesh - it will be curved then every time the object moves on the canvas.
                straightMesh = new Mesh();
                vh.FillMesh(straightMesh);

                curve = true;
            }


            if (curve)
            {
                //Debug.Log("Submesh: Curve", this.gameObject);
                vh = new VertexHelper(straightMesh);
                crvdVE.ModifyMesh(vh);
                curvedMesh = new Mesh();
                vh.FillMesh(curvedMesh);
                crvdVE.CurvingRequired = true;
            }

            //upload mesh to TMP object's renderer
            TMPsub.canvasRenderer.SetMesh(curvedMesh);


            //cleanup for not needed submeshes.
            if (TMPtext != null && TMPtext.textInfo.materialCount < 2)
            {
                //Each submesh uses 1 additional material.
                //If materialCount is 1, this means Submesh is not needed. Bounce it to toggle cleanup.
                TMPsub.enabled = false;
                TMPsub.enabled = true;
            }
        }
Пример #3
0
        public void UpdateSubmesh(bool tesselate, bool curve)
        {
            if (TMPsub == null)
            {
                TMPsub = gameObject.GetComponent <TMP_SubMeshUI>();
            }

            if (TMPsub == null)
            {
                return;
            }

            if (crvdVE == null)
            {
                crvdVE = gameObject.AddComponentIfMissing <CurvedUIVertexEffect>();
            }


            if (tesselate || straightMesh == null || vh == null || (!Application.isPlaying))
            {
                //Debug.Log("Submesh: tesselate", this.gameObject);
                vh = new VertexHelper(TMPsub.mesh);

                //save straight mesh - it will be curved then every time the object moves on the canvas.
                straightMesh = new Mesh();
                vh.FillMesh(straightMesh);

                //we do it differently now
                //curve and save mesh
                //crvdVE.ModifyMesh(vh);
                //curvedMesh = new Mesh();
                //vh.FillMesh(curvedMesh);

                curve = true;
            }


            if (curve)
            {
                //Debug.Log("Submesh: Curve", this.gameObject);
                vh = new VertexHelper(straightMesh);
                crvdVE.ModifyMesh(vh);
                curvedMesh = new Mesh();
                vh.FillMesh(curvedMesh);
                crvdVE.CurvingRequired = true;
            }

            TMPsub.canvasRenderer.SetMesh(curvedMesh);
        }
Пример #4
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);
            }
        }
Пример #5
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();
            }
        }
Пример #6
0
        void LateUpdate()
        {
            //Edit Mesh on TextMeshPro component
            if (tmp != null)
            {
                //if (!Application.isPlaying)
                //    tesselationRequired = true;


                if (savedSize != (transform as RectTransform).rect.size)
                {
                    tesselationRequired = true;
                    //Debug.Log("size changed");
                }
                else if (savedCanvasSize != 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 || savedMesh == null || vh == null || (curvingRequired && !Application.isPlaying))
                {
                    //Modify the mesh
                    //Debug.Log("meshing TMP");
                    tmp.renderMode = TMPro.TextRenderFlags.Render;
                    tmp.ForceMeshUpdate();
                    vh = new VertexHelper(tmp.mesh);
                    crvdVE.TesselationRequired = true;
                    crvdVE.ModifyMesh(vh);

                    //upload mesh to TMP Object
                    savedMesh = new Mesh();
                    vh.FillMesh(savedMesh);
                    tmp.renderMode = TMPro.TextRenderFlags.DontRender;

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

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

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


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

                    if (Application.isPlaying)
                    {
                        crvdVE.ModifyMesh(vh);
                    }

                    //fill mesh to VertexHelper
                    vh.FillMesh(savedMesh);

                    //reset flags
                    curvingRequired = false;

                    //save current data
                    savedSize = (transform as RectTransform).rect.size;
                    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);
                    }
                }

                //tmp.canvasRenderer.SetMesh(savedMesh);
                tmp.canvasRenderer.SetMesh(savedMesh);
            }
            else
            {
                FindTMP();
            }
        }
Пример #7
0
 private void ModifyMesh(CurvedUIVertexEffect crvdVE)
 {
     crvdVE.ModifyMesh(this.vh);
 }