예제 #1
0
    // Main loop during animation
    IEnumerator CollectAnimation()
    {
        float t     = 0;
        float speed = 1.0f;


        // 첫 실행시 소리발생
        if (_playSoundMode == PLAY_SOUND_MODE.AT_BEGINNING)
        {
            _collectinEffectController.PlayCollectingSound();
        }

        // 1st step :  첫 좌표를 생성
        Vector3 direction;

        if (_expansionMode == EXPANSION_MODE.UPWARD)
        {
            direction = new Vector3((Random.value - 0.5f) * _moveHorizontalFactor, _moveUpFactor, 0.0f);
        }
        else
        {
            direction = new Vector3((Random.value - 0.5f) * _moveHorizontalFactor, (Random.value - 0.5f) * _moveUpFactor, 0.0f);
        }

        while (t < _expansionDuration)
        {
            t += Time.deltaTime * _animationSpeed;
            if (_expansionMode == EXPANSION_MODE.UPWARD)
            {
                transform.position += Vector3.Scale(direction, new Vector3(1, speed, 1));
            }
            else
            {
                transform.position += Vector3.Scale(direction, new Vector3(speed, speed, 1));
            }
            speed = Mathf.Exp(-4 * t / _expansionDuration);
            yield return(new WaitForFixedUpdate());
        }

        // 2nd step : Move to destination
        t = 0;
        Vector3 pos   = transform.position;
        Vector3 scale = transform.localScale / _scaleDiminutionFactor;

        while (t < 1.0f)
        {   //보간을 적용해서 pos------->_itemDisplayer의 위치로 이동하게 한다.
            t += Time.deltaTime * _animationSpeed;
            transform.position   = Vector3.Lerp(pos, _itemDisplayerTransform.position, t);
            transform.localScale = Vector3.Lerp(transform.localScale, scale, t);
            yield return(new WaitForFixedUpdate());
        }

        // 사운드가 움직임이 끝나고 들리게 한다.
        if (_playSoundMode == PLAY_SOUND_MODE.AT_THE_END)
        {
            _collectinEffectController.PlayCollectingSound();
        }

        //인스턴스 리스트에 넣고 이미지를 세팅한다.
        // 코인하나당 증가할 value 가 된다.

        if (_displayer == DISPLAYER_MODE.GOLD)
        {
            _itemDisplayer.AddItem(Amount);
        }
        else if (_displayer == DISPLAYER_MODE.TROPHY)
        {
            _itemDisplayer_trophy.AddItem(Amount);
        }
        else if (_displayer == DISPLAYER_MODE.EX)
        {
            _itemDisplayer_Ex.AddItem(Amount);
        }
        else if (_displayer == DISPLAYER_MODE.NONE)
        {
            Debug.Log("Mode를 선택하여 주십시오");
        }


        _animationRunning = false;

        StartCoroutine(CheckIfAlive(1.5f));

        // Hide this item until next reuse
        _image.enabled = false;

        yield return(null);
    }