Mesh map Radar (Ugui)

Source: Internet
Author: User
Tags cos radar

/********************************************************************************
Reference: http://www.cnblogs.com/jeason1997/p/5130413.html

* * Class Name: Radareditor


* * Description: Radar chart


* * Tanaka

*********************************************************************************/
Using Unityengine;
Using Unityeditor;
Using Unityengine.ui;


[Addcomponentmenu ("Ui/extensions/radareditor")]
public class Radareditor:maskablegraphic
{
public bool Isfill = true;
[Range (0, 0.99f)]
public float fillpercent = 0.8f;
[Range (0f, 1f)]
Public float[] values;
[Range (0f, 360f)]
public float angleoffset = 0;
public bool Usestateline = true;
Public Color linecolor = Color.White;
public float linewidth = 0.5f;
[Range (0f, 1f)]
public float linelength = 0.8f;
<summary>
Rewrite Onpopulatemesh
</summary>
<param name= "VH" ></param>
protected override void Onpopulatemesh (Vertexhelper vh)
{
Vector2 size = getcomponent<recttransform> (). rect.size/2f;
Vh. Clear ();
int partcount = values. Length;
for (int i = 0; i < Partcount; i++)
{
Vector2 pos1 = getpoint (Size, i) * values[i];
Vector2 Pos2 = Isfill? Vector2.zero: (POS1 * fillpercent);
Vector2 Pos4 = (i + 1 >= partcount)? (GetPoint (size, 0) * Values[0]): (GetPoint (size, i + 1) * values[i + 1]);
Vector2 pos3 = Isfill? Vector2.zero: (POS4 * fillpercent);
Vh. Adduivertexquad (Getquad (POS1, Pos2, POS3, Pos4));
if (usestateline)
{
if (i! = 0)
{
Vector2 Lineendpos = getpoint (Size, i) * linelength;
Vector2 linestartpos = Vector2.zero;
Vh. Adduivertexquad (GetLine (Linestartpos, Lineendpos));
}
if (i + 1 = = Partcount)
{
Vector2 Lineendpos = getpoint (size, 0) * LINELENGTH;
Vector2 linestartpos = Vector2.zero;
Vh. Adduivertexquad (GetLine (Linestartpos, Lineendpos));
}
}
}
}
<summary>
Draw Line
</summary>
<param name= "Start" ></param>
<param name= "End" ></param>
<returns></returns>
Private uivertex[] GetLine (Vector2 start, Vector2 end)
{
Uivertex[] vs = new uivertex[4];
vector2[] UV = new VECTOR2[4];
Uv[0] = new Vector2 (0, 0);
UV[1] = new Vector2 (0, 1);
UV[2] = new Vector2 (1, 0);
UV[3] = new Vector2 (1, 1);
Vector2 V1 = End-start;
Vector2 v2 = (V1.y = = 0f)? New Vector2 (0f, 1f): New Vector2 (1f,-V1.X/V1.Y);
V2. Normalize ();
V2 *= linewidth/2f;
Vector2[] pos = new VECTOR2[4];
Pos[0] = start + v2;
POS[1] = end + v2;
POS[2] = end-v2;
POS[3] = start-v2;
for (int i = 0; i < 4; i++)
{
Uivertex v = uivertex.simplevert;
V.color = LineColor;
V.position = Pos[i];
V.uv0 = Uv[i];
Vs[i] = v;
}
return vs;
}
<summary>
Get Point Vector2
</summary>
<param name= "Size" ></param>
<param name= "I" ></param>
<returns></returns>
Private Vector2 GetPoint (Vector2 size, int i)
{
int partcount = values. Length;
float angle = 360f/partcount * i + angleoffset;
float sin = mathf.sin (angle * mathf.deg2rad);
float cos = mathf.cos (angle * mathf.deg2rad);
return new Vector2 (size.x * cos, size.y * sin);
}


<summary>
Get Uivertex by point
</summary>
<param name= "Vertpos" ></param>
<returns></returns>
Private uivertex[] Getquad (params vector2[] vertpos)
{
Uivertex[] vs = new uivertex[4];
vector2[] UV = new VECTOR2[4];
Uv[0] = new Vector2 (0, 0);
UV[1] = new Vector2 (0, 1);
UV[2] = new Vector2 (1, 0);
UV[3] = new Vector2 (1, 1);
for (int i = 0; i < 4; i++)
{
Uivertex v = uivertex.simplevert;
V.color = color;
V.position = Vertpos[i];
V.uv0 = Uv[i];
Vs[i] = v;
}
return vs;
}
}

Mesh map Radar (Ugui)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.