新增函数
This commit is contained in:
parent
a335f2f4bd
commit
1313b080c9
@ -423,4 +423,34 @@ public class Utility
|
|||||||
list[j] = temp;
|
list[j] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 该方法用于打乱当前脚本所挂载物体的子物体顺序
|
||||||
|
public void ShuffleChildObjects(Transform parent)
|
||||||
|
{
|
||||||
|
List<Transform> children = new List<Transform>();
|
||||||
|
|
||||||
|
for (int i = 0; i < parent.childCount; i++)
|
||||||
|
{
|
||||||
|
children.Add(parent.GetChild(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打乱子物体数组的顺序
|
||||||
|
for (int i = 0; i < children.Count; i++)
|
||||||
|
{
|
||||||
|
int randomIndex = UnityEngine.Random.Range(i, children.Count);
|
||||||
|
Transform temp = children[randomIndex];
|
||||||
|
children[randomIndex] = children[i];
|
||||||
|
children[i] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照打乱后的顺序重新设置子物体的顺序
|
||||||
|
for (int i = 0; i < children.Count; i++)
|
||||||
|
{
|
||||||
|
children[i].SetSiblingIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user