c# - BaseVertexEffect 中的 ModifyVertices 移动到 BaseMeshEffect 中的位置

标签 c# unity-game-engine

我的代码遇到了问题,我正在采用现已弃用的 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/

相关文章:

c# - 使用 web api 文档时如何返回 NotFound 结果

c# - 如何编写 linq 查询来获取 mvc Web 应用程序中的 blogId

visual-studio - VS 2019找不到SDK

android - 将 Fabric with Multidex 与导出的 Unity 项目一起使用

c# - 缺少实现 `IPreprocessBuildWithReport` 的程序集引用?

unity-game-engine - 在unity3D中显示html

c# - 为什么(发件人为 "something")在 C# Windows Forms 应用程序中具有空值

C# 控制台应用程序构建但不启动应用程序

c# - 2D Portal 有时只能在 Unity 中工作

c# - 安装 log4net 多个项目