尝试进入playmode时,我的统一代码出现问题 它说
Assets/game/Scripts/Effects/Gradient.cs(14,26): error CS0115: `Gradient.ModifyVertices(System.Collections.Generic.List<UnityEngine.UIVertex>)' is marked as an override but no suitable method found to override
和Gradient.cs看起来像这样
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( List<UIVertex> vertexList )
{
if( !IsActive() )
{
return;
}
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;
}
}
}
&#13;
任何人都可以帮助我,我是团结的初学者,我一直在寻找一个多月的解决方案。 PS:我正在使用团结2017.3
答案 0 :(得分:0)
您的代码存在两个问题:
1 。错误的类派生
如果您使用重载<p class="text-center">You need to login or create an account to create a post</p>
<div class="row mt-4 d-flex justify-content-center">
<div class="col-12 col-md-6">
<div class="loginForm bg-white border">
<div class="text-center mt-4">
<a href="#login" data-toggle="tab" role="tab" class="btn btn-primary">Login</a>
<a href="#register" data-toggle="tab" role="tab" class="btn btn-outline-primary">Create Account</a>
</div>
<div class="tab-content registration_body bg-white mt-4" id="tabbb">
<div class="tab-pane fade show active clearfix" id="login" role="tabpanel" aria-labelledby="home-tab">
<form class="clearfix" method="POST" action="">
<div class="form-group col-12 px-0">
<label for="inputEmail4"
class="text-heading font-weight-semi-bold">Email</label>
<input type="email" class="form-control" value="" name="email" required autofocus placeholder="Email">
</div>
<div class="form-group col-12 px-0">
<label for="inputEmail4"
class="text-heading font-weight-semi-bold">Pass
</label>
<input type="password" class="form-control" name="password" required placeholder="Pass">
</div>
<button type="submit" class="btn btn-primary btn d-block w-100">Login</button>
</form>
</div>
<div class="tab-pane fade show clearfix" id="register" role="tabpanel" aria-labelledby="home-tab">
<form method="post" class="clearfix" method="POST" action="">
<div class="form-group col-12 px-0">
<label for="name"
class="text-heading font-weight-semi-bold">Name</label>
<input type="text" class="form-control" name="name" value="" required autofocus>
</div>
<div class="form-group col-12 px-0">
<label for="email"
class="text-heading font-weight-semi-bold">Email</label>
<input id="email" type="email" class="form-control" name="email" value="" required>
</div>
<div class="form-group col-12 px-0">
<label for="password"
class="text-heading font-weight-semi-bold">Pass</label>
<input id="password" type="password" class="form-control" name="password" required>
</div>
<div class="form-group col-12 px-0">
<label for="password-confirm"
class="text-heading font-weight-semi-bold">Confirm Pass</label>
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
<button type="submit" class="btn btn-primary btn d-block w-100">Create Account</button>
</form>
</div>
</div>
</div>
参数覆盖ModifyVertices
函数,则应该从BaseVertexEffect
而非 List<UIVertex> vertices
开始编写脚本。
此应有效:
BaseMeshEffect
但是赢了,因为您使用的是Unity 2017.3。它应该适用于较旧版本的Unity。有关详细信息和操作,请参阅#2 。
2 。已保留的脚本和功能
#1 的解决方案可行,但您使用的是Unity 2017.3。
public class Gradient : BaseVertexEffect
{
public override void ModifyVertices( List<UIVertex> vertexList )
{
....
}
}
已弃用很长时间,现在已在Unity 2017.3.0p3 中removed。您不能再使用BaseVertexEffect
脚本派生,也无法使用BaseVertexEffect
,因为它已被删除。添加了一个新的重载来替换它。
要派生的新类是void ModifyVertices(List<UIVertex> verts)
。要覆盖的函数是BaseMeshEffect
。虽然看起来已被void ModifyMesh(Mesh mesh)
替换,但如果您收到任何已弃用的错误,请移除void ModifyMesh(VertexHelper vh)
。
您的新代码应如下所示:
ModifyMesh(Mesh mesh)
答案 1 :(得分:-1)
类UI.BaseMeshEffect(https://docs.unity3d.com/ScriptReference/UI.BaseMeshEffect.html)没有可以覆盖的ModifyVertices函数。
覆盖仅适用于基类具有的功能,并且标记为可重写(虚拟或抽象)。在你的情况下,重写是没有意义的。您所能做的就是将函数添加到您的类中。