예제 #1
0
        private void LoseOperation()
        {
#if FULLLOG
            MoreDebug.Log("qaa go: " + gameObject.name);
#endif

            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            if (InfoPriority > CampaignManager.campaign.OperationTerseness)
            {
                MessageBoxParams parms = new MessageBoxParams();
                parms.Message               = FailureInfo;
                parms.MessageBoxTitle       = oname;
                parms.Button1Action         = PauseGame.only.queueResume;
                parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
                EasyMessageBox.Show(parms);
                PauseGame.only.queuePause();
            }
            OnLoseOperation.Invoke();
            level.LoseAnOperation();
            // Remember winning the operation does not win the level or (necessarily) end the operation
            if (ForceLevelLose)
            {
                EndOperation();
                level.LoseLevel();
            }
        }
예제 #2
0
        private void StartCampaign()
        {
            // Called when enabled
            // todo: can we just put this in OnEnable() ?
#if FULLLOG
            MoreDebug.Log("go: " + gameObject.name);
#endif
            // announce the start of the campaign
            PauseGame.only.beginPlay();
            OnBeginCampaign.Invoke();
            // show the campaign start screen

            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            MessageBoxParams parms = new MessageBoxParams();
            parms.Message               = StartingInfo;
            parms.MessageBoxTitle       = CampaignName;
            parms.Button1Action         = PauseGame.only.queueResume;
            parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
            EasyMessageBox.Show(parms);
            PauseGame.only.queuePause();

            // load the first level
            currentLevel = 0;
            LoadLevel(currentLevel);
        }
예제 #3
0
        private IEnumerator ShowOperationStatus()
        {
#if FULLLOG
            MoreDebug.Log(".");
#endif

            yield return(new WaitForSeconds(2));

            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            string sceneresult = "There are " + Missions.Length + "(" + missioncount.MaximumCount + ") missions " + newline +
                                 "Actual wins: " + missioncount.GroupCount[1] + newline +
                                 "Actual losses: " + missioncount.GroupCount[0];
            MessageBoxParams parms = new MessageBoxParams();
            parms.Message               = sceneresult;
            parms.MessageBoxTitle       = "Operation is Ended";
            parms.Button1Action         = PauseGame.only.queueResume;
            parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
            EasyMessageBox.Show(parms);
            PauseGame.only.queuePause();
        }
예제 #4
0
        void SucceedMission()
        {
#if FULLLOG
            MoreDebug.Log("go: " + gameObject.name);
#endif
            if (!isActive)
            {
                return;
            }
#if FULLLOG
            MoreDebug.Log("real.");
#endif
            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            if (InfoPriority > operation.MissionTerseness)
            {
                MessageBoxParams parms = new MessageBoxParams();
                parms.Message               = SuccessInfo;
                parms.MessageBoxTitle       = MissionTitle;
                parms.Button1Action         = PauseGame.only.queueResume;
                parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
                EasyMessageBox.Show(parms);
                PauseGame.only.queuePause();
            }
            currentState = GoalManager.GoalState.realwin;
            SuccessEvent.Invoke();
            operation.WinMission();
            isActive = false;
            //Reset ();
        }
예제 #5
0
        public void BeginMission()
        {
            // must be called after pausegame.beginplay()
#if FULLLOG
            MoreDebug.Log("go: " + gameObject.name);
#endif

            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            if (InfoPriority >= operation.MissionTerseness)
            {
                MessageBoxParams parms = new MessageBoxParams();
                parms.Message               = StartingInfo;
                parms.MessageBoxTitle       = MissionTitle;
                parms.Button1Action         = PauseGame.only.queueResume;
                parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
                EasyMessageBox.Show(parms);
                PauseGame.only.queuePause();
            }

            // reset the goal state
            currentState = initialState;
            isActive     = true;
            CurrentLevel = Registry.only.GetObject <LevelManager> ().MapOverlayName;
            operation.StartMission();
            // set flags
            BeginEvent.Invoke();
        }
예제 #6
0
        public void quit()
        {
            // quit the game after confirming
            hideall();
            MessageBoxParams param = new MessageBoxParams();

            param.Message       = "Do you really want to stop the game now?";
            param.Button1Text   = "Yes";
            param.Button1Action = QuitClean.QuitGame;
            param.Button2Text   = "No";
            param.Button2Action = showmain;
            EasyMessageBox.Show(param);
        }
