从现在开始不赞成使用的BaseVertexEffect我所采用的代码遇到了麻烦,老实说,我不知道我在哪里犯了错误:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.UI;

    [AddComponentMenu( "UI/Effects/Gradient" )]
    public class Gradient : BaseMeshEffect
    {
        [SerializeField]
        private Color32 topColor = Color.white;
        [SerializeField]
        private Color32 bottomColor = Color.black;

        public override void ModifyVertices(VertexHelper vh)
        {
            if(!this.IsActive())
                return;
            List<UIVertex> vertexList = new List<UIVertex> ();
            vh.GetUIVertexStream(vertexList);

            ModifyVertices (vertexList);

            vh.Clear ();
            vh.AddUIVertexTriangleStream(vertexList);

            int count = vertexList.Count;
            float bottomY = vertexList[0].position.y;
            float topY = vertexList[0].position.y;

            for( int i = 1; i < count; i++ )
            {
                float y = vertexList[i].position.y;
                if( y > topY )
                {
                    topY = y;
                }
                else if( y < bottomY )
                {
                    bottomY = y;
                }
            }

            float uiElementHeight = topY - bottomY;

            for( int i = 0; i < count; i++ )
            {
                UIVertex uiVertex = vertexList[i];
                uiVertex.color = Color32.Lerp( bottomColor, topColor, (                 uiVertex.position.y - bottomY ) / uiElementHeight );
                vertexList[i] = uiVertex;
            }
        }
    }


和错误:


  错误CS0115:将“ Gradient.ModifyVertices(UnityEngine.UI.VertexHelper)”标记为替代,但找不到合适的方法来替代


有人可以帮我解决这个问题吗?

最佳答案

通过在ModifyVertices上使用关键字override,您试图覆盖基类BaseMeshEffect上名为ModifyVertices的方法。由于没有名为ModifyVertices的方法可以覆盖,因此会发生此错误。

其根源似乎是您打算使用BaseVertexEffect(确实具有此方法,但是从Unity3D 5.3.3开始已删除),而被定向为使用BaseMeshEffect。

您需要通过重命名要匹配的方法来正确覆盖ModifyMesh,然后更新现有代码以从新输入Mesh中获取VertexHelper(您之前在ModifyVertices上传递):

public override void ModifyMesh (Mesh mesh)
{
    List<UIVertex> vertexList = new List<UIVertex>();
    using (VertexHelper vertexHelper = new VertexHelper(mesh))
    {
        // Move previous VH-related code that you need to keep here
    }

    ...
}

关于c# - 来自BaseVertexEffect的ModifyVertices在BaseMeshEffect中移动的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36851992/

10-15 06:44