Exemple #1
0
    private float SwitchToCharacter(string name)
    {
        string characterPath  = "StoryEngine/" + name;
        float  animateInTime  = 0.6f;
        float  animateOutTime = animateInTime * 0.6f;

        // If the character is already there, don't do anything
        if (CharacterImage.resourcePath != null && CharacterImage.resourcePath.Equals(characterPath))
        {
            return(0.0f);
        }

        // Animate out the current character!
        if (CharacterImage.resourcePath != null)
        {
            if (Spotlight.canvasGroup.alpha > 0.5f)
            {
                AnimateOutPlayer(0);

                LeanTween.value(Spotlight.gameObject, (v) => {
                    Spotlight.canvasGroup.alpha = v;
                    CharacterImage.image.color  = new Color(v, v, v, 1.0f);
                }, 1.0f, 0.0f, animateOutTime);
            }
        }

        SetPlayerStartAnimationPosition();

        LeanTween.delayedCall(animateOutTime, () => {
            AnimateInPlayer(0);

            // Load in the new character image
            CharacterImage.LoadImageWithResourcePath(characterPath);
            if (CharacterImage.image.sprite != null)
            {
                CharacterImage.rectTransform.sizeDelta = CharacterImage.image.sprite.textureRect.size;
            }
        });

        // Animate in the new character
        // animate in the character
        Spotlight.canvasGroup.alpha = 0.0f;
        LeanTween.value(Spotlight.gameObject, (v) => {
            Spotlight.canvasGroup.alpha = v;
            CharacterImage.image.color  = new Color(v, v, v, 1.0f);
        }, 0.0f, 1.0f, animateInTime).setDelay(animateOutTime);

        return(animateInTime + animateOutTime);
    }