예제 #7
0
        public void quitlevel()
        {
            // quit the level after confirming
            hideall();
            MessageBoxParams param = new MessageBoxParams();

            param.Message       = "Do you really want to end this level?";
            param.Button1Text   = "Yes";
            param.Button1Action = QuitClean.only.FailScene;
            param.Button2Text   = "No";
            param.Button2Action = showpause;
            EasyMessageBox.Show(param);
        }
예제 #8
0
        public void OnButton_LevelComplete()
        {
            MessageBoxParams param = new MessageBoxParams()
            {
                TemplateId    = 1,
                MessageLayout = MessageLayout.Vertical,
                MessageTitle  = "Level Complete!",
                MessageIcon   = dashboardIcon,
                Button1Text   = "Restart",
                Button1Icon   = restartIcon,
                Button2Text   = "Home",
                Button2Icon   = homeIcon,
                Button3Text   = "Share",
                Button3Icon   = shareIcon,
                InAnimation   = InAnimationTypes.VerticalExpand,
                OutAnimation  = OutAnimationTypes.Shrink
            };

            EasyMessageBox.Show(param);
        }
예제 #9
0
        // Local methods

        public override void show()
        {
            MessageBoxParams boxDef = new MessageBoxParams();

            boxDef.MessageBoxTitle = Title;
            boxDef.MessageTitle    = Header;
            boxDef.Message         = Message;
            boxDef.TemplateId      = TemplateID;
            if (ClickAction != null)
            {
                boxDef.Button1Action = ClickAction;
            }
            else
            {
                string actionname   = onClick.GetPersistentMethodName(0);
                object actionobject = onClick.GetPersistentTarget(0);
                boxDef.Button1Action = (UnityAction)Delegate.CreateDelegate(typeof(UnityAction), actionobject, actionname);
            }

            EasyMessageBox.Show(boxDef);
        }
예제 #10
0
        private void LoseCampaign()
        {
#if FULLLOG
            MoreDebug.Log("go: " + gameObject.name);
#endif

            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            MessageBoxParams parms = new MessageBoxParams();
            parms.Message               = FailureInfo;
            parms.MessageBoxTitle       = CampaignName;
            parms.Button1Action         = PauseGame.only.queueResume;
            parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
            EasyMessageBox.Show(parms);
            PauseGame.only.queuePause();
            OnLoseCampaign.Invoke();
            CampaignManager.EndCampaign();
        }
예제 #11
0
    void ActualShowDialogBox(MessageBoxParams param)
    {
        bool hasAvailableBox = false;

        for (int i = 0; i < boxPool[param.TemplateId].Count; i++)
        {
            if (!boxPool[param.TemplateId][i].gameObject.activeSelf)
            {
                hasAvailableBox = true;
                (boxPool[param.TemplateId][i].transform as RectTransform).anchoredPosition = Vector2.zero;
                (boxPool[param.TemplateId][i].transform as RectTransform).sizeDelta        = Vector2.zero;
                boxPool[param.TemplateId][i].gameObject.SetActive(true);
                boxPool[param.TemplateId][i].gameObject.GetComponent <BoxController>().Initiate(param);
                //activeBoxes.Add(boxPool[param.TemplateId][i].gameObject.GetComponent<BoxController>());
                break;
            }
        }
        if (!hasAvailableBox)
        {
            //Instantiate new box based on template.
            var box = Instantiate(Templates[param.TemplateId]);
            box.transform.SetParent(transform);
            (box.transform as RectTransform).anchoredPosition = Vector2.zero;
            (box.transform as RectTransform).sizeDelta        = Vector2.zero;
            var controller = box.GetComponent <BoxController>();
            boxPool[param.TemplateId].Add(controller);
            //activeBoxes.Add(controller);
            controller.Background.color = Color.clear;
            controller.Initiate(param);
        }

        if (param.MultipleCallBehaviour == MultipleCallBehaviours.Queue)
        {
            hasQueuedBox = true;
        }
    }
