我没有删除其他陈述中的孩子的麻烦,但这一陈述很奇怪。
这是我在 NGUI 中删除孩子的代码
void DeleteChildrens(Transform t)
{
NGUITools.DestroyChildren(t);
}
现在我正在使用它。
[SerializeField] Transform[] pos_big_road = null;
[SerializeField] Transform[] pos_bead_road = null;
[SerializeField] Transform[] pos_big_eye_road = null;
private myFunction(bool success, ...){
if(g-number == 1){
DeleteChildrens(pos_big_road[0]); //--> THIS IS HOW I USE THE DeleteChildrens().
DeleteChildrens(pos_bead_road[0]);
//first statement met successfully
foreach(string previousValue in newChars){
GameObject bigroad = Instantiate(prefab_big_road[0]) as GameObject;
bigroad.transform.SetParent(pos_big_road[0]);
bigroad.transform.localScale = Vector3.one
}
//second statement met successfully
foreach(string previousValue2 in newChars){
GameObject beadroad = Instantiate(prefab_bead_road[0]) as GameObject;
beadroad.transform.SetParent(pos_bead_road[0]);
beadroad.transform.localScale = Vector3.one;
}
}
}
这两个foreach()
语句工作正常,可以顺利删除子项。
顺便说一句,我在这里尝试做的就像refresh
功能一样。
现在这里是我的混乱部分DeleteChildrens()
表现得不像我期望的那样。
[SerializeField] Transform[] pos_big_road = null;
[SerializeField] Transform[] pos_bead_road = null;
[SerializeField] Transform[] pos_big_eye_road = null;
private myFunction(bool success, ...){
if(g-number == 1){
DeleteChildrens(pos_big_road[0]); //--> THIS IS HOW I USE THE DeleteChildrens().
DeleteChildrens(pos_bead_road[0]);
//first statement met successfully
foreach(string previousValue in newChars){
GameObject bigroad = Instantiate(prefab_big_road[0]) as GameObject;
bigroad.transform.SetParent(pos_big_road[0]);
bigroad.transform.localScale = Vector3.one
}
//second statement met successfully
foreach(string previousValue2 in newChars){
GameObject beadroad = Instantiate(prefab_bead_road[0]) as GameObject;
beadroad.transform.SetParent(pos_bead_road[0]);
beadroad.transform.localScale = Vector3.one;
}
}
//The messed up part
for (int col = 0; col < table.GetLength(0); col++)
{
for (int row = 0; row < table.GetLength(1); row++)
{
//more codes here
}
}
if (redBead)
{
if (isWholeColumnNull)
{
NGUITools.SetActive(p, false);
}
else
{
p = Instantiate(prefab_big_eye_road[0]) as GameObject;
p.transform.SetParent(pos_big_eye_road[0]);
p.transform.localScale = Vector3.one;
p.GetComponent<UISprite>().spriteName = "symble_banker_bigroad-bigeyeroad";
NGUITools.SetActive(p, true);
}
}
if (blueBead)
{
if (isWholeColumnNull)
{
NGUITools.SetActive(p, false);
}
else
{
p = Instantiate(prefab_big_eye_road[0]) as GameObject;
p.transform.SetParent(pos_big_eye_road[0]);
p.transform.localScale = Vector3.one;
p.GetComponent<UISprite>().spriteName = "symble_player_bigroad-bigeyeroad";
NGUITools.SetActive(p, true);
}
}
}
当我尝试将此代码与其他
一起放在上面时DeleteChildrens(pos_big_road[0]);
DeleteChildrens(pos_bead_road[0]);
DeleteChildrens(pos_big_eye_road[0]);
此
DeleteChildrens(pos_big_eye_road[0]);
只是删除子项并且永远不再实例化与其他2语句不同。可能是什么问题呢?有人可以指出我:)