Beispiel #1
0
    public IEnumerator ResetLettersToSaveLocaion(float duration)
    {
        var letters = Singleton.Instance.LetterController.AllLetters;

        var startPos = letters.Select(l => l.transform.position).ToList();

        yield return(MsgAnimation.RunAnimation(
                         duration,
                         v =>
        {
            for (int i = 0; i < letters.Count; i++)
            {
                letters[i].transform.position = Vector3.Lerp(startPos[i], _letterPos[i], v);
            }
        }));
    }
        private IEnumerator ActivateImages()
        {
            // Get Fade in images
            var          fadeInImages  = Images;
            List <Image> fadeOutImages = GetSiblingImages();

            // Disable Interaction during animation
            var eventSystem = EventSystem.current;

            eventSystem.enabled = false;

            // Enable FadeIn Images
            fadeInImages.ForEach(fiImage => fiImage.gameObject.SetActive(true));

            // Run fade in/out animation
            yield return(MsgAnimation.RunAnimation(
                             AvatarWindow.TransitionDuration,
                             v =>
            {
                // Fade out
                foreach (var fadeOutImage in fadeOutImages)
                {
                    fadeOutImage.color = MgsColorUtility.FadeOut(v);
                }

                // Fade in
                foreach (var fadeInImage in fadeInImages)
                {
                    fadeInImage.color = MgsColorUtility.FadeIn(v);
                }
            }));

            // Disable Fade out images
            fadeOutImages.ForEach(foImage => foImage.gameObject.SetActive(false));

            // Enable Interaction during animation
            eventSystem.enabled = true;
        }
Beispiel #3
0
    public IEnumerator ShuffleRuntime(MonoBehaviour owner)
    {
        List <LetterBound> letterBounds = ComputeLetterBounds();
        // Get target bound
        Bounds targetBounds = letterBounds[0].GetBounds();

        for (int i = 1; i < letterBounds.Count; i++)
        {
            letterBounds[i].AddBounds(ref targetBounds);
        }

        owner.StartCoroutine(Singleton.Instance.CameraController.FocusToBound(targetBounds));

        yield return(MsgAnimation.RunAnimation(
                         1f,
                         (v) =>
        {
            foreach (var letterBound in letterBounds)
            {
                letterBound.MoveTowardTarget(v);
            }
        }));
    }
    public IEnumerator RunAnimation(List <Letter> letters, Dictionary <Letter, Vector3> target)
    {
        var startPos = new Dictionary <Letter, Vector3>();

        letters.ForEach(l => startPos.Add(l, l.transform.position));

        letters.ForEach(l => l.Select());

        OnLetterSelected.Invoke();

        yield return(new WaitForSeconds(0.5f));

        yield return(MsgAnimation.RunAnimation(
                         Duration,
                         value =>
        {
            letters.ForEach(l =>
                            l.transform.position = Vector3.Lerp(startPos[l], target[l], value)
                            );
        }));

        letters.ForEach(l => l.Unselect());
        OnLetterUnselected.Invoke();
    }
Beispiel #5
0
    public IEnumerator Shuffle()
    {
        _compressCount = 1;

        if(Paritions==null)
            Paritions=new List<List<Letter>>();
        Paritions.Clear();

        var allLetters = 
            new List<Letter>(Singleton.Instance.LetterController.AllLetters);

        while (allLetters.Count>0)
        {
            var letters = new List<Letter>();
            allLetters[0].GetConnectedLetters(letters);
            Paritions.Add(letters);
            letters.ForEach(l=>allLetters.Remove(l));
        }

        #region Shuffle partions

        for (int i = 0; i < Paritions.Count * 2; i++)
        {
            int p1 = Random.Range(0, Paritions.Count);
            int p2 = Random.Range(0, Paritions.Count);

            var tp = Paritions[p1];
            Paritions[p1] = Paritions[p2];
            Paritions[p2] = tp;
        }

        #endregion

        #region Get bounds

        List<LetterBound> letterBounds = new List<LetterBound>();

        foreach (List<Letter> letters in Paritions)
            letterBounds.Add(new LetterBound(letters));

        #endregion

        #region Place as a grid

        int columns = Mathf.RoundToInt(Mathf.Sqrt(letterBounds.Count));

        int x = 0, y = 0;

        for (int i = 0; i <= columns; i++)
        {
            int width = 0;
            int height = 0;

            for (int j = 0; j < columns; j++)
            {
                int index = i * columns + j;

                if (index >= Paritions.Count)
                    break;

                width += letterBounds[index].Width;

                if (height < letterBounds[index].Height)
                    height = letterBounds[index].Height;
            }

            x = -width / 2;

            for (int j = 0; j < columns; j++)
            {
                int index = i * columns + j;

                if (index >= Paritions.Count)
                    break;

                var bounds = letterBounds[index];

                bounds.SetTarget(x, y + (height - bounds.Height) / 2);

                x += bounds.Width;

            }

            y += height;
        }

        #endregion

        #region Move to center

        foreach (var letterBound in letterBounds)
            letterBound.TargetY += -y / 2 - 2;

        #endregion

        if (Application.isPlaying)
        {
            // Get target bound
            Bounds targetBounds = letterBounds[0].GetBounds();

            for (int i = 1; i < letterBounds.Count; i++)
                letterBounds[i].AddBounds(ref targetBounds);

            StartCoroutine(Singleton.Instance.CameraController.FocusToBound(targetBounds));

            yield return MsgAnimation.RunAnimation(
                1f,
                (v) =>
                {
                    foreach (var letterBound in letterBounds)
                        letterBound.MoveTowardTarget(v);
                });
        }
        else
            foreach (var letterBound in letterBounds)
                letterBound.MoveTowardTarget(1f);
    }