2015-09-20 08:49:52 +08:00
|
|
|
/// Credit koohddang
|
|
|
|
/// Sourced from - http://forum.unity3d.com/threads/onfillvbo-to-onpopulatemesh-help.353977/#post-2299311
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
{
|
|
|
|
[AddComponentMenu("UI/Extensions/Primitives/Diamond Graph")]
|
2016-05-25 07:56:18 +08:00
|
|
|
public class DiamondGraph : UIPrimitiveBase
|
2015-09-20 08:49:52 +08:00
|
|
|
{
|
2017-02-11 00:45:50 +08:00
|
|
|
[SerializeField]
|
|
|
|
private float m_a = 1;
|
|
|
|
[SerializeField]
|
|
|
|
private float m_b = 1;
|
|
|
|
[SerializeField]
|
|
|
|
private float m_c = 1;
|
|
|
|
[SerializeField]
|
|
|
|
private float m_d = 1;
|
|
|
|
|
|
|
|
|
|
|
|
public float A
|
|
|
|
{
|
|
|
|
get { return m_a; }
|
|
|
|
set { m_a = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public float B
|
|
|
|
{
|
|
|
|
get { return m_b; }
|
|
|
|
set { m_b = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public float C
|
|
|
|
{
|
|
|
|
get { return m_c; }
|
|
|
|
set { m_c = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public float D
|
|
|
|
{
|
|
|
|
get { return m_d; }
|
|
|
|
set { m_d = value; }
|
|
|
|
}
|
|
|
|
|
2015-09-20 08:49:52 +08:00
|
|
|
|
2015-10-11 19:05:53 +08:00
|
|
|
protected override void OnPopulateMesh(VertexHelper vh)
|
2015-09-20 08:49:52 +08:00
|
|
|
{
|
2015-10-11 19:05:53 +08:00
|
|
|
vh.Clear();
|
2015-09-20 08:49:52 +08:00
|
|
|
float wHalf = rectTransform.rect.width / 2;
|
|
|
|
//float hHalf = rectTransform.rect.height / 2;
|
2017-02-11 00:45:50 +08:00
|
|
|
m_a = Math.Min(1, Math.Max(0, m_a));
|
|
|
|
m_b = Math.Min(1, Math.Max(0, m_b));
|
|
|
|
m_c = Math.Min(1, Math.Max(0, m_c));
|
|
|
|
m_d = Math.Min(1, Math.Max(0, m_d));
|
2015-09-20 08:49:52 +08:00
|
|
|
|
|
|
|
Color32 color32 = color;
|
2017-02-11 00:45:50 +08:00
|
|
|
vh.AddVert(new Vector3(-wHalf * m_a, 0), color32, new Vector2(0f, 0f));
|
|
|
|
vh.AddVert(new Vector3(0, wHalf * m_b), color32, new Vector2(0f, 1f));
|
|
|
|
vh.AddVert(new Vector3(wHalf * m_c, 0), color32, new Vector2(1f, 1f));
|
|
|
|
vh.AddVert(new Vector3(0, -wHalf * m_d), color32, new Vector2(1f, 0f));
|
2015-09-20 08:49:52 +08:00
|
|
|
|
2015-10-11 19:05:53 +08:00
|
|
|
vh.AddTriangle(0, 1, 2);
|
|
|
|
vh.AddTriangle(2, 3, 0);
|
2015-09-20 08:49:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|