Пример #1
0
        public IEnumerator DestroyCarparkEffect(GameObject carpark, GameObject decorations,
                                                Action <bool> callback = null, int tilesPerIteration = 8)
        {
            callback?.Invoke(true);

            foreach (Transform child in decorations.transform)
            {
                StartCoroutine(FadeAnimation(child.gameObject, FadeDirection.Out, false, null, 1f));
            }

            List <GameObject> tiles = new List <GameObject>();

            foreach (Transform child in carpark.transform)
            {
                tiles.Add(child.gameObject);
            }

            List <GameObject> shuffledList = Randomiser.ShuffleList(tiles);

            for (int i = 0; i < shuffledList.Count; i = i + tilesPerIteration)
            {
                int completed = 0;
                int expected  = tilesPerIteration;
                for (int j = 0; j < tilesPerIteration; j++)
                {
                    if (i + j < shuffledList.Count)
                    {
                        StartCoroutine(FadeAnimation(shuffledList[i + j], FadeDirection.Out, true, status =>
                        {
                            if (status)
                            {
                                completed++;
                            }
                        }));
                    }
                    else
                    {
                        expected--;
                    }
                }

                yield return(new WaitUntil(() => completed == expected));
            }

            callback?.Invoke(true);
            Debug.Log("Destroyed old carpark");
        }
Пример #2
0
        public IEnumerator SpawnCarparkEffect(GameObject carpark, GameObject decorations, Action <bool> callback = null,
                                              int tilesPerIteration = 8)
        {
            if (decorations != null)
            {
                foreach (Transform child in decorations.transform)
                {
                    Material material = child.GetComponent <SpriteRenderer>().material;
                    var      color    = material.color;
                    color.a        = 0f;
                    material.color = color;
                }
            }

            List <GameObject> tiles = new List <GameObject>();

            foreach (Transform child in carpark.transform)
            {
                tiles.Add(child.gameObject);
                Material material = child.GetComponent <SpriteRenderer>().material;
                var      color    = material.color;
                color.a        = 0f;
                material.color = color;
            }

            List <GameObject> shuffledList = Randomiser.ShuffleList(tiles);

            for (int i = 0; i < shuffledList.Count; i = i + tilesPerIteration)
            {
                int completed = 0;
                int expected  = tilesPerIteration;
                for (int j = 0; j < tilesPerIteration; j++)
                {
                    if (i + j < shuffledList.Count)
                    {
                        StartCoroutine(FadeAnimation(shuffledList[i + j], FadeDirection.In, true, status =>
                        {
                            if (status)
                            {
                                completed++;
                            }
                        }));
                    }
                    else
                    {
                        expected--;
                    }
                }

                yield return(new WaitUntil(() => completed == expected));
            }

            if (decorations != null)
            {
                foreach (Transform child in decorations.transform)
                {
                    StartCoroutine(FadeAnimation(child.gameObject, FadeDirection.In, false, null, 1f));
                }
            }

            callback?.Invoke(true);
            Debug.Log("Created a new carpark");
        }