基本上试图缩短这个:
octree[nodeIndices[0]].nodes[nodeIndices[1]]
.nodes[nodeIndices[2]].nodes[nodeIndices[3]].nodes[nodeIndices[4]]
我认为这样的事情可行,但不确定如何:
octree[nodeIndices[0]].(Enumerable.Repeat(node[nodeIndices[i]], 4)
编辑:这里有更多代码
OctreeNode[] nodes = octree;
ushort subdivisions = 1;
while (true)
{
ushort nodeIndex = 0;
OctreeNode node = nodes[nodeIndex];
if (node == null)
{
node = new OctreeNode();
node.nodes = new OctreeNode[8];
nodes = node.nodes;
}
subdivisions++;
if (subdivisions > 4)
break;
}
// the actual octree variable is unchanged
答案 0 :(得分:4)
var result = octree[nodeIndices[0]];
for (int i = 1; i <= 4; i++)
result = result.node[nodeIndices[i]];
// do something with result;