/// <summary>
 /// Shows the error dialog. It will invoke the callback with null args if errorDialog template not set.
 /// </summary>
 /// <param name="msg">Message.</param>
 public static void ShowErrorDialog(string msg, CancelButtonPressedDelegate cancelCallback = null)
 {
     IAPDialog.Show(_uiSettings.errorDialog, msg, null, cancelCallback);
 }
示例#2
0
        /// <summary>
        /// Show the specified template, msg, confirmCallback and cancelCallback.
        /// </summary>
        /// <param name="template">Template.</param>
        /// <param name="msg">Message.</param>
        /// <param name="confirmCallback">Confirm callback.</param>
        /// <param name="cancelCallback">Cancel callback.</param>
        public static void Show(GameObject template, string msg, ConfirmButtonPressedDelegate confirmCallback = null, CancelButtonPressedDelegate cancelCallback = null)
        {
            // Get the Canvas
            GameObject canvas = GameObject.Find("Canvas") as GameObject;

            if (canvas != null && template != null)
            {
                GameObject    obj             = Instantiate(template);
                RectTransform dialogTransform = obj.GetComponent <RectTransform>();
                RectTransform canvasTransform = canvas.GetComponent <RectTransform>();

                if (dialogTransform != null && canvasTransform != null)
                {
                    IAPDialog dialog = obj.AddComponent <IAPDialog>();
                    dialogTransform.SetParent(canvasTransform);
                    dialogTransform.offsetMin  = new Vector2(0, 0);
                    dialogTransform.offsetMax  = new Vector2(0, 0);
                    dialogTransform.localScale = new Vector3(1, 1, 1);

                    Text[] txts = obj.GetComponentsInChildren <Text>();
                    foreach (Text txt in txts)
                    {
                        if (txt.name == "message")
                        {
                            txt.text = msg;
                        }
                    }

                    if (confirmCallback != null)
                    {
                        dialog.OnConfirmButtonPressed += confirmCallback;
                    }

                    if (cancelCallback != null)
                    {
                        dialog.OnCancelButtonPressed += cancelCallback;
                    }
                }
            }
        }
 /// <summary>
 /// Shows the confirm dialog. It will invoke the callback directly if no confirmDialog template set.
 /// </summary>
 /// <param name="msg">Message.</param>
 public static void ShowConfirmDialog(string msg, ConfirmButtonPressedDelegate confirmCallback = null, CancelButtonPressedDelegate cancelCallback = null)
 {
     if (_uiSettings.confirmDialog == null)
     {
         confirmCallback.Invoke(null);
     }
     else
     {
         IAPDialog.Show(_uiSettings.confirmDialog, msg, confirmCallback, cancelCallback);
     }
 }