public void RemovePopupAndParentCanvas(BaseSceneEaseInOut panel) { if (panel == null) { return; } panel.Dispose(); Canvas canvas = panel.transform.parent.GetComponent <Canvas>(); if (canvas != null) { GameObject.Destroy(canvas.gameObject); } }
//三个参数是否 点击空白消失,是否点击back键消失,是否阻塞住back键事件 public bool SetPopupPanelAutoClose(GameObject gameObj, bool blankAutoClose = true, bool backKeyAutoClose = true, bool blockBackKeyEvent = true) { if (gameObj == null) { return(false); } BaseSceneEaseInOut baseEIO = gameObj.GetComponent <BaseSceneEaseInOut>(); if (baseEIO != null) { baseEIO.clickBlankAutoClose = blankAutoClose; return(true); } else { return(false); } }
public GameObject AddPopupInNewCanvas(string prefabName) { //jony add //GameObject prefab = MySceneManager.instance.getPreloadedGameObject(prefabName); GameObject prefab = null; if (prefab == null) { prefab = (GameObject)Resources.Load(prefabName); if (prefab == null) { Lucky.LuckyUtils.Log("AddPopupInNewCanvas, Cannot find prefab!"); return(null); } } //add end Canvas canvas = null; GameObject popUp = null; //创建PopUp popUp = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; //CreateStoreCanvas:获取对应的canvas:如果有则直接取值,如果没有则会执行创建过程 canvas = CreatePopCanvas(prefab.name); //设置popUp位置:居中显示在屏幕上 popUp.transform.SetParent(canvas.transform, false); popUp.transform.localPosition = Vector3.zero; popUp.transform.localScale = Vector3.one; (popUp.transform as RectTransform).SetAsLastSibling(); BaseSceneEaseInOut baseEIO = popUp.GetComponent <BaseSceneEaseInOut>(); if (baseEIO != null) { baseEIO.clickBlankAutoClose = true; } return(popUp); }
//找到所有ID为StrId的弹窗,并将之销毁 public bool RemovePopup(string strId) { if (connectFailedDialogId == strId) { Lucky.LuckyUtils.Log("Try Remove connectFailedDialog,Failed!"); return(false); } //找到所有ID为StrId的弹窗,并将之销毁 List <GameObject> objs = new List <GameObject>(); //在uiLayerPopUps队列以及uiLayerPopUps里面GameObj的子弹窗里面找 for (int idx = 0; idx < uiLayerPopUps.Count; ++idx) { if (uiLayerPopUps[idx].strId == strId) { objs.Add(uiLayerPopUps[idx].gameObj); for (int idx2 = 0; idx2 < uiLayerPopUps[idx].childObjs.Count; ++idx2) { if (uiLayerPopUps[idx].childObjs[idx2].strId == strId) { objs.Add(uiLayerPopUps[idx].childObjs[idx2].gameObj); } } } } //在popLayerPopUps队列以及popLayerPopUps里面GameObj的子弹窗里面找 for (int idx = 0; idx < popLayerPopUps.Count; ++idx) { if (popLayerPopUps[idx].strId == strId) { objs.Add(popLayerPopUps[idx].gameObj); for (int idx2 = 0; idx2 < popLayerPopUps[idx].childObjs.Count; ++idx2) { if (popLayerPopUps[idx].childObjs[idx2].strId == strId) { objs.Add(popLayerPopUps[idx].childObjs[idx2].gameObj); } } } } if (objs.Count == 0) { return(false); } //销毁掉所有的这些弹窗 for (int idx = 0; idx < objs.Count; ++idx) { BaseSceneEaseInOut baseScene = objs[idx].GetComponent <BaseSceneEaseInOut>(); if (baseScene != null) { baseScene.Dispose(); } } return(true); }