二维数组的使用举例:
List <List <int >> array1 = new List <List <int >>();
List <int> array2 = new List <int>();array2.Add(2);
array2.Add(3);
array2.Add(6);
array2.Add(6);
array2.Add(6);
List <int> array3 = new List <int>();
array3.Add(1);
array3.Add(4);
array3.Add(5);
array3.Add(12);
array3.Add(32);
array1.Add(数组2);
array1.Add(ARRAY3);List <string> array4 = array1 [0];
List <string> array5 = array1 [1];
相当于数组里套了一个数组(N维数组同理)。
泛型的基本用法:https://blog.csdn.net/weixin_42513339/article/details/83188987
画圆代码如下:
int Pos_Z = 0;
public int N; //半圆采样点个数
List<List<float>> RoundPoints1 = new List<List<float>>();
List<float> xPoints1 = new List<float>();
List<float> yPoints1 = new List<float>();
List<List<float>> RoundPoints2 = new List<List<float>>();
List<float> xPoints2 = new List<float>();
List<float> yPoints2 = new List<float>();
// Use this for initialization
void Start () {
for (int i = 0; i < N; i++)
{
float x1 = -1.3f + i * (2f / N);
float y1 = Mathf.Sqrt(1 - Mathf.Pow(x1 + 0.3f, 2));
xPoints1.Add(x1);
yPoints1.Add(y1);
}
for (int i = N; i < 2*N+1; i++)
{
float x1 = 0.7f - (i-N) * (2f / N);
float y1 = -Mathf.Sqrt(1 - Mathf.Pow(x1 + 0.3f, 2));
xPoints1.Add(x1);
yPoints1.Add(y1);
}
for (int i = 0; i < N; i++)
{
float x2 = 0 + i * (2f / N);
float y2 = Mathf.Sqrt(1 - Mathf.Pow(x2 - 1f, 2));
xPoints2.Add(x2);
yPoints2.Add(y2);
}
for (int i = N; i < 2*N+1; i++)
{
float x2 = 2 - (i-N) * (2f / N);
float y2 = -Mathf.Sqrt(1 - Mathf.Pow(x2 - 1f, 2));
xPoints2.Add(x2);
yPoints2.Add(y2);
}
RoundPoints1.Add(xPoints1);
RoundPoints1.Add(yPoints1);
RoundPoints2.Add(xPoints2);
RoundPoints2.Add(yPoints2);
}
// Update is called once per frame
void Update () {
for (int i = 0; i < xPoints1.Count-1; i++)
{
Debug.DrawLine(new Vector3(xPoints1[i], yPoints1[i], Pos_Z),
new Vector3(xPoints1[i + 1], yPoints1[i + 1], Pos_Z), Color.red);
}
for (int i = 0; i < xPoints2.Count-1; i++)
{
Debug.DrawLine(new Vector3(xPoints2[i], yPoints2[i], Pos_Z),
new Vector3(xPoints2[i + 1], yPoints2[i + 1], Pos_Z), Color.red);
}
}
上图是画两个圆的函数,如果画一个,那么删除一部分即可。
下图便是画出圆的形状,当然如果想要画的圆更加光滑,那么只需要增大采样点N的个数即可。
而且本人只是调试用的圆,所以直接用了Debug.DrawLine()
如果想在场景运行的时候显示,那么可以是用LineRender();
PS:两种上述画线函数具体用法请点击这里,泛型函数点击这里。
本人接下去可能会写一些关于两个圆融合的程序。(https://blog.csdn.net/weixin_42513339/article/details/83212575)