using UnityEngine;
using UnityEngine.UI;
public class ArrowRenderer : Graphic
{
protected override void OnPopulateMesh(VertexHelper vh)
{
Vector2 corner1 = Vector2.zero;
Vector2 corner2 = Vector2.zero;
Vector2 leftBottom = Vector2.zero;
Vector2 rightBottom = Vector2.zero;
Vector2 top = Vector2.zero;
corner1.x = 0f;
corner1.y = 0f;
corner2.x = 1f;
corner2.y = 1f;
leftBottom.x = -0.2f;
leftBottom.y = 0f;
rightBottom.x = 1.2f;
rightBottom.y = 0f;
top.y = -0.3f;
top.x = 0.5f;
corner1.x -= rectTransform.pivot.x;
corner1.y -= rectTransform.pivot.y;
corner2.x -= rectTransform.pivot.x;
corner2.y -= rectTransform.pivot.y;
leftBottom.x -= rectTransform.pivot.x;
leftBottom.y -= rectTransform.pivot.y;
rightBottom.x -= rectTransform.pivot.x;
rightBottom.y -= rectTransform.pivot.y;
top.y -= rectTransform.pivot.y;
top.x -= rectTransform.pivot.x;
corner1.x *= rectTransform.rect.width;
corner1.y *= rectTransform.rect.height;
corner2.x *= rectTransform.rect.width;
corner2.y *= rectTransform.rect.height;
leftBottom.x *= rectTransform.rect.width;
leftBottom.y *= rectTransform.rect.height;
rightBottom.x *= rectTransform.rect.width;
rightBottom.y *= rectTransform.rect.height;
top.y *= rectTransform.rect.height;
top.x *= rectTransform.rect.width;
vh.Clear();
UIVertex vert = UIVertex.simpleVert;
vert.position = new Vector2(corner1.x, corner1.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(corner1.x, corner2.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(corner2.x, corner2.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(corner2.x, corner1.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(leftBottom.x, leftBottom.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(rightBottom.x, rightBottom.y);
vert.color = Color.black;
vh.AddVert(vert);
vert.position = new Vector2(top.x, top.y);
vert.color = Color.black;
vh.AddVert(vert);
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
vh.AddTriangle(4, 5, 6);
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme