Merge remote-tracking branch 'origin/NewMaster' into AnHui_BaoShi
This commit is contained in:
commit
1f70feb68f
@ -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