using UnityEngine;

using System.Collections;

using Vectrosity;

public class StudyVectrosity : MonoBehaviour

{

//线条材质

public Material myMaterial;

private VectorLine energyLine;

private Vector2[] energyLinePoints;

private int index = 0;

// Use this for initialization

void Start()

{

//X轴水平线,Y轴水平线

CreteLine( new Vector2(100, Screen.height * 0.1f), new Vector2(100, Screen.height * 0.3f) );

CreteLine( new Vector2(100, Screen.height * 0.1f), new Vector2(1200, Screen.height * 0.1f) );

energyLinePoints = new Vector2[350];

energyLine = new VectorLine("Energy", energyLinePoints, myMaterial,3.0f, LineType.Continuous, Joins.Weld);

//矩形图表

CreateRect(100, 500, 50, 200, Color.green);

CreateRect(150, 700, 50, 400, Color.green);

CreateRect(200, 550, 50, 250, Color.green);

CreateRect(250, 600, 50, 300, Color.green);

CreateRect(300, 500, 50, 200, Color.green);

//绘制圆形

VectorLine circleLine = new VectorLine("Circle", new Vector2[100], myMaterial, 3.0f, LineType.Discrete, Joins.Weld);

circleLine.MakeCircle(new Vector2(600, 450), 100);

circleLine.SetColor(Color.green);

circleLine.Draw();

}

// Update is called once per frame

void Update()

{

}

void LateUpdate()

{

if (index < energyLinePoints.Length)

{

//给数组赋值

energyLinePoints[index].x = index * 3 + 100;

energyLinePoints[index].y = Mathf.Sin(index * 0.1f) * 60 + Screen.height * 0.1f;

//限制min max ,去除与之连接的那条线的

energyLine.minDrawIndex = index - 1;

energyLine.maxDrawIndex = index;

//绘制

energyLine.Draw();

//这句是逗比代码,别在意

//CreteLine(new Vector2(index * 3 + 100, Screen.height * 0.1f), new Vector2(energyLinePoints[index].x, energyLinePoints[index].y));

index++;

}

}

/// <summary>

/// 绘制线段

/// </summary>

/// <param name="startVector"></param>

/// <param name="endVector"></param>

private void CreteLine(Vector2 startVector,Vector2 endVector)

{

Vector2[] linePoints = { startVector, endVector };

VectorLine line = new VectorLine("Line", linePoints, myMaterial, 3.0f, LineType.Continuous, Joins.Weld);

line.Draw();

}

/// <summary>

/// 绘制矩形

/// </summary>

/// <param name="posX"></param>

/// <param name="posY"></param>

/// <param name="width"></param>

/// <param name="height"></param>

/// <param name="color"></param>

private void CreateRect(float posX, float posY, float width, float height, Color color)

{

VectorLine squareLine = new VectorLine("Square", new Vector2[8], myMaterial, 3.0f, LineType.Discrete, Joins.Weld);

squareLine.MakeRect(new Rect(posX, posY, width, height));

squareLine.SetColor(color);

squareLine.Draw();

}

}