示例#1
0
        protected virtual void OpenPromptDialog()
        {
            if (!IsActive() || !IsInteractable())
            {
                return;
            }

            if (string.IsNullOrEmpty(m_CustomDialogPath))
            {
                OpenDefaultPromptDialog();
            }
            else
            {
                DialogManager.ShowCustomDialogAsync <DialogPrompt>(m_CustomDialogPath, (dialog) =>
                {
                    _dialogPrompt = dialog;
                    if (_dialogPrompt != null)
                    {
                        _dialogPrompt.destroyOnHide = true;
                        _dialogPrompt.Initialize(this,
                                                 (value) =>
                        {
                            if (this != null)
                            {
                                value          = string.IsNullOrEmpty(value) ? string.Empty : value;
                                var willChange = m_Text != value;

                                this.text = value;
                                if (willChange && onEndEdit != null)
                                {
                                    onEndEdit.Invoke(m_Text);
                                }
                                if (OnReturnPressed != null)
                                {
                                    OnReturnPressed.Invoke();
                                }
                            }
                        },
                                                 "OK",
                                                 this.hintText,
                                                 null,
                                                 null,
                                                 "Cancel");
                    }
                    else
                    {
                        OpenDefaultPromptDialog();
                    }
                });
            }
        }
        protected virtual void ShowFrameActivity <TFrame>(TFrame cachedFrame, string dialogPrefabPath, System.Action <TFrame, bool> initializeCallback) where TFrame : MaterialDialogFrame
        {
            if (IsDialogMode())
            {
                if (cachedFrame == null || !(cachedFrame.activity is MaterialDialogActivity))
                {
                    if (cachedFrame != null && cachedFrame.activity != null)
                    {
                        cachedFrame.activity.destroyOnHide = true;
                        cachedFrame.activity.Hide();
                    }

                    System.Action <TFrame> initDelegate = (dialog) =>
                    {
                        cachedFrame = dialog;
                        if (initializeCallback != null)
                        {
                            initializeCallback(dialog, true);
                        }
                    };
                    if (m_OpenDialogAsync)
                    {
                        DialogManager.ShowCustomDialogAsync <TFrame>(dialogPrefabPath, initDelegate);
                    }
                    else
                    {
                        DialogManager.ShowCustomDialog <TFrame>(dialogPrefabPath, initDelegate);
                    }
                }
                else
                {
                    if (initializeCallback != null)
                    {
                        initializeCallback(cachedFrame, true);
                    }
                    cachedFrame.Show();
                }
            }
            else
            {
                if (cachedFrame == null || !(cachedFrame.activity is MaterialSpinnerActivity))
                {
                    if (cachedFrame != null && cachedFrame.activity != null)
                    {
                        cachedFrame.activity.destroyOnHide = true;
                        cachedFrame.activity.Hide();
                    }

                    cachedFrame = PrefabManager.InstantiateGameObject(dialogPrefabPath, null).GetComponent <TFrame>();
                    CreateSpinnerActivity(cachedFrame);
                }

                if (cachedFrame != null)
                {
                    if (initializeCallback != null)
                    {
                        initializeCallback(cachedFrame, false);
                    }
                    var activity = (cachedFrame.activity as MaterialSpinnerActivity);
                    if (activity != null)
                    {
                        activity.RecalculatePosition(this);
                    }
                    cachedFrame.Show();
                }
            }
        }