Unityで作成しているデシベルアプリのグラフを描画する必要があります。以下の解決策は機能しますが、私の雇用主が望むほど正確ではありません。このグラフをもっとプロフェッショナルかつ正確に見せることができますか?基本的には、次の図のように、線の幅を同じにして線がほとんど見えないようにします。http://puu.sh/qjSvO/a51c11cef5.pngUnityでキャンバスに2Dグラフを描画する方法
2次元テクスチャを作成して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