两个以上gameobject同时调用同一函数时候transform代码中改变但是实际效果并不改变的诡异问题
点击按钮触发面板弹出动画:
void MainPanelBtnClick(string btnName) { switch (btnName) { case "0": if(currentBtn != MainPanelBtn.BETTLE) { _GUI_BG.active = false; currentBtn = MainPanelBtn.BETTLE; } break; case "1": if(currentBtn == MainPanelBtn.BETTLE) { _GUI_BG.active = true; } currentBtn = MainPanelBtn.HERO; if(!is2) { is2 = true; iTween.Stop(); if(ModelData.shareData.panelGroupDic.ContainsKey("ContentPanel")) { PanelFunc.PanelOn(ModelData.shareData.panelGroupDic["ContentPanel"]); } if(ModelData.shareData.panelGroupDic.ContainsKey("TitleBar")) { PanelFunc.PanelOn(ModelData.shareData.panelGroupDic["TitleBar"]); } if(ModelData.shareData.panelGroupDic.ContainsKey("ActNotify")) { PanelFunc.PanelOn(ModelData.shareData.panelGroupDic["ActNotify"]); } } else { is2 = false; iTween.Stop(); if(ModelData.shareData.panelGroupDic.ContainsKey("ContentPanel")) { PanelFunc.PanelOff(ModelData.shareData.panelGroupDic["ContentPanel"]); } if(ModelData.shareData.panelGroupDic.ContainsKey("TitleBar")) { PanelFunc.PanelOff(ModelData.shareData.panelGroupDic["TitleBar"],"OnMove2Complete",gameObject); } if(ModelData.shareData.panelGroupDic.ContainsKey("ActNotify")) { PanelFunc.PanelOff(ModelData.shareData.panelGroupDic["ActNotify"],"OnMove2Complete",gameObject); } } break; case "2": break; case "3": break; case "4": break; case "5": break; default: break; } }
先执行面板出现动画 3个面板同时出现
public static void PanelOn( PanelPos _panelPos) { _panelPos.g.getChild(0).transform.gameObject.SetActiveRecursively(true); if(_panelPos.middlePos!=_panelPos.oriPos) iTween.MoveTo(_panelPos.g, iTween.Hash( "position", _panelPos.middlePos, iT.MoveTo.islocal, true, "easetype", "easeOutBack", "loopType", "none", "delay", .1,"time",.5)); }
上面动画未结束就迅速执行面板隐藏函数
public static void PanelOff(PanelPos _panelPos) { _panelPos.g.transform.getChild(0).gameObject.SetActiveRecursively(false); _panelPos.g.transform.localPosition = _panelPos.oriPos; Debug.Log(_panelPos.g.name+" "+_panelPos.g.transform.localPosition); }
则有一个面板(绿色部分)的上面红色部分不执行,其实是执行了的
ContentPanel (0.0, -820.0, 0.0)
TitleBar (-660.0, 300.0, 0.0)
ActNotify (470.0, 300.0, 0.0)
程序中检测位置是移动了,但是实际视窗中并没移动
TitleBar (-300.0, 300.0, 0.0)
后来多次查找原因未果,后将
_panelPos.g.transform.getChild(0).gameObject.SetActiveRecursively(false);
改为
_panelPos.g.transform.gameObject.SetActiveRecursively(false);
则bug消除,不解!!!