/// <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);
     }
 }
예제 #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;
                    }
                }
            }
        }