Пример #1
0
    public void AddViewsForAnimal(Animal animal)
    {
        int        animalPrefabIndex = (int)animal.animalType;
        AnimalView animalView        = AnimalPrefabs[animalPrefabIndex].Spawn(animalsTransform, PointForCell(animal.column, animal.row)).GetComponent <AnimalView>();

        animalView.transform.localScale = new Vector2(0.5f, 0.5f);
        animal.view = animalView;

        SpriteRenderer animalViewRenderer = animalView.GetComponent <SpriteRenderer>();
        Color          color = animalViewRenderer.color;

        color.a = 0f;
        animalViewRenderer.color = color;

        Sequence sequence = DOTween.Sequence();

        sequence.Append(animalViewRenderer.DOFade(1f, 0.25f))
        .Join(animalView.transform.DOScale(1f, 0.25f))
        .PrependInterval(Random.Range(0f, 0.5f));
    }
Пример #2
0
    public void AnimateNewAnimals(List <List <Animal> > columns, Action completion)
    {
        float longestDuration = 0f;

        foreach (List <Animal> animals in columns)
        {
            int startRow = animals[0].row + 1;

            int animalIndex = 0;
            foreach (Animal animal in animals)
            {
                int        animalPrefabIndex = (int)animal.animalType;
                AnimalView animalView        = AnimalPrefabs[animalPrefabIndex].Spawn(animalsTransform, PointForCell(animal.column, startRow)).GetComponent <AnimalView>();
                animalView.transform.localScale = Vector3.one;
                animal.view = animalView;

                float delay    = 0.1f + 0.2f * (animals.Count - animalIndex - 1);
                float duration = (startRow - animal.row) * 0.1f;
                longestDuration = Mathf.Max(longestDuration, duration + delay);

                Vector2 newPosition = PointForCell(animal.column, animal.row);

                SpriteRenderer animalViewRenderer = animalView.GetComponent <SpriteRenderer>();
                Color          color = animalViewRenderer.color;
                color.a = 0f;
                animalViewRenderer.color = color;

                Sequence sequence = DOTween.Sequence();
                sequence.Append(animalViewRenderer.DOFade(1f, 0.05f))
                .Join(animalView.transform.DOLocalMove(newPosition, duration).SetEase(Ease.OutExpo).OnStart(() => audioSource.PlayOneShot(addAnimalSound)))
                .PrependInterval(delay);

                animalIndex++;
            }
            ;
        }

        // TODO: try to call completion in better way!
        transform.DOScale(Vector3.one, longestDuration).OnComplete(() => completion());
    }