我需要为我使用Unity制作的分贝应用绘制图形。下面的解决方案可行,但并不像我的雇主所愿。我可以让这张图看起来更专业和准确吗?基本上我想要的行是相等的宽度,并防止线几乎看不见像在下面的图片:http://puu.sh/qjSvO/a51c11cef5.png如何在Unity中的Canvas上绘制2D图形
我想制作2D纹理和使用SetPixel,但我不知道这是否是正确的方式。
该图形作为可缩放UI的一部分在画布上绘制。
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