Beispiel #1
0
        /// <summary>
        /// Opens dialog, waits for input, then closes
        /// </summary>
        /// <returns></returns>
        protected IEnumerator RunDialogOverTime()
        {
            // Create our buttons and set up our message
            GenerateButtons();
            SetTitleAndMessage();
            FinalizeLayout();
            // Register all active buttons under buttonParent as interactibles
            foreach (Transform button in buttonParent)
            {
                if (button.gameObject.activeSelf)
                {
                    SimpleDialogButton sdb = button.gameObject.GetComponent <SimpleDialogButton>();
                    if (sdb == null)
                    {
                        UnityEngine.Debug.LogError("No 'SimpleDialogButton' component attached to dialog button!");
                    }
                    RegisterInteractible(button.gameObject);
                }
            }

            // Open dialog
            state = StateEnum.Opening;
            yield return(StartCoroutine(OpenDialog()));

            state = StateEnum.WaitingForInput;
            // Wait for input
            while (state == StateEnum.WaitingForInput)
            {
                UpdateDialog();
                yield return(null);
            }
            // Close dialog
            state = StateEnum.Closing;
            yield return(StartCoroutine(CloseDialog()));

            state = StateEnum.Closed;
            // Callback
            if (OnClosed != null)
            {
                OnClosed(result);
            }
            // Wait a moment to give scripts a chance to respond
            yield return(null);

            // Destroy ourselves
            GameObject.Destroy(gameObject);
            yield break;
        }
Beispiel #2
0
        protected override void OnTapped(GameObject obj, InteractionManager.InteractionEventArgs eventArgs)
        {
            base.OnTapped(obj, eventArgs);
            // If we're not done opening, wait
            if (state != StateEnum.WaitingForInput)
            {
                return;
            }

            SimpleDialogButton button = obj.GetComponent <SimpleDialogButton>();

            // If this isn't a simple dialog button it's not our problem
            if (button == null)
            {
                return;
            }

            result.Result = button.Type;
            state         = StateEnum.Closing;
        }
        /// <summary>
        /// Generates a button based on type
        /// Sets button text based on type
        /// </summary>
        /// <param name="buttonType"></param>
        protected virtual GameObject GenerateButton(ButtonTypeEnum buttonType)
        {
            GameObject buttonGo = GameObject.Instantiate(buttonPrefab, buttonParent) as GameObject;
            // Set the text
            CompoundButtonText text = buttonGo.GetComponent <CompoundButtonText>();

            if (text != null)
            {
                text.Text = buttonType.ToString();
            }
            // Add the dialog button component
            SimpleDialogButton simpleDialogButton = buttonGo.GetComponent <SimpleDialogButton>();

            if (simpleDialogButton == null)
            {
                simpleDialogButton = buttonGo.AddComponent <SimpleDialogButton>();
            }
            simpleDialogButton.Type = buttonType;
            return(buttonGo);
        }