現在、私は次のことを行っていますが、それは遅い方法だと確信しています。基本的に、私はグリッドを調べて、a) 星が存在するかどうか、b) 星がある場合はどのようなタイプかを判断します。私がすべきだと思うことは、既知の値 (たとえば current_star_density * 0.25) を使用し、それを使用して一連の点をプロットすることです。私が不確かな部分は、その量をプロットするときに重複を防ぐ方法だと思います.
どんな助けでもありがたく受け取られます。これは、コードの関連部分です。
for (var z = 0; z < gridZ; z++)
{
for (var x= 0; x < gridX; x++)
{
star_chance = Random.value * 1000; // * 1000
if (star_chance <= current_star_density)
{
star_class = Random.value * 100;
if (star_class <=1) // add in the other star types etc
{
new_star = Instantiate(prefab_o, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("O:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=2)
{
new_star = Instantiate(prefab_b, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("B:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=5)
{
new_star = Instantiate(prefab_a, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("A:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=10)
{
new_star = Instantiate(prefab_f, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("F:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=20)
{
new_star = Instantiate(prefab_g, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("G:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=40)
{
new_star = Instantiate(prefab_k, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("K:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=80)
{
new_star = Instantiate(prefab_m, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("M:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
}
}
}