Upgrading to 5.2 my onFillVBO’s are no longer working.
I have a script based on the one posted here:
Within “protected override void OnFillVBO (List vbo){” I’m calculating positions and UV coords for vertices and then adding them to the list.
I’m still getting the polygons drawn to the screen, but they’re no longer in the correct position and have incorrect UV coords.
So is there a quick fix or do I need to change the entire thing to a mesh? If so, can someone point me in the right direction to replicate my current functionality? Everything I’ve tried has resulted in nothing being drawn to the screen.
Oh, and also from 5.1 to 5.2 my frame rate has dropped from 300fps to 75fps with only a few UI objects in the scene
Was working late last night finishing the 5.2 updates. The LineRenderer especially caused me some grief, the new vertex drawing way of doing things in 5.2 is very different. (but there are helpers)
Is there any chance you could help me out with this? I’m not sure why this isn’t filling. There seem to be the correct number of vertices being generated, but it’s not creating the mesh…
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
[ExecuteInEditMode]
public class UICircle2 : Graphic
{
[Range(0, 100)]
public int fillPercent;
public bool fill = true;
public int thikness = 5;
[Range(0, 360)]
public int segments = 360;
void Update()
{
this.thikness = (int)Mathf.Clamp(this.thikness, 0, rectTransform.rect.width / 2);
}
// protected override void OnFillVBO(List<UIVertex> vbo)
protected override void OnPopulateMesh(Mesh toFill)
{
float outer = -rectTransform.pivot.x * rectTransform.rect.width;
float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thikness;
// vbo.Clear();
toFill.Clear();
var vbo = new VertexHelper(toFill);
UIVertex vert = UIVertex.simpleVert;
Vector2 prevX = Vector2.zero;
Vector2 prevY = Vector2.zero;
float f = (this.fillPercent / 100f);
float degrees = 360f / segments;
int fa = (int)((segments + 1) * f);
for (int i = 0; i < fa; i++)
{
float rad = Mathf.Deg2Rad * (i * degrees);
float c = Mathf.Cos(rad);
float s = Mathf.Sin(rad);
float x = outer * c;
float y = inner * c;
vert.color = color;
vert.position = prevX;
vbo.AddVert(vert);
prevX = new Vector2(outer * c, outer * s);
vert.position = prevX;
vbo.AddVert(vert);
if (this.fill)
{
vert.position = Vector2.zero;
vbo.AddVert(vert);
vbo.AddVert(vert);
}
else
{
vert.position = new Vector2(inner * c, inner * s); ;
vbo.AddVert(vert);
vert.position = prevY;
vbo.AddVert(vert);
prevY = new Vector2(inner * c, inner * s);
}
}
vbo.FillMesh(toFill);
int verts = vbo.currentVertCount;
Debug.Log(verts);
}
}
I had the same issue updating the LineRenderer, had to use DrawQuad instead of AddVert. no idea why it failed but the mesh was reporting a valid number of vertices, possibly a winding order issue maybe?
Looks like you did the same thing.
Did a miss a version where OnFillVBO was deprecated? I’m sort of astounded that it was Obsoleted like this and that the doc page still has an example using OnFillVBO.
That was the issue I came up against. Once again, I just copied your code and it worked
@ddf OnFillVBO was depreciated in 5.2. Documentation still needs to catch up, but you can find examples at bitbucket linked to by Simon earlier in the thread.
@ddf it was deprecated for a fairly good reason, they moved from a custom vertices approach to using regular Unity 3D meshes, so the old functions (from 5.2 onwards) didn’t make sense any more.
So all the functions are now mesh based and all the vertext / color / uv information is now stored in separate arrays. kind of makes sense to unify it so there is less to manage / maintain going forward. Docs will take a while to update as @zge stated
I agree with @SimonDarksideJ , and this seems to be a great move so far, but I also think @ddf has a point in that an “in-between” version where both methods worked would have been nice and less abrupt, giving us some more leeway to adapt. I mean, we’re not totally unified yet anyway, as UIVertex still exists. So no, you didn’t miss a version, it just went straight to Obsolete. =)
Wait, for real…?! In the meantime, I adopted my Asset to be both 4.6-5.0 and 5.1+ compatible before submitting. I s*** you not, they actually managed to change the API before my Asset even got approved… sigh Guess I’ll have to take a look at this new API then… Thanks for the heads-up @wikmanyo .