Beispiel #1
0
    public UIPromptDisplay Prompt(float lifetime, TransitionPreset transitionPreset, params object[] elements)
    {
        UIPromptDisplay spawnedPrompt = Instantiate(promptDisplayPrefab, Vector2.zero, Quaternion.identity, promptParent);

        spawnedPrompt.InitPrompt(Vector2.zero, transitionPreset, lifetime, elements);

        return(spawnedPrompt);
    }
Beispiel #2
0
    public void PromptIfEmpty(float lifetime, TransitionPreset transitionPreset, params object[] elements)
    {
        if (currentlySpawnedPrompt != null)
        {
            return;
        }

        currentlySpawnedPrompt = Prompt(lifetime, transitionPreset, elements);
    }
        /// <summary>
        /// Inits the prompt.
        /// </summary>
        /// <param name="pos">Position.</param>
        /// <param name="lifetime">Life time.</param>
        /// <param name="elements">UI <paramref name="elements"/>. Can be <c>string</c>, <c>Sprite</c> or <c>GameObject</c>.</param>
        public void InitPrompt(Vector2 pos, TransitionPreset transitionPreset, float lifetime, params object[] elements)
        {
            hasBeenInitialized = false;

            for (int i = 0; i < elements.Length; i++)
            {
                if (elements[i] is Sprite)
                {
                    Image spawnedImage = Instantiate(standardImagePrefab, layoutGroup.transform);
                    spawnedImage.sprite = elements[i] as Sprite;
                    spawnedImage.gameObject.SetActive(true);
                }
                else if (elements[i] is string)
                {
                    Text spawnedText = Instantiate(standardTextPrefab, transform);
                    spawnedText.text = elements[i] as string;
                    spawnedText.gameObject.SetActive(true);

                    ContentSizeFitter csf = spawnedText.GetComponent <ContentSizeFitter>();
                    csf.SetLayoutHorizontal();
                    Destroy(csf);

                    spawnedText.transform.SetParent(layoutGroup.transform);
                }
                else if (elements[i] is GameObject)
                {
                    GameObject spawnedGameObject = Instantiate(elements[i] as GameObject, layoutGroup.transform);
                }
                else
                {
                    Debug.LogError("An object was given to the UIPromptDisplay that could not be handled. (Param " + i + ").", this);
                    Destroy(gameObject);
                    return;
                }
            }

            rootRectTransform.anchoredPosition = pos;

            // if the lifetime is < 0f, the object is destroyed immediately
            // feel free to fix this problem inside of UITransition instead. /Tomas
            bool destroyAfterLifetime = lifetime >= 0f;

            transitioner.InitTransition(lifetime, destroyAfterLifetime, new UITransitionData(transitionPreset));

            hasBeenInitialized = true;
        }
Beispiel #4
0
        private void SpawnSamplePrompt(TransitionPreset preset, float lifeTime)
        {
            UIPromptDisplay spawnedPD = Instantiate(defaultPromptDisplay, promptDisplayParent);

            spawnedPD.InitPrompt(Vector2.zero, preset, lifeTime, testSprite, "Some cool sample text.");
        }
        public UITransitionData(TransitionPreset transitionPreset)
        {
            useAlpha    = false;
            useScale    = false;
            usePosition = false;

            alphaSpeed = 10f;
            scaleSpeed = 10f;
            moveSpeed  = 10f;

            alphaFadeIn     = false;
            alphaFadeOut    = false;
            scaleFadeIn     = false;
            scaleFadeOut    = false;
            positionFadeIn  = false;
            positionFadeOut = false;
            localPosition   = false;

            startPosition = new Vector2(0f, 0f);
            endPosition   = new Vector2(0f, 0f);

            switch (transitionPreset)
            {
            case TransitionPreset.FadeIn:
                useAlpha     = true;
                useScale     = false;
                usePosition  = false;
                alphaSpeed   = 10f;
                alphaFadeIn  = true;
                alphaFadeOut = true;
                break;

            case TransitionPreset.ScaleIn:
                useAlpha     = false;
                useScale     = true;
                usePosition  = false;
                scaleSpeed   = 10f;
                scaleFadeIn  = true;
                scaleFadeOut = true;
                break;

            case TransitionPreset.TopDown:
                useAlpha        = true;
                useScale        = false;
                usePosition     = true;
                alphaSpeed      = 10f;
                moveSpeed       = 10f;
                positionFadeIn  = true;
                positionFadeOut = false;
                alphaFadeIn     = false;
                alphaFadeOut    = true;
                startPosition   = new Vector2(0f, 2000f);
                localPosition   = true;
                break;

            case TransitionPreset.LeftToRight:
                useAlpha        = false;
                useScale        = false;
                usePosition     = true;
                moveSpeed       = 15f;
                positionFadeIn  = true;
                positionFadeOut = true;
                startPosition   = new Vector2(-2000f, 0f);
                endPosition     = new Vector2(2000f, 0f);
                localPosition   = true;
                break;
            }
        }