示例#1
0
        public static void ShowModalConfirmDialog(
            string title, string instructions,
            string confirmText, string cancelText,
            object target,
            Action <object> onAccept, Action <object> onCancel)
        {
            GameObject dialog = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("ModalConfirmCancelDialog"));

            UnityUIUtil.FindTextAndSet(dialog, "Title", title);
            UnityUIUtil.FindTextAndSet(dialog, "InfoText", instructions);
            UnityUIUtil.FindTextAndSet(dialog, "OKText", confirmText);
            UnityUIUtil.FindTextAndSet(dialog, "CancelText", cancelText);

            Button cancelButton = UnityUIUtil.FindButtonAndAddClickHandler(dialog, "Cancel", () => {
                if (onCancel != null)
                {
                    onCancel(target);
                }
                context.RegisterNextFrameAction(() => {
                    GameObject.Destroy(dialog);
                });
            });

            Button okButton = UnityUIUtil.FindButtonAndAddClickHandler(dialog, "OK", () => {
                onAccept(target);
                context.RegisterNextFrameAction(() => {
                    GameObject.Destroy(dialog);
                });
            });

            okButton.Select();

            MainUICanvas.AddChild(dialog, false);
        }
示例#2
0
        public static void GetStringFromDialog(string title, string instructions, object target,
                                               Func <string, bool> ValidatorF, Action <string, object> onAccept, Action onCancel)
        {
            GameObject dialog = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("GetStringDialog"));

            UnityUIUtil.FindTextAndSet(dialog, "Title", title);
            UnityUIUtil.FindTextAndSet(dialog, "InfoText", instructions);

            Button cancelButton = UnityUIUtil.FindButtonAndAddClickHandler(dialog, "Cancel", () => {
                if (onCancel != null)
                {
                    onCancel();
                }
                context.RegisterNextFrameAction(() => {
                    GameObject.Destroy(dialog);
                });
            });

            var input = UnityUIUtil.FindInput(dialog, "TextEntry");

            Button okButton = UnityUIUtil.FindButtonAndAddClickHandler(dialog, "OK", () => {
                if (input.text.Length == 0)
                {
                    return;
                }
                if (ValidatorF != null && ValidatorF(input.text) == false)
                {
                    return;
                }

                onAccept(input.text, target);
                context.RegisterNextFrameAction(() => {
                    GameObject.Destroy(dialog);
                });
            });

            input.Select();

            MainUICanvas.AddChild(dialog, false);
        }
示例#3
0
        public static void ShowModalMessageDialog(
            string title, string message,
            string confirmText,
            object target,
            Action <object> onAccept)
        {
            GameObject dialog = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("ModalMessageDialog"));

            UnityUIUtil.FindTextAndSet(dialog, "Title", title);
            UnityUIUtil.FindTextAndSet(dialog, "InfoText", message);
            UnityUIUtil.FindTextAndSet(dialog, "OKText", confirmText);

            Button okButton = UnityUIUtil.FindButtonAndAddClickHandler(dialog, "OK", () => {
                onAccept?.Invoke(target);
                context.RegisterNextFrameAction(() => {
                    GameObject.Destroy(dialog);
                });
            });

            okButton.Select();
            MainUICanvas.AddChild(dialog, false);
        }