Пример #1
0
        /// <summary>
        /// Opens the dialog with full custom options
        /// </summary>
        /// <param name="indicatorStyle"></param>
        /// <param name="progressStyle"></param>
        /// <param name="messageStyle"></param>
        /// <param name="message"></param>
        /// <param name="icon"></param>
        public void Open(IndicatorStyleEnum indicatorStyle, ProgressStyleEnum progressStyle, MessageStyleEnum messageStyle, string message = "", GameObject prefab = null)
        {
            if (gameObject.activeSelf)
            {
                return;
            }

            // Make sure we aren't parented under anything
            transform.parent = null;

            // Turn our common objects on
            closing = false;
            gameObject.SetActive(true);
            progressText.gameObject.SetActive(progressStyle == ProgressStyleEnum.Percentage);
            progressBarContainer.gameObject.SetActive(progressStyle == ProgressStyleEnum.ProgressBar);
            messageText.gameObject.SetActive(messageStyle != MessageStyleEnum.None);
            messageText.text = message;

            // Reset our loading progress
            smoothProgress = 0f;
            targetProgress = 0f;

            // Re-enable objects based on our style
            switch (indicatorStyle)
            {
            case IndicatorStyleEnum.None:
                break;

            case IndicatorStyleEnum.StaticIcon:
                // Instantiate our custom object under our animator
                if (defaultIconPrefab == null)
                {
                    UnityEngine.Debug.LogError("No Icon prefab available in loading dialog, spawning without one");
                }
                else
                {
                    instantiatedCustomObject = GameObject.Instantiate(defaultIconPrefab) as GameObject;
                    instantiatedCustomObject.transform.localPosition = new Vector3(0.0f, 13.0f, 0.0f);
                    instantiatedCustomObject.transform.localRotation = Quaternion.identity;
                    instantiatedCustomObject.transform.localScale    = new Vector3(10.0f, 10.0f, 10.0f);

                    instantiatedCustomObject.transform.Translate(messageText.transform.position);
                    instantiatedCustomObject.transform.SetParent(messageText.transform, false);
                }
                break;

            case IndicatorStyleEnum.AnimatedOrbs:
                if (defaultOrbsPrefab != null)
                {
                    instantiatedCustomObject = GameObject.Instantiate(defaultOrbsPrefab) as GameObject;
                    instantiatedCustomObject.transform.localPosition = new Vector3(0.0f, 25.0f, 0.0f);
                    //instantiatedCustomObject.transform.localRotation = Quaternion.identity;
                    instantiatedCustomObject.transform.localScale = new Vector3(3.0f, 3.0f, 3.0f);

                    instantiatedCustomObject.transform.Translate(messageText.transform.position);
                    instantiatedCustomObject.transform.SetParent(messageText.transform, false);
                }
                break;

            case IndicatorStyleEnum.Prefab:
                // Instantiate our custom object under our animator
                if (defaultPrefab == null && prefab == null)
                {
                    UnityEngine.Debug.LogError("No prefab available in loading dialog, spawning without one");
                }
                else
                {
                    instantiatedCustomObject = GameObject.Instantiate(defaultPrefab) as GameObject;
                    instantiatedCustomObject.transform.localPosition = new Vector3(0.0f, 20.0f, 0.0f);
                    instantiatedCustomObject.transform.localRotation = Quaternion.identity;
                    instantiatedCustomObject.transform.localScale    = new Vector3(10.0f, 10.0f, 10.0f);

                    instantiatedCustomObject.transform.Translate(messageText.transform.position);
                    instantiatedCustomObject.transform.SetParent(messageText.transform, false);
                }
                break;
            }
            animator.SetTrigger("Open");
        }
Пример #2
0
        /// <summary>
        /// Opens the dialog with full custom options
        /// </summary>
        /// <param name="indicatorStyle"></param>
        /// <param name="progressStyle"></param>
        /// <param name="messageStyle"></param>
        /// <param name="message"></param>
        /// <param name="icon"></param>
        public void Open(IndicatorStyleEnum indicatorStyle, ProgressStyleEnum progressStyle, MessageStyleEnum messageStyle, string message = "", Texture2D icon = null, GameObject prefab = null)
        {
            if (gameObject.activeSelf)
            {
                return;
            }

            // Make sure we aren't parented under anything
            transform.parent = null;

            // Make sure we aren't destroyed on load
            // Just in case the user is loading a scene
            DontDestroyOnLoad(transform);

            // Turn our common objects on
            closing = false;
            gameObject.SetActive(true);
            progressText.gameObject.SetActive(progressStyle == ProgressStyleEnum.Percentage);
            progressBarContainer.gameObject.SetActive(progressStyle == ProgressStyleEnum.ProgressBar);
            messageText.gameObject.SetActive(messageStyle != MessageStyleEnum.None);
            messageText.text = message;

            // Reset our loading progress
            smoothProgress = 0f;
            targetProgress = 0f;

            // Turn the style objects off
            iconRenderer.enabled = false;
            orbsObject.SetActive(false);

            /*if (displayParent != null && transform.parent != displayParent)
             * {
             *  transform.parent = displayParent;
             *  transform.localPosition = Vector3.zero;
             *  transform.localRotation = Quaternion.identity;
             * }*/

            // Re-enable objects based on our style
            switch (indicatorStyle)
            {
            case IndicatorStyleEnum.None:
                break;

            case IndicatorStyleEnum.StaticIcon:
                iconRenderer.enabled = true;
                if (defaultIcon == null && icon == null)
                {
                    UnityEngine.Debug.LogError("No icon available in loading dialog, spawning without one");
                    iconRenderer.enabled = false;
                }
                else
                {
                    // The icon sent in the function overrides the icon set in the inspector
                    iconRenderer.material.mainTexture = (icon == null) ? defaultIcon : icon;
                }
                break;

            case IndicatorStyleEnum.AnimatedOrbs:
                iconRenderer.enabled = false;
                orbsObject.SetActive(true);
                orbsObject.GetComponent <LoadingAnimation>().StartLoader();
                break;

            case IndicatorStyleEnum.Prefab:
                // Instantiate our custom object under our animator
                if (defaultPrefab == null && prefab == null)
                {
                    UnityEngine.Debug.LogError("No prefab available in loading dialog, spawning without one");
                }
                else
                {
                    // The prefab sent in the function overrides the prefab set in the inspector
                    instantiatedCustomObject = GameObject.Instantiate((prefab == null) ? defaultPrefab : prefab, animator.transform) as GameObject;
                    instantiatedCustomObject.transform.localPosition = Vector3.zero;
                    instantiatedCustomObject.transform.localRotation = Quaternion.identity;
                }
                break;
            }
            animator.SetTrigger("Open");
        }