我的代码遇到了问题,我正在采用现已弃用的 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;
}
}
}
和错误:
error CS0115: `Gradient.ModifyVertices(UnityEngine.UI.VertexHelper)' is marked as an override but no suitable method found to override
有人可以帮我解决这个问题吗?
最佳答案
通过在 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/