Epigene.UI.UIChartPie.Create C# (CSharp) Метод

Create() публичный Метод

public Create ( ) : void
Результат void
		public void Create()
		{
			Vertices = new List<Vector3>();
			Colors = new List<Color32>();
			Triangles = new List<int>();

			float total = 0.0f;
			for (int i = 0; i < datas.Count; i++)
			{
				total += (float)datas[i]["value"];
			}

			float percent = 0.0f;
			for (int i = 0; i < datas.Count; i++)
			{
				Color32 color1 = datas[i].ContainsKey("color1") ? (Color32)datas[i]["color1"] : defaultColors[(i % (defaultColors.Length / 2)) * 2];
				Color32 color2 = datas[i].ContainsKey("color2") ? (Color32)datas[i]["color2"] : defaultColors[(i % (defaultColors.Length / 2)) * 2 + 1];

				float rad = percent * Mathf.PI * 2;
				Vector3 p1 = new Vector3(Mathf.Sin(rad) * factor, Mathf.Cos(rad) * factor, 0.0f);

				float val = (float)datas[i]["value"];

				percent += val / total;
				datas[i]["percent"] = val / total;;
				rad = percent * Mathf.PI * 2;
				Vector3 p2 = new Vector3(Mathf.Sin(rad) * factor, Mathf.Cos(rad) * factor, 0.0f);
				
				float angle = (val == total) ? 360.0f : Angle(p1, p2);
		
				while (angle > 5.0f)
				{
					Vector3 p = p1;
					
					p1 = Quaternion.Euler(0, 0, -5) * p1;

					AddTriangle(Vector3.zero, p, p1, color1, color2);
					
					angle = Angle(p1, p2);
				}
				if (angle <= 5.0f)
				{

					AddTriangle(Vector3.zero, p1, p2, color1, color2);
				}
			}

			if (showLabel)
				CreateLabels();

			if (scrollArea != null)
			{
				scrollArea.RefreshContent();
			}
			chartPie.SetAllDirty();
		}

Usage Example

        void Awake()
        {
            Debug.Log("PieExample Awake");
            ChartPie c = gameObject.GetComponent<ChartPie>();
            chart = c.UIChartPie;
            c.sortingOrder = 103;

            // set default values
            chart.AddValues(new float[] { 110, 100, 10, 200, 200, 700, 70 } );
            chart.SetColor(0, Color.white, Color.black);
            chart.SetColor(1, Color.red, Color.yellow);
            chart.SetColor(2, new Color32(0, 40, 0, 255), new Color32(0, 255, 0, 255));
            chart.Create();

            time = System.Environment.TickCount;
        }