1. 程式人生 > >彈出訊息提示框,彈出確認取消,彈出物品獲得提示框

彈出訊息提示框,彈出確認取消,彈出物品獲得提示框


一、 彈出提示框

Globals.MUIManager.CreatMessageLabel("支付失敗");

        public T GetUI<T>() where T : HotFix_Project.UI.UI_Logic
        {
            HotFix_Project.UI.UI_Logic logicPanel = null;

            if (existingUI.TryGetValue(typeof(T).ToString(), out logicPanel))
            {
                return (T)(logicPanel);
            }
            else
            {
                return (T)null;
            }
        }

      public void ShowMessageLabel(string label)
        {
            if (messageLabel_pfb == null)
                return;
            GameObject mlabel = GameObject.Instantiate(messageLabel_pfb) as GameObject;
            mlabel.transform.localPosition = messageLabel_pfb.transform.localPosition;
            mlabel.transform.parent = messageLabel_pfb.transform.parent;
            SetLabelText(GetbyPath("Label", mlabel), label);
            mlabel.GetComponent<UISprite>().width = GetbyPath("Label", mlabel).GetComponent<UILabel>().width + 100;
            mlabel.transform.localScale = Vector3.one;
            mlabel.SetActive(true);
            GameObject.Destroy(mlabel, 2.5f);

        }

  二、彈出確認取消框

第一個引數為   點選確認的委託    第二個引數為顯示的文字


 Globals.MUIManager.CreatMBSuerDo(delegate (GameObject obj)

                                {

                                    Application.Quit();

                                }, Language.Instance.GetWord(1001936));
   public void CreatMBSuerDo(UIEventListener.VoidDelegate secbtEvt, string messge, int skin = 0)
        {
            AddUI<UI_MessageBox>(delegate (UI_MessageBox page) { page.CreatMessageBoxSureDo(secbtEvt, messge, skin); });
        }
 public void AddUI<T>(GUICallback<T> callback = null) where T : HotFix_Project.UI.UI_Logic
        {

            T uiLogic = GetUI<T>();
            if (null == uiLogic)
            {
                if (typeof(T) != typeof(UI_Guidance))
                {
                    Rooter.RemoveHand();
                }


                string ui_name = typeof(T).ToString();
                ui_name = ui_name.Substring(ui_name.LastIndexOf('.') + 1);


                GameObject uiObj = ILRT.Instance.MResourceManager.CreatGameObjectAtWord(uiPfbPath + ui_name, Vector2.zero);
                if (uiObj == null)
                {
                    MDebug.LogError("didn't find " + ui_name + "'s perfab");
                    return;
                }
                uiObj.name = ui_name;
                Transform uiTrans = uiObj.transform;
                uiTrans.parent = uiRoot.transform;
                uiTrans.localScale = Vector3.one;
                uiTrans.localPosition = Vector3.zero;

                FindLabel(uiTrans);
                //uiLogic = uiObj.AddComponent<T>();

                uiLogic = System.Activator.CreateInstance<T>();


                uiLogic.Init(uiObj);

                existingUI[typeof(T).ToString()] = uiLogic;

            }
            else
            {
                if (uiLogic.AwaysExits)
                {
                    uiLogic.Hide(false);
                }
            }
            if (null != callback)
                callback(uiLogic);
        }

        public void ShowMessageBox(UIEventListener.VoidDelegate fbtEvt, string fbtLb, UIEventListener.VoidDelegate secbtEvt, string secbtLb, string messge)
        {
            UIGrid grid = BT_PFB.transform.parent.gameObject.GetComponent<UIGrid>();
            FR_MessageBox.GetComponent<TweenScale>().ResetToBeginning();
            FR_MessageBox.GetComponent<TweenScale>().enabled = true;

            Label.text = messge;
            if (buttonlist.Count > 0)
            {
                for (int i = 0; i < buttonlist.Count; i++)
                    GameObject.DestroyImmediate(buttonlist[i]);
            }

            SetBTPerfactStart();
            CreatBt(fbtLb, fbtEvt);
            CreatBt(secbtLb, secbtEvt);
            SetBtPerfectEnd();

            grid.cellWidth = 174f;

            grid.repositionNow = true;
            FR_MessageBox.SetActive(true);
            NoToggle();

        }
    void CreatBt(string label, UIEventListener.VoidDelegate btclick)
        {
            GameObject bt1 = GameObject.Instantiate(BT_PFB) as GameObject;
            buttonlist.Add(bt1);
            bt1.transform.parent = BT_PFB.transform.parent;
            bt1.transform.localPosition = Vector3.zero;
            bt1.transform.localScale = Vector3.one;
            var lb = bt1.transform.Find("Label").GetComponent<UILabel>();
            lb.text = label;
            if (lb.width > maxBtLableW)
                maxBtLableW = lb.width;
            UIEventListener.Get(bt1).onClick += delegate (GameObject go)
            {
                CloseMessagebox();
            };
            UIEventListener.Get(bt1).onClick += btclick;
            bt1.SetActive(true);
        }

三、彈出物品獲得提示框

  public void ShowDrops(Dictionary<int, int> items, UIEventListener.VoidDelegate onClose = null)
        {
            if (items.Count > 0)
            {
                Globals.MUIManager.AddUI<UI_Event>(
                    delegate (UI_Event page)
                    {
                        page.ShowItemsElsewhere(items, onClose);
                    });
            }
        }
        public void ShowItemsElsewhere(Dictionary<int, int> itemList, UIEventListener.VoidDelegate onClose = null)
        {
            transform.Find("Anchor_Center").GetComponent<TweenScale>().enabled = false;
            transform.Find("Anchor_Center").localScale = Vector3.one;
            transform.Find("MaskBlack").gameObject.SetActive(false);
            transform.Find("Anchor_Center/Desc").gameObject.SetActive(false);
            List<SPUI_Event.Item> items = new List<SPUI_Event.Item>();
            foreach (var propItem in itemList)
            {
                SPUI_Event.Item item = new SPUI_Event.Item();
                ItemConfig.ItemObject _item = Globals.MDataTableManager.GetConfig<ItemConfig>().GetConfigElementByID(propItem.Key);
                if (null != _item)
                {
                    item.id = propItem.Key;
                    item.name = _item.Name;
                    item.icon = _item.Icon;
                    item.count = propItem.Value;
                    items.Add(item);
                }
            }

            _spui.SetItems(items);
            if (onClose != null)
            {
                UIEventListener.Get(_spui.BT_ItemClose).onClick += onClose;
            }
            UIEventListener.Get(_spui.BT_ItemClose).onClick += CloseThisElsewhere;
        }