示例#1
0
    IEnumerator PingPongMove(DebugUnityColliderProxy comp, LVector3 sPos, LVector3 ePos, float time)
    {
        float   timer = 0;
        Vector3 deg;

        deg.x = Random.Range(1.0f - degFloatRate, 1.0f + degFloatRate);
        deg.y = Random.Range(1.0f - degFloatRate, 1.0f + degFloatRate);
        deg.z = Random.Range(1.0f - degFloatRate, 1.0f + degFloatRate);
        var startDeg = comp.transform.localRotation.eulerAngles.ToLVector3();
        var endDeg   = (startDeg.ToVector3() + (deg * rawRotateDeg)).ToLVector3();

        var obb    = comp.Collider as OBB;
        var aabb   = comp.Collider as AABB;
        var sphere = comp.Collider as Sphere;

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

            var timeRate = (timer / time).ToLFloat();
            //change position
            comp.transform.position = (LVector3.Lerp(sPos, ePos, timeRate).ToVector3());
            var collider = comp.Collider;
            //change rotation
            if (aabb == null)
            {
                Vector3 tdeg = LMath.Lerp(startDeg, endDeg, timeRate).ToVector3();
                comp.transform.rotation = Quaternion.Euler(tdeg.x, tdeg.y, tdeg.z);
            }

            yield return(null);
        }

        StartCoroutine(PingPongMove(comp, ePos, sPos,
                                    rawMoveTime * UnityEngine.Random.Range(1.0f - timeFloatRate, 1.0f + timeFloatRate)));
    }
示例#2
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)));
        }