0
我有这块代码。我需要迭代每个子对象,但是子对象可以有更多的子对象。当程序第一次运行时调用Awake()
方法。所以,我在问如何构建一个迭代器来检查孩子内是否有孩子。然后对这些孩子运行ResizeMeshCollection(MeshFilter[] collection)
,直到不再有子对象。迭代通过多级子对象
public class ResizeAsset : MonoBehaviour {
void Awake()
{
ResizeMeshCollection(this.GetComponentsInChildren<MeshFilter>());
}
void ResizeMeshCollection(MeshFilter[] collection)
{
foreach (MeshFilter mf in collection)
{
mf.GetComponent<MeshFilter>();
Transform tf = mf.GetComponent<Transform>();
/// Resize logic here
/// check if there are children under this child object,
/// Run ResizeMeshCollection() on
/// all children until there are no more.
我敢肯定,我不想在自身运行ResizeMeshCollection(),我也不知道这是可能的,但我只是无法弄清楚如何做到这一点。
标签[tag:unity]的第一个标记是“不要在关于UNITY GAME ENGINE的问题上使用(使用:[tag:unity3d]来代替)” –
http://www.hacker-dictionary.com/条款/递归 –
那么,有没有这样做?我知道调用内部方法可能会产生一些不良影响 –