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. /// Update the UI renderer mesh.
/// </summary> /// </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) switch (type)
{ {
case Type.Simple: case Type.Simple:
@ -270,6 +276,12 @@ namespace UnityEngine.UI.Extensions
GenerateFilledSprite(vbo, m_PreserveAspect); GenerateFilledSprite(vbo, m_PreserveAspect);
break; break;
} }
using (var helper = new VertexHelper())
{
helper.AddUIVertexTriangleStream(vbo);
helper.FillMesh(toFill);
}
} }
#region Various fill functions #region Various fill functions

View File

@ -1,5 +1,6 @@
/// Credit AriathTheWise /// Credit AriathTheWise
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1796783 /// 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.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@ -18,11 +19,19 @@ namespace UnityEngine.UI.Extensions
#endregion #endregion
#region Events #region Events
[Tooltip("Event that fires when a button is clicked")]
public UIButtonEvent OnButtonClick; public UIButtonEvent OnButtonClick;
[Tooltip("Event that fires when a button is initially pressed down")]
public UIButtonEvent OnButtonPress; public UIButtonEvent OnButtonPress;
[Tooltip("Event that fires when a button is released")]
public UIButtonEvent OnButtonRelease; public UIButtonEvent OnButtonRelease;
[Tooltip("Event that continually fires while a button is held down")]
public UIButtonEvent OnButtonHeld;
#endregion #endregion
private bool _pressed;
private PointerEventData _heldEventData;
public override void OnPointerClick(PointerEventData eventData) public override void OnPointerClick(PointerEventData eventData)
{ {
base.OnSubmit(eventData); base.OnSubmit(eventData);
@ -42,6 +51,8 @@ namespace UnityEngine.UI.Extensions
{ {
OnButtonPress.Invoke(eventData.button); OnButtonPress.Invoke(eventData.button);
} }
_pressed = true;
_heldEventData = eventData;
} }
@ -53,6 +64,20 @@ namespace UnityEngine.UI.Extensions
{ {
OnButtonRelease.Invoke(eventData.button); 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 namespace UnityEngine.UI.Extensions
{ {
[AddComponentMenu("UI/Extensions/UILineRenderer")] [AddComponentMenu("UI/Extensions/UILineRenderer")]
public class UILineRenderer : Graphic public class UILineRenderer : MaskableGraphic
{ {
[SerializeField] [SerializeField]
Texture m_Texture; 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 // requires sets of quads
if (Points == null || Points.Length < 2) if (Points == null || Points.Length < 2)
@ -107,7 +107,8 @@ namespace UnityEngine.UI.Extensions
offsetY += Margin.y / 2f; offsetY += Margin.y / 2f;
} }
vbo.Clear(); toFill.Clear();
var vbo = new VertexHelper(toFill);
Vector2 prevV1 = Vector2.zero; Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero; Vector2 prevV2 = Vector2.zero;
@ -143,31 +144,38 @@ namespace UnityEngine.UI.Extensions
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter }; Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1) if (i > 1)
SetVbo(vbo, new[] { prevV1, prevV2, v1, v2 }, uvs); vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
if (i == 1) if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter }; uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1) else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight }; 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; prevV1 = v3;
prevV2 = v4; 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++) for (int i = 0; i < vertices.Length; i++)
{ {
var vert = UIVertex.simpleVert; var vert = UIVertex.simpleVert;
vert.color = color; vert.color = color;
vert.position = vertices[i]; vert.position = vertices[i];
vert.uv0 = uvs[i]; vert.uv0 = uvs[i];
vbo.Add(vert); vbo[i] = vert;
} }
return vbo;
} }
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)

View File

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