Exemplo n.º 1
0
        IEnumerator PingPongMove(ColliderConfig comp, LVector3 sPos, LVector3 ePos, float time)
        {
            float timer      = 0;
            var   degFloat   = Random.Range(1.0f - degFloatRate, 1.0f + degFloatRate).ToLFloat();
            var   sizeFloat1 = Random.Range(1.0f - sizeFloatRate, 1.0f + sizeFloatRate).ToLFloat();
            var   sizeFloat2 = Random.Range(1.0f - sizeFloatRate, 1.0f + sizeFloatRate).ToLFloat();
            var   obb        = comp.Collider as OBB2D;
            var   aabb       = comp.Collider as AABB2D;
            var   circle     = comp.Collider as Circle;
            var   startDeg   = comp.deg;
            var   endDeg     = startDeg + degFloat * (rawRotateDeg.ToLFloat());

            var startRadius = comp.Collider.radius;
            var endRandius  = sizeFloat1 * rawSize.ToLFloat();
            var rawSizeVec  = LVector2.one;
            var endSizeVec  = LVector2.one;

            if (circle == null)
            {
                rawSizeVec = obb != null ? obb.size : aabb.size;
                endSizeVec = new LVector2(sizeFloat1 * rawSize.ToLFloat(), sizeFloat2 * rawSize.ToLFloat());
            }

            while (true)
            {
                timer += Time.deltaTime;
                if (timer > time)
                {
                    break;
                }

                var timeRate = (timer / time).ToLFloat();
                //change position
                comp.SetPosition(LVector3.Lerp(sPos, ePos, timeRate));
                var collider = comp.Collider;
                //change rotation
                if (aabb == null)
                {
                    comp.SetRotation(LMath.Lerp(startDeg, endDeg, timeRate));
                }

                //change size
                if (circle != null)
                {
                    circle.radius = LMath.Lerp(startRadius, endRandius, timeRate);
                }

                if (aabb != null)
                {
                    aabb.size = LVector2.Lerp(rawSizeVec, endSizeVec, timeRate);
                }

                if (obb != null)
                {
                    obb.size = LVector2.Lerp(rawSizeVec, endSizeVec, timeRate);
                }

                yield return(null);
            }

            StartCoroutine(PingPongMove(comp, ePos, sPos,
                                        rawMoveTime * Random.Range(1.0f - timeFloatRate, 1.0f + timeFloatRate)));
        }