Esempio n. 1
0
    /// <summary>
    /// Rebuild the draw call's material.
    /// </summary>

    Material RebuildMaterial()
    {
        // Destroy the old material
        DestroyDynamicMat();

        // Create a new material
        CreateMaterial();

        // llm 2018-8-25 灰度相关
        if (grey)
        {
            mDynamicMat.EnableKeyword("Use_Gray");
        }
        else
        {
            mDynamicMat.DisableKeyword("Use_Gray");
        }
        ////////////////////////////////////////////

        mDynamicMat.renderQueue = mRenderQueue;

        // Assign the main texture
        if (mTexture != null)
        {
            mDynamicMat.mainTexture = mTexture;
        }

        // Update the renderer
        if (mRenderer != null)
        {
            mRenderer.sharedMaterials = new Material[] { mDynamicMat }
        }
        ;
        return(mDynamicMat);
    }

    void DestroyDynamicMat()
    {
        if (mDynamicMat == null)
        {
            return;
        }

        NGUITools.DestroyImmediate(mDynamicMat);
        mMaterial   = null;
        mDynamicMat = null;
    }

    /// <summary>
    /// Update the renderer's materials.
    /// </summary>

    void UpdateMaterials()
    {
        if (panel == null)
        {
            return;
        }

        // If clipping should be used, we need to find a replacement shader
        if (mRebuildMat || mDynamicMat == null || mClipCount != panel.clipCount || mTextureClip != (panel.clipping == Clipping.TextureMask))
        {
            RebuildMaterial();
            mRebuildMat = false;
        }
        else if (mRenderer.sharedMaterial != mDynamicMat)
        {
#if UNITY_EDITOR
            Debug.LogError("Hmm... This point got hit!");
#endif
            mRenderer.sharedMaterials = new Material[] { mDynamicMat };
        }
    }

    void PrepareMeshData()
    {
        int vcount = 0, ucount = 0, ccount = 0;
        int i = 0, imax;

        for (i = 0, imax = widgets.Count; i < imax; ++i)
        {
            vcount += widgets [i].geometry.vertCount;
            ucount += widgets [i].geometry.uvs.size;
            ccount += widgets [i].geometry.cols.size;
        }
        verts.AllocateMoreByCount(vcount);
        uvs.AllocateMoreByCount(ucount);
        cols.AllocateMoreByCount(ccount);
        for (i = 0, imax = widgets.Count; i < imax; ++i)
        {
            widgets [i].WriteToBuffers(verts, uvs, cols, null, null);
        }
        widgets.Clear();
    }