Exemple #1
0
    IEnumerator ScaleIcon(IconPos icon, float duration, Vector3 scaleTarget, bool resetPos = false)
    {
        float   timer      = 0;
        Vector3 startScale = icon.rectT.localScale;

        while (timer < duration)
        {
            icon.rectT.localScale = Vector3.Lerp(startScale, scaleTarget, timer / duration);
            yield return(new WaitForFixedUpdate());

            timer += Time.deltaTime;
        }

        icon.rectT.localScale = scaleTarget;

        if (resetPos)
        {
            Vector2 lastPos = Vector2.zero;

            for (int i = 0; i < emptyPos.Length; i++)
            {
                if (!emptyPos[i].Equals(icon) && emptyPos[i].rectT.anchoredPosition.x > lastPos.x)
                {
                    lastPos = emptyPos[i].rectT.anchoredPosition;
                }
            }

            lastPos.x += iconGap * 2;
            icon.rectT.anchoredPosition = lastPos;
        }
    }
Exemple #2
0
    IEnumerator MoveIcon(bool direction, IconPos icon, float duration, float distance)
    {
        float timer           = 0;
        int   directionFactor = direction ? 1 : -1;

        Vector2 startPos = icon.rectT.anchoredPosition;
        Vector2 endPos   = new Vector2(icon.rectT.anchoredPosition.x + (distance * directionFactor), icon.rectT.anchoredPosition.y);

        while (timer < duration)
        {
            icon.rectT.anchoredPosition = Vector2.Lerp(startPos, endPos, timer / duration);
            yield return(new WaitForFixedUpdate());

            timer += Time.deltaTime;
        }

        icon.rectT.anchoredPosition = endPos;
    }
Exemple #3
0
    public void RemoveIcon()
    {
        IconPos target = emptyPos[UnityEngine.Random.Range(0, emptyPos.Length - 1)];

        StartCoroutine(ScaleIcon(target, 1, Vector3.zero, true));

        for (int i = 0; i < emptyPos.Length; i++)
        {
            if (!emptyPos[i].Equals(target))
            {
                if (emptyPos[i].rectT.anchoredPosition.x > target.rectT.anchoredPosition.x)
                {
                    StartCoroutine(MoveIcon(false, emptyPos[i], 1, 0.35f));
                }
                else
                {
                    StartCoroutine(MoveIcon(true, emptyPos[i], 1, 0.35f));
                }
            }
        }
    }