Exemple #1
0
    public static Sequence MakeAnimationClips(string name, Vector2Int position)
    {
        GameObject gameObject = Instantiate(instance.animationClips[instance.animationNames.IndexOf(name)], new Vector3(position.x, position.y, -2), Quaternion.identity);

        gameObject.SetActive(false);

        Sequence sequence = DOTween.Sequence();

        SpriteAnimation spriteAnimation = gameObject.GetComponent <SpriteAnimation>();
        ParticleSystem  particleSystem  = gameObject.GetComponent <ParticleSystem>();

        // Category 2 : SpriteAnimation
        if (spriteAnimation != null)
        {
            sequence = spriteAnimation.GetAnimationSequence()
                       .OnStart(() => gameObject.SetActive(true))
                       .OnComplete(() => GameObject.Destroy(gameObject));
        }
        // Category 3 : ParticleAnimation
        else if (particleSystem != null)
        {
            sequence.Append(DOVirtual.DelayedCall(particleSystem.main.startLifetime.constant, () => GameObject.Destroy(gameObject)))
            .OnStart(() => gameObject.SetActive(true))
            .OnComplete(() => GameObject.Destroy(gameObject));
        }

        sequence.Pause();

        Reserve(sequence);

        return(sequence);
    }