Beispiel #1
0
        public void OpenSmallMessageBox(string strContent, bool isHaveCancelBtn, enUIEventID confirmID, enUIEventID cancelID, stUIEventParams par, int autoCloseTime = 0, enUIEventID closeTimeID = 0, string confirmStr = "", string cancelStr = "", bool isContentLeftAlign = false)
        {
            CUIFormScript script = Singleton <CUIManager> .GetInstance().OpenForm("UGUI/Form/Common/Form_SmallMessageBox.prefab", false, false);

            if (script != null)
            {
                GameObject gameObject = script.gameObject;
                if (gameObject != null)
                {
                    if (string.IsNullOrEmpty(confirmStr))
                    {
                        confirmStr = Singleton <CTextManager> .GetInstance().GetText("Common_Confirm");
                    }
                    if (string.IsNullOrEmpty(cancelStr))
                    {
                        cancelStr = Singleton <CTextManager> .GetInstance().GetText("Common_Cancel");
                    }
                    GameObject obj3 = gameObject.transform.Find("Panel/Panel/btnGroup/Button_Confirm").gameObject;
                    obj3.GetComponentInChildren <Text>().text = confirmStr;
                    GameObject obj4 = gameObject.transform.Find("Panel/Panel/btnGroup/Button_Cancel").gameObject;
                    obj4.GetComponentInChildren <Text>().text = cancelStr;
                    Text component = gameObject.transform.Find("Panel/Panel/Text").GetComponent <Text>();
                    component.text = strContent;
                    if (!isHaveCancelBtn)
                    {
                        obj4.CustomSetActive(false);
                    }
                    else
                    {
                        obj4.CustomSetActive(true);
                    }
                    CUIEventScript script2 = obj3.GetComponent <CUIEventScript>();
                    CUIEventScript script3 = obj4.GetComponent <CUIEventScript>();
                    script2.SetUIEvent(enUIEventType.Click, confirmID, par);
                    script3.SetUIEvent(enUIEventType.Click, cancelID, par);
                    if (isContentLeftAlign)
                    {
                        component.alignment = TextAnchor.MiddleLeft;
                    }
                    if (autoCloseTime != 0)
                    {
                        Transform transform = script.transform.Find("closeTimer");
                        if (transform != null)
                        {
                            CUITimerScript script4 = transform.GetComponent <CUITimerScript>();
                            if (script4 != null)
                            {
                                if (closeTimeID > enUIEventID.None)
                                {
                                    script4.m_eventIDs[1] = closeTimeID;
                                }
                                script4.SetTotalTime((float)autoCloseTime);
                                script4.StartTimer();
                            }
                        }
                    }
                    this.CloseSendMsgAlert();
                }
            }
        }
Beispiel #2
0
        public void OpenTips(string strContent, bool bReadDatabin = false, float timeDuration = 1.5f, GameObject referenceGameObject = null, params object[] replaceArr)
        {
            string text = strContent;

            if (bReadDatabin)
            {
                text = Singleton <CTextManager> .GetInstance().GetText(strContent);
            }
            if (!string.IsNullOrEmpty(text))
            {
                if (replaceArr != null)
                {
                    try
                    {
                        text = string.Format(text, replaceArr);
                    }
                    catch (FormatException exception)
                    {
                        object[] inParameters = new object[] { text, exception.Message };
                        DebugHelper.Assert(false, "Format Exception for string \"{0}\", Exception:{1}", inParameters);
                    }
                }
                CUIFormScript script = Singleton <CUIManager> .GetInstance().OpenForm("UGUI/Form/Common/Form_Tips.prefab", false, false);

                if (script != null)
                {
                    script.gameObject.transform.Find("Panel/Text").GetComponent <Text>().text = text;
                }
                if ((script != null) && (referenceGameObject != null))
                {
                    RectTransform component  = referenceGameObject.GetComponent <RectTransform>();
                    RectTransform transform2 = script.gameObject.transform.Find("Panel") as RectTransform;
                    if ((component != null) && (transform2 != null))
                    {
                        Vector3[] fourCornersArray = new Vector3[4];
                        component.GetWorldCorners(fourCornersArray);
                        float   num         = Math.Abs((float)(CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[2]).x - CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[0]).x));
                        float   num2        = Math.Abs((float)(CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[2]).y - CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[0]).y));
                        Vector2 screenPoint = new Vector2(CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[0]).x + (num / 2f), CUIUtility.WorldToScreenPoint(Singleton <CUIManager> .instance.FormCamera, fourCornersArray[0]).y + (num2 / 2f));
                        transform2.position = CUIUtility.ScreenToWorldPoint(null, screenPoint, transform2.position.z);
                    }
                }
                if (script != null)
                {
                    CUITimerScript script2 = script.gameObject.transform.Find("Timer").GetComponent <CUITimerScript>();
                    script2.EndTimer();
                    script2.m_totalTime = timeDuration;
                    script2.StartTimer();
                }
                Singleton <CSoundManager> .instance.PostEvent("UI_Click", null);
            }
        }