Resolved FillVBO to PopulateMesh errors

Added ButtonHelp event to UIButton
Fixed issue #21, changed the base control for the LineRenderers from Graphic to MaskableGraphic

--HG--
branch : develop_5.2
pull/413/head
Simon (darkside) Jackson 2015-09-10 18:50:23 +01:00
parent 9630c2c5d1
commit c0f0786227
4 changed files with 76 additions and 23 deletions

View File

@ -253,8 +253,14 @@ namespace UnityEngine.UI.Extensions
/// Update the UI renderer mesh.
/// </summary>
protected override void OnFillVBO(List<UIVertex> vbo)
protected override void OnPopulateMesh(Mesh toFill)
{
List<UIVertex> vbo = new List<UIVertex>();
using (var helper = new VertexHelper(toFill))
{
helper.GetUIVertexStream(vbo);
}
switch (type)
{
case Type.Simple:
@ -270,6 +276,12 @@ namespace UnityEngine.UI.Extensions
GenerateFilledSprite(vbo, m_PreserveAspect);
break;
}
using (var helper = new VertexHelper())
{
helper.AddUIVertexTriangleStream(vbo);
helper.FillMesh(toFill);
}
}
#region Various fill functions

View File

@ -1,5 +1,6 @@
/// Credit AriathTheWise
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1796783
/// Extended to include a HELD state that continually fires while the button is held down.
using UnityEngine.Events;
using UnityEngine.EventSystems;
@ -18,10 +19,18 @@ namespace UnityEngine.UI.Extensions
#endregion
#region Events
[Tooltip("Event that fires when a button is clicked")]
public UIButtonEvent OnButtonClick;
[Tooltip("Event that fires when a button is initially pressed down")]
public UIButtonEvent OnButtonPress;
[Tooltip("Event that fires when a button is released")]
public UIButtonEvent OnButtonRelease;
[Tooltip("Event that continually fires while a button is held down")]
public UIButtonEvent OnButtonHeld;
#endregion
private bool _pressed;
private PointerEventData _heldEventData;
public override void OnPointerClick(PointerEventData eventData)
{
@ -42,6 +51,8 @@ namespace UnityEngine.UI.Extensions
{
OnButtonPress.Invoke(eventData.button);
}
_pressed = true;
_heldEventData = eventData;
}
@ -53,6 +64,20 @@ namespace UnityEngine.UI.Extensions
{
OnButtonRelease.Invoke(eventData.button);
}
}
_pressed = false;
_heldEventData = null;
}
void Update()
{
if (!_pressed)
return;
if (OnButtonHeld != null)
{
OnButtonHeld.Invoke(_heldEventData.button);
}
}
}
}

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/UILineRenderer")]
public class UILineRenderer : Graphic
public class UILineRenderer : MaskableGraphic
{
[SerializeField]
Texture m_Texture;
@ -65,7 +65,7 @@ namespace UnityEngine.UI.Extensions
}
}
protected override void OnFillVBO(List<UIVertex> vbo)
protected override void OnPopulateMesh(Mesh toFill)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
@ -107,7 +107,8 @@ namespace UnityEngine.UI.Extensions
offsetY += Margin.y / 2f;
}
vbo.Clear();
toFill.Clear();
var vbo = new VertexHelper(toFill);
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
@ -143,31 +144,38 @@ namespace UnityEngine.UI.Extensions
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
SetVbo(vbo, new[] { prevV1, prevV2, v1, v2 }, uvs);
vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
SetVbo(vbo, new[] { v1, v2, v3, v4 }, uvs);
vbo.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
prevV1 = v3;
prevV2 = v4;
}
if (vbo.currentVertCount > 3)
{
vbo.FillMesh(toFill);
}
}
protected void SetVbo(List<UIVertex> vbo, Vector2[] vertices, Vector2[] uvs)
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)
{
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo.Add(vert);
}
UIVertex[] vbo = new UIVertex[4];
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo[i] = vert;
}
return vbo;
}
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)

View File

@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/UILineTextureRenderer")]
public class UILineTextureRenderer : Graphic
public class UILineTextureRenderer : MaskableGraphic
{
[SerializeField]
Texture m_Texture;
@ -66,7 +66,7 @@ namespace UnityEngine.UI.Extensions
}
}
protected override void OnFillVBO(List<UIVertex> vbo)
protected override void OnPopulateMesh(Mesh toFill)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
@ -108,7 +108,8 @@ namespace UnityEngine.UI.Extensions
offsetY += Margin.y / 2f;
}
vbo.Clear();
toFill.Clear();
var vbo = new VertexHelper(toFill);
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
@ -144,31 +145,38 @@ namespace UnityEngine.UI.Extensions
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
SetVbo(vbo, new[] { prevV1, prevV2, v1, v2 }, uvs);
vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
SetVbo(vbo, new[] { v1, v2, v3, v4 }, uvs);
vbo.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
prevV1 = v3;
prevV2 = v4;
}
if (vbo.currentVertCount > 3)
{
vbo.FillMesh(toFill);
}
}
protected void SetVbo(List<UIVertex> vbo, Vector2[] vertices, Vector2[] uvs)
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)
{
UIVertex[] vbo = new UIVertex[4];
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo.Add(vert);
vbo[i] = vert;
}
return vbo;
}
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)