예제 #12
0
        /// <summary>
        /// Initiate the message box with a param set.
        /// </summary>
        /// <param name="param">The param set used to initiate.</param>
        public void Initiate(MessageBoxParams param)
        {
            this.currentParam   = param;
            currentOutAnimation = param.OutAnimation;

            //reset transform
            messageBox.anchoredPosition     = Vector2.zero;
            messageBox.localRotation        = Quaternion.identity;
            messageBox.localScale           = Vector3.one;
            transform.localScale            = initialScaleSelf;
            Background.transform.localScale = initialScaleBackground;

            //layout
            if (param.MessageLayout == MessageLayout.Horizontal)
            {
                horizontalGroup.gameObject.SetActive(true);
                verticalGroup.gameObject.SetActive(false);
            }
            else if (param.MessageLayout == MessageLayout.Vertical)
            {
                horizontalGroup.gameObject.SetActive(false);
                verticalGroup.gameObject.SetActive(true);
            }
            //background
            Background.color = Color.clear;
            lerpState        = true;
            lerpValue        = 0f;

            //message
            if (string.IsNullOrEmpty(param.Message))
            {
                messageTextHorizontal.gameObject.SetActive(false);
                messageTextVertical.gameObject.SetActive(false);
            }
            else
            {
                messageTextHorizontal.gameObject.SetActive(true);
                messageTextVertical.gameObject.SetActive(true);
                messageTextHorizontal.text = param.Message;
                messageTextVertical.text   = param.Message;
            }
            //message title
            if (string.IsNullOrEmpty(param.MessageTitle))
            {
                messageTitleHorizontal.gameObject.SetActive(false);
                messageTitleVertical.gameObject.SetActive(false);
            }
            else
            {
                messageTitleHorizontal.gameObject.SetActive(true);
                messageTitleVertical.gameObject.SetActive(true);
                messageTitleHorizontal.text = param.MessageTitle;
                messageTitleVertical.text   = param.MessageTitle;
            }
            //message box title
            if (string.IsNullOrEmpty(param.MessageBoxTitle))
            {
                titleBar.gameObject.SetActive(false);
            }
            else
            {
                titleBar.gameObject.SetActive(true);
                messageBoxTitle.text = param.MessageBoxTitle;
            }
            //title bar close button
            titleBarCloseButton.gameObject.SetActive(param.ShowTitleBarCloseButton);
            if (param.ShowTitleBarCloseButton)
            {
                titleBarCloseButton.onClick.RemoveAllListeners();
                titleBarCloseButton.onClick.AddListener(OnTitleBarCloseButtonClicked);
            }
            //message icon
            if (param.MessageIcon == null)
            {
                messageIconHorizontal.transform.parent.gameObject.SetActive(false);
                messageIconVertical.transform.parent.gameObject.SetActive(false);
            }
            else
            {
                messageIconHorizontal.transform.parent.gameObject.SetActive(true);
                messageIconVertical.transform.parent.gameObject.SetActive(true);
                messageIconHorizontal.sprite = param.MessageIcon;
                messageIconVertical.sprite   = param.MessageIcon;
            }
            //button 1
            if (string.IsNullOrEmpty(param.Button1Text) && param.Button1Icon == null)
            {
                button1.gameObject.SetActive(false);
            }
            else
            {
                button1.gameObject.SetActive(true);

                button1.onClick.RemoveAllListeners();
                if (param.Button1Action != null)
                {
                    button1.onClick.AddListener(param.Button1Action);
                }
                button1.onClick.AddListener(Close);

                if (string.IsNullOrEmpty(param.Button1Text))
                {
                    button1Text.gameObject.SetActive(false);
                }
                else
                {
                    button1Text.gameObject.SetActive(true);
                    button1Text.text = param.Button1Text;
                }
                if (param.Button1Icon == null)
                {
                    button1Image.gameObject.SetActive(false);
                }
                else
                {
                    button1Image.gameObject.SetActive(true);
                    button1Image.sprite = param.Button1Icon;
                }

                if (param.InputFieldActionsFireOnButton == Buttons.Button1 || param.InputFieldActionsFireOnButton == Buttons.All)
                {
                    button1.onClick.AddListener(FireInputFieldActions);
                }
            }
            //button 2
            if (string.IsNullOrEmpty(param.Button2Text) && param.Button2Icon == null)
            {
                button2.gameObject.SetActive(false);
            }
            else
            {
                button2.gameObject.SetActive(true);

                button2.onClick.RemoveAllListeners();
                if (param.Button2Action != null)
                {
                    button2.onClick.AddListener(param.Button2Action);
                }
                button2.onClick.AddListener(Close);

                if (string.IsNullOrEmpty(param.Button2Text))
                {
                    button2Text.gameObject.SetActive(false);
                }
                else
                {
                    button2Text.gameObject.SetActive(true);
                    button2Text.text = param.Button2Text;
                }
                if (param.Button2Icon == null)
                {
                    button2Image.gameObject.SetActive(false);
                }
                else
                {
                    button2Image.gameObject.SetActive(true);
                    button2Image.sprite = param.Button2Icon;
                }
                if (param.InputFieldActionsFireOnButton == Buttons.Button2 || param.InputFieldActionsFireOnButton == Buttons.All)
                {
                    button2.onClick.AddListener(FireInputFieldActions);
                }
            }
            //button 3
            if (string.IsNullOrEmpty(param.Button3Text) && param.Button3Icon == null)
            {
                button3.gameObject.SetActive(false);
            }
            else
            {
                button3.gameObject.SetActive(true);

                button3.onClick.RemoveAllListeners();
                if (param.Button3Action != null)
                {
                    button3.onClick.AddListener(param.Button3Action);
                }
                button3.onClick.AddListener(Close);

                if (string.IsNullOrEmpty(param.Button3Text))
                {
                    button3Text.gameObject.SetActive(false);
                }
                else
                {
                    button3Text.gameObject.SetActive(true);
                    button3Text.text = param.Button3Text;
                }
                if (param.Button3Icon == null)
                {
                    button3Image.gameObject.SetActive(false);
                }
                else
                {
                    button3Image.gameObject.SetActive(true);
                    button3Image.sprite = param.Button3Icon;
                }
                if (param.InputFieldActionsFireOnButton == Buttons.Button3 || param.InputFieldActionsFireOnButton == Buttons.All)
                {
                    button3.onClick.AddListener(FireInputFieldActions);
                }
            }
            //toggle
            bool toggleEnabled = !string.IsNullOrEmpty(param.ToggleText);

            toggle.transform.parent.gameObject.SetActive(toggleEnabled);
            if (toggleEnabled)
            {
                toggleText.text = param.ToggleText;
                toggle.onValueChanged.RemoveAllListeners();
                toggle.isOn = param.DefaultToggleState;
                if (param.ToggleValueChangedAction != null)
                {
                    toggle.onValueChanged.AddListener(param.ToggleValueChangedAction);
                }
            }
            //Input fields
            if (InputField1 != null)
            {
                if (!string.IsNullOrEmpty(param.InputField1Label))
                {
                    InputField1.text = string.IsNullOrEmpty(param.InputField1Text) ? "" : param.InputField1Text;
                    InputField1.transform.parent.gameObject.SetActive(true);
                    inputField1Label.text = param.InputField1Label;
                }
                else
                {
                    InputField1.transform.parent.gameObject.SetActive(false);
                }
            }
            if (InputField2 != null)
            {
                if (!string.IsNullOrEmpty(param.InputField2Label))
                {
                    InputField2.text = string.IsNullOrEmpty(param.InputField2Text) ? "" : param.InputField2Text;
                    InputField2.transform.parent.gameObject.SetActive(true);
                    inputField2Label.text = param.InputField2Label;
                }
                else
                {
                    InputField2.transform.parent.gameObject.SetActive(false);
                }
            }

            //animations
            switch (param.InAnimation)
            {
            case InAnimationTypes.None:
                animator.SetBool("In_None", true);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            case InAnimationTypes.Popup:
                animator.SetBool("In_None", false);
                animator.SetBool("In_Popup", true);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            case InAnimationTypes.Stamp:
                animator.SetBool("In_None", false);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", true);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            case InAnimationTypes.Spin:
                animator.SetBool("In_None", false);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", true);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            case InAnimationTypes.HorizontalExpand:
                animator.SetBool("In_None", false);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", true);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            case InAnimationTypes.VerticalExpand:
                animator.SetBool("In_None", false);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", true);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;

            default:
                animator.SetBool("In_None", true);
                animator.SetBool("In_Popup", false);
                animator.SetBool("In_Fade", false);
                animator.SetBool("In_Stamp", false);
                animator.SetBool("In_Spin", false);
                animator.SetBool("In_HorizontalExpand", false);
                animator.SetBool("In_VerticalExpand", false);
                animator.SetBool("Out_None", false);
                animator.SetBool("Out_Fade", false);
                animator.SetBool("Out_Shrink", false);
                animator.SetBool("Out_Spin", false);
                break;
            }

            //drag
            CurrentDragType = param.DragType;

            //sound effects
            if (!disableSoundEffects)
            {
                if (param.InAnimationStartSound != null)
                {
                    aSource.PlayOneShot(param.InAnimationStartSound);
                }
                else if (defaultSound_InAnimationStart != null)
                {
                    aSource.PlayOneShot(defaultSound_InAnimationStart);
                }
            }
            //close flag
            closeInvokedFlag = false;
        }
