/// <summary> /// 给UiPnlModelBackground添加点击事件 /// </summary> /// <param name="ui"></param> private void AddClickEvent(BaseUi ui) { if (ui.model && ui.autoClickHide) { UiLayer layer = ui.layer; UiPnlModelBackground back = ui.modelBackground.GetComponent <UiPnlModelBackground>(); BoxCollider collider = UiUtility.AddIfMissing <BoxCollider>(back.spriteBack.gameObject); collider.isTrigger = true; UIEventListener.Get(back.spriteBack.gameObject).onClick = go => ui.Hide(); UiModelTool.ChangeTransformLayer(ui.modelBackground.gameObject, layer.ToString()); } }
/// <summary> /// 给Ui添加UiPnlModelBackground /// </summary> /// <param name="ui"></param> private void AddBackground(BaseUi ui) { if (ui.model && ui.modelBackground == null) { GameObject go = GameObjectUtility.CreateGameObject(UiPrefabNames.UiPnlModelBackground); go.SetActive(false); UiPnlModelBackground modelBackground = go.GetComponent <UiPnlModelBackground>(); UiUtility.SetParent(modelBackground.gameObject, ui.gameObject); modelBackground.transform.SetAsFirstSibling(); modelBackground.gameObject.SetActive(true); ui.modelBackground = modelBackground.GetComponent <UIPanel>(); } }