Esempio n. 1
0
    /// <summary>
    /// 绘制Mesh
    /// </summary>
    /// <param name="rect"></param>
    /// <param name="uvID">UVID</param>
    private static void DrawMesh(Rect rect, Vector4 offsetScale, GameObject gameObject, int uvID, bool lightMapLayoutMode, int lightMapIndex, int pass)
    {
        Mesh mesh = GetMesh(gameObject);

        if (!mesh)
        {
            return;
        }
        Renderer renderer = gameObject.GetComponent <Renderer>();

        if (!renderer)
        {
            return;
        }

        Matrix4x4 matrix = default(Matrix4x4);

        //计算并设置裁剪矩阵
        UVMaterial.SetMatrix("clipMatrix", GetGUIClipMatrix(rect));

        //UVMaterial.SetPass(pass);
        //matrix = GetDrawMatrix(rect, offsetScale);
        //Graphics.DrawMeshNow(mesh, matrix);

        //非光照贴图布局模式下直接计算绘制矩阵
        if (!lightMapLayoutMode)
        {
            matrix = GetDrawMatrix(rect, offsetScale);
        }
        UVMaterial.SetPass(pass);


        if (lightMapLayoutMode)
        {
            //光照贴图布局模式下需要根据每个Renderer的LightMapScaleOffset来计算绘制矩阵
            if (renderer.lightmapIndex != lightMapIndex)
            {
                return;
            }
            Vector4 lmST = renderer.lightmapScaleOffset;

            matrix =
                GetDrawMatrix(rect, offsetScale, lmST.z, lmST.w, lmST.x, lmST.y);
            if (CheckUV(mesh, 1))
            {
                UVMaterial.SetFloat("_UVIndex", 1.5f);
            }
            else
            {
                if (CheckUV(mesh, 0))
                {
                    UVMaterial.SetFloat("_UVIndex", 0.5f);
                }
                else
                {
                    return;
                }
            }
        }
        else
        {
            if (!CheckUV(mesh, uvID))
            {
                return;
            }
            UVMaterial.SetFloat("_UVIndex", 0.5f + uvID);
        }
        if (mesh)
        {
            Graphics.DrawMeshNow(mesh, matrix);
        }
    }
Esempio n. 2
0
 private static void DrawUVMesh(Rect rect, Vector4 offsetScale, GameObject gameObject, int uvID, bool lightMapLayoutMode, int lightMapIndex, Color color)
 {
     UVMaterial.SetColor("_Color", color);
     DrawMesh(rect, offsetScale, gameObject, uvID, lightMapLayoutMode, lightMapIndex, 0);
 }