예제 #13
0
        void Start()
        {
#if FULLLOG
            MoreDebug.Log("go: " + gameObject.name);
#endif
            RegisterSelf();
            // Warn if there's no mission
            if (Missions.Length == 0)
            {
                Debug.LogWarning("OperationManager: No missions set.");
            }

            // Set up each mission
            foreach (MissionManager mi in Missions)
            {
                if (mi == null)
                {
                    continue;
                }
                mi.SetOperation(this);
                if (mi.StartOnLoad)
                {
                    OnBeginOperation.AddListener(mi.BeginMission);
                }
            }

            // Set up end managers
            foreach (EndManager em in OperationEndConditions)
            {
                em.OnEnd.AddListener(EndOperation);
                em.isActive = true;
            }

            // let the level know you're here
            level.IncrementOperations();

            // load overlays
            if (OperationOverlayNames != null)
            {
                foreach (string scenename in OperationOverlayNames)
                {
                    SceneManager.LoadScene(scenename, LoadSceneMode.Additive);  // todo: what if its not there?
                }
            }

            // Warn if there's no end criteria (level won't end)
            if (OperationEndConditions.Length == 0)
            {
                Debug.LogWarning("OperationManager: No criteria set to end the level.");
            }

            // Place the items
            StartCoroutine(PlaceItems());

            // show the op start screen
            if (!PauseGame.exists)
            {
#if FULLLOG
                MoreDebug.Log("No PauseGame -----");
#endif
            }
            if (CampaignManager.campaign.ForceMissionTerseness)
            {
                MissionTerseness = CampaignManager.campaign.OperationTerseness;
            }
            if (InfoPriority >= CampaignManager.campaign.OperationTerseness)
            {
                MessageBoxParams parms = new MessageBoxParams();
                parms.Message               = StartingInfo;
                parms.MessageBoxTitle       = OperationName;
                parms.Button1Action         = PauseGame.only.queueResume;
                parms.MultipleCallBehaviour = MultipleCallBehaviours.Queue;
                EasyMessageBox.Show(parms);
                PauseGame.only.queuePause();
            }

            // announce the start of the op
            // _opIsStarted = true;
            OnBeginOperation.Invoke();
        }
