C# 其中,BaseVertexEffect中的ModifyVertex在BaseMeshEffect中移动

C# 其中,BaseVertexEffect中的ModifyVertex在BaseMeshEffect中移动,c#,unity3d,C#,Unity3d,我现在采用的代码有问题,已弃用的BaseVertexEffect,老实说,我不知道哪里出错了: using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; [AddComponentMenu( "UI/Effects/Gradient" )] public class Gradient : BaseMesh

我现在采用的代码有问题,已弃用的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;
            }
        }
    }
使用UnityEngine;
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine.UI;
[AddComponentMenu(“UI/Effects/Gradient”)]
公共类梯度:BaseMesh效应
{
[序列化字段]
private Color32 topColor=Color.white;
[序列化字段]
private Color32 bottomColor=Color.black;
公共覆盖无效修改顶点(VertexHelper vh)
{
如果(!this.IsActive())
返回;
列表顶点列表=新列表();
vh.GetUIVertexStream(vertexList);
修改顶点(顶点列表);
vh.Clear();
vh.AddUIVertexTriangleStream(vertexList);
int count=vertexList.count;
float bottomY=顶点列表[0]。位置.y;
float topY=顶点列表[0]。位置.y;
对于(int i=1;itopY)
{
topY=y;
}
否则如果(y<底部)
{
y=y;
}
}
浮动UIElement高度=顶部-底部;
for(int i=0;i
和错误:

错误CS0115:'Gradient.ModifyVertices(UnityEngine.UI.VertexHelper)'标记为覆盖,但未找到合适的覆盖方法


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

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

这一问题的根源似乎是您打算使用的(确实有此方法,但在Unity3D 5.3.3中已删除),并被指示改为使用BaseMeshEffect

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

public覆盖void ModifyMesh(网格)
{
列表顶点列表=新列表();
使用(VertexHelper VertexHelper=新的VertexHelper(网格))
{
//移动之前需要保留在此处的VH相关代码
}
...
}

非常感谢您的帮助!:)@TomaszM请检查我对这篇文章的编辑,看看它是否符合你的问题(我已经使标题不那么笼统,并且与这个答案稍微一致)。如果标题与您的意图不符,请随时恢复并更新标题,使其更为友好(请确保不要因此而使答案无效)。
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
    }

    ...
}