Мне нужно нарисовать график для моего приложения decibel, которое я делаю с Unity. Решение ниже работает, но не так точно, как хотелось бы моему работодателю. Могу ли я сделать этот график более профессиональным и точным? В принципе, я хочу, чтобы линии были одинаковой ширины и чтобы линия не была почти невидимой, как на следующем рисунке: http://puu.sh/qjSvO/a51c11cef5.pngКак нарисовать 2D-граф на холсте в Unity 5
Я думал о создании 2D-текстуры и использовании SetPixel, но я не уверен, Правильный способ.
График рисуется на холсте как часть масштабируемого пользовательского интерфейса.
public class Graph : MonoBehaviour {
public float graphWidth;
public float graphHeight;
LineRenderer newLineRenderer;
List<int> decibels;
int vertexAmount = 50;
float xInterval;
GameObject parentCanvas;
// Use this for initialization
void Start()
{
parentCanvas = GameObject.Find("Canvas");
graphWidth = transform.Find("Linerenderer").GetComponent<RectTransform>().rect.width;
graphHeight = transform.Find("Linerenderer").GetComponent<RectTransform>().rect.height;
newLineRenderer = GetComponentInChildren<LineRenderer>();
newLineRenderer.SetVertexCount(vertexAmount);
xInterval = graphWidth/vertexAmount;
}
//Display 1 minute of data or as much as there is.
public void Draw(List<int> decibels)
{
if (decibels.Count == 0)
return;
float x = 0;
for (int i = 0; i < vertexAmount && i < decibels.Count; i++)
{
int _index = decibels.Count - i - 1;
float y = decibels[_index] * (graphHeight/130); //(Divide grapheight with the maximum value of decibels.
x = i * xInterval;
newLineRenderer.SetPosition(i, new Vector3(x - graphWidth/2 , y - graphHeight/2 , 0));
}
}
}
Похоже, что вы случайно установили «widthCurve» или «colorGradiant» - возможно, в инспекторе, а не в вашем коде. – ArtOfWarfare