예제 #14
0
    /// <summary>
    /// Show the message box using specified param.
    /// </summary>
    /// <returns>The show.</returns>
    /// <param name="param">Parameter.</param>
    public static void Show(MessageBoxParams param)
    {
        if (Instance == null)
        {
            GameObject canvasObject = new GameObject();
            canvasObject.name = "Easy Message Box Canvas";
            canvasObject.AddComponent <Canvas>();
            canvasObject.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
            canvasObject.AddComponent <CanvasScaler>();
            canvasObject.AddComponent <GraphicRaycaster>();
            canvasObject.AddComponent <EasyMessageBox>();
            Instance = canvasObject.GetComponent <EasyMessageBox>();
            var messageBoxObject = (GameObject)Instantiate(settings.DefaultPrefab);
            var messageBox       = messageBoxObject.GetComponent <BoxController>();
            messageBoxObject.transform.SetParent(Instance.transform);
            Instance.Templates.Add(messageBox);
            Instance.boxPool.Add(new List <BoxController>());
            Instance.boxPool[0].Add(Instance.Templates[0]);
            (messageBoxObject.transform as RectTransform).anchoredPosition = Vector2.zero;
            (messageBoxObject.transform as RectTransform).sizeDelta        = Vector2.zero;
            messageBoxObject.SetActive(false);
            Debug.Log("No template found in the scene, using default message box template.");
        }
        else if (Instance.Templates == null || /*Instance.Templates.Count - 1 < param.TemplateId*/ Instance.Templates.Count == 0)
        {
            Debug.LogWarning("Cannot find template id " + param.TemplateId.ToString() + ", using default message box. Make sure to add corresponding template in the Inspector of EasyMessageBox object before you call its ID.");
            var messageBoxObject = (GameObject)Instantiate(settings.DefaultPrefab);
            var messageBox       = messageBoxObject.GetComponent <BoxController>();
            messageBoxObject.transform.SetParent(Instance.transform);
            Instance.Templates.Add(messageBox);
            param.TemplateId = 0;
            Instance.boxPool.Add(new List <BoxController>());
            Instance.boxPool[0].Add(Instance.Templates[0]);
            (messageBoxObject.transform as RectTransform).anchoredPosition = Vector2.zero;
            (messageBoxObject.transform as RectTransform).sizeDelta        = Vector2.zero;
            messageBoxObject.SetActive(false);
        }

        if (param.TemplateId > Instance.Templates.Count - 1)
        {
            Debug.Log(string.Format("Cannot find template id {0}, using the first template 0.", param.TemplateId.ToString()));
            param.TemplateId = 0;
        }

        switch (param.MultipleCallBehaviour)
        {
        case MultipleCallBehaviours.ShowNewInstance:
            Instance.ActualShowDialogBox(param);
            break;

        case MultipleCallBehaviours.Queue:
            if (!Instance.hasQueuedBox)
            {
                Instance.ActualShowDialogBox(param);
            }
            else
            {
                BoxQueue.Enqueue(param);
            }
            break;

        default:
            break;
        }
    }
