Beispiel #1
0
        /// <summary>
        /// Builds and link the texture used to color the body.
        /// </summary>
        private void SetupBodyColorTexture()
        {
            //Generate the body texture to color using the face actual size
            m_tBodyTexture = new Texture2D(
                Mathf.FloorToInt(m_oBody.sharedMesh.bounds.size.x * m_iPixelPerUnit),
                Mathf.FloorToInt(m_oBody.sharedMesh.bounds.size.z * m_iPixelPerUnit),
                TextureFormat.ARGB32,
                false);
            m_tBodyTexture.SetPixels(TextureUtilities.FillTextureWithColor(m_tBodyTexture, m_oBaseColor)); //initialiaze it to white
            m_tBodyTexture.Apply();

            //link the body texture as the material's main texture
            m_oSurfaceRenderer.material.SetTexture("_MainTex", m_tBodyTexture);
        }
Beispiel #2
0
        /// <summary>
        /// Builds and link the texture used to color the letter.
        /// </summary>
        private void SetupLetterColorTexture()
        {
            //Generate the texture to color using the letter actual size
            //- Format can be very low, we only need some base color not a full 32 bit but setPixel/Pixels works
            //  only on ARGB32, RGB24 and Alpha8 texture formats
            Vector3[] _meshVertices = m_oLetterMeshCollider.sharedMesh.vertices;
            m_tLetterDynamicTexture = new Texture2D(
                Mathf.FloorToInt(Mathf.Abs(_meshVertices[0].x - _meshVertices[3].x) * m_iPixelPerUnit),
                Mathf.FloorToInt(Mathf.Abs(_meshVertices[0].y - _meshVertices[1].y) * m_iPixelPerUnit),
                TextureFormat.ARGB32,
                false);
            m_tLetterDynamicTexture.SetPixels(TextureUtilities.FillTextureWithColor(m_tLetterDynamicTexture, m_oBaseColor)); //initialiaze it to white
            m_tLetterDynamicTexture.Apply();

            //link the dynamic texture to the TextMeshPro Text as the material's face texture
            m_oTextMeshObject.fontMaterial.SetTexture("_FaceTex", m_tLetterDynamicTexture);
        }