예제 #15
0
    /// <summary>
    /// Show the message box. The appearance and behaviour of the message box is defined by setting
    /// a series of parameters. All parameters are optional except the 'message' string. The optional parameters
    ///  can also be set in any order using named arguments. For example: EasyMessageBox.Show("Level complete!", layout: ContentLayouts.Vertical, messageBoxTitle:"Congratulations!");
    /// </summary>
    /// <param name="message">The message text to show in the message box. The UI element itself will hide if set to null or an empty string.</param>
    /// <param name="messageIcon">The icon for the message. The UI element itself will hide if set to null. It will be to the left of the message in horizontal layout and above the message in vertical layout.</param>
    /// <param name="messageTitle">An additiontial title for the main message itself (not the title of the message box). It will be above the message text in horizontal layout and above the message icon in vertical layout. The UI element itself will hide if set to null or an empty string.</param>
    /// <param name="messageBoxTitle">The title for the message box. The title bar will hide if set to null or an empty string.</param>
    /// <param name="showCloseButtonInTitleBar">Indicates whether the title bar will show a close button if the title bar is displayed.</param>
    /// <param name="button1Icon">The icon for button 1. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button1Text">The text for button 1. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button1Action">The action to take when button 1 is pressed.</param>
    /// <param name="button2Icon">The icon for button 2. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button2Text">The text for button 2. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button2Action">The action to take when button 2 is pressed.</param>
    /// <param name="button3Icon">The icon for button 3. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button3Text">The text for button 3. To hide this button, set both its icon and text to null(or an empty string).</param>
    /// <param name="button3Action">The action to take when button 3 is pressed.</param>
    /// <param name="toggleText">The text for the toggle. Will hide the toggle if set to null or an empty string.</param>
    /// <param name="toggleAction">The action to take when the toggle's state is changed. Setting this to null will hide the toggle.</param>
    /// <param name="defaultToggleState">Decides whether the toggle is on when first displayed.</param>
    /// <param name="inputField1Label">The label text for the optional input field 1. Will hide the input field if set to null or an empty string.</param>
    /// <param name="inputField1Text">Optional text to show in input field 1 when it's first displayed</param>
    /// <param name="inputField2Label">The label text for the optional input field 2. Will hide the input field if set to null or an empty string.</param>
    /// <param name="inputField2Text">Optional text to show in input field 2 when it's first displayed</param>
    /// <param name="inputFieldAction">The action to take if any of the input field is displayed. The action requires two strings for each input field.</param>
    /// <param name="inputFieldActionsFireOnButton">Controls which button will fire the input field action. The default is button 1.</param>
    /// <param name="inAnimation">The animation type to use for animating in.</param>
    /// <param name="inAnimationStartSound">The audio clip to play when the message box begins to animate in.</param>
    /// <param name="inAnimationEndSound">The audio clip to play when the message box finishes its in-animation. This is useful when you want to emphasize when the message box is fully present, e.g. when telling the player that an achievement has be achieved.</param>
    /// <param name="outAnimation">The animation type to use for animating out.</param>
    /// <param name="outAnimationStartSound">The audio clip to play when the message box begins to animate out.</param>
    /// <param name="layout">Controls which layout to use for the message box.</param>
    /// <param name="multipleCallBehaviour">Controls the behaviour when a new call is made to show a message box while there is already a message box displaying on the screen. When set to Queue, the new calls is automatically queued and will show based on a first-in, first-out rule when an existing message box is closed. When set to ShowNewInstance, a new message box instance will show immediately.</param>
    /// <param name="dragType">Controls how the message box can be dragged.</param>
    /// <param name="templateId">Controls which template to use when displaying a message box. This is the index of the Templates list and can be found in the inspector of EasyMessageBox component.</param>
    public static void Show(string message,
                            Sprite messageIcon             = null,
                            string messageTitle            = null,
                            string messageBoxTitle         = null,
                            bool showCloseButtonInTitleBar = false,
                            Sprite button1Icon             = null,
                            string button1Text             = "OK",
                            UnityAction button1Action      = null,
                            Sprite button2Icon             = null,
                            string button2Text             = null,
                            UnityAction button2Action      = null,
                            Sprite button3Icon             = null,
                            string button3Text             = null,
                            string toggleText               = null,
                            UnityAction button3Action       = null,
                            UnityAction <bool> toggleAction = null,
                            bool defaultToggleState         = false,
                            string inputField1Label         = null,
                            string inputField1Text          = null,
                            string inputField2Label         = null,
                            string inputField2Text          = null,
                            UnityAction <string, string> inputFieldAction = null,
                            Buttons inputFieldActionsFireOnButton         = Buttons.Button1,
                            InAnimationTypes inAnimation                 = InAnimationTypes.Popup,
                            AudioClip inAnimationStartSound              = null,
                            AudioClip inAnimationEndSound                = null,
                            OutAnimationTypes outAnimation               = OutAnimationTypes.None,
                            AudioClip outAnimationStartSound             = null,
                            MessageLayout layout                         = MessageLayout.Horizontal,
                            MultipleCallBehaviours multipleCallBehaviour = MultipleCallBehaviours.ShowNewInstance,
                            DragTypes dragType = DragTypes.TitleOnly,
                            int templateId     = 0
                            )
    {
        var param = new MessageBoxParams()
        {
            Message                       = message,
            MessageIcon                   = messageIcon,
            MessageTitle                  = messageTitle,
            MessageBoxTitle               = messageBoxTitle,
            ShowTitleBarCloseButton       = showCloseButtonInTitleBar,
            Button1Icon                   = button1Icon,
            Button1Text                   = button1Text,
            Button1Action                 = button1Action,
            Button2Icon                   = button2Icon,
            Button2Text                   = button2Text,
            Button2Action                 = button2Action,
            Button3Icon                   = button3Icon,
            Button3Text                   = button3Text,
            Button3Action                 = button3Action,
            ToggleText                    = toggleText,
            ToggleValueChangedAction      = toggleAction,
            InputField1Label              = inputField1Label,
            InputField1Text               = inputField1Text,
            InputField2Label              = inputField2Label,
            InputField2Text               = inputField2Text,
            InputFieldAction              = inputFieldAction,
            InputFieldActionsFireOnButton = inputFieldActionsFireOnButton,
            DefaultToggleState            = defaultToggleState,
            InAnimation                   = inAnimation,
            InAnimationStartSound         = inAnimationStartSound,
            InAnimationEndSound           = inAnimationEndSound,
            OutAnimation                  = outAnimation,
            OutAnimationStartSound        = outAnimationStartSound,
            MessageLayout                 = layout,
            MultipleCallBehaviour         = multipleCallBehaviour,
            DragType                      = dragType,
            TemplateId                    = templateId,
        };

        Show(param);
    }