Esempio n. 1
0
    public static Sequence DOLocalJump(this Transform target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
    {
        if (numJumps < 1)
        {
            numJumps = 1;
        }
        float    startPosY  = target.localPosition.y;
        float    offsetY    = -1f;
        bool     offsetYSet = false;
        Sequence s          = DOTween.Sequence();

        s.Append(DOTween.To(() => target.localPosition, delegate(Vector3 x)
        {
            target.localPosition = x;
        }, new Vector3(endValue.x, 0f, 0f), duration).SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
                 .OnUpdate(delegate
        {
            if (!offsetYSet)
            {
                offsetYSet = false;
                offsetY    = (s.isRelative ? endValue.y : (endValue.y - startPosY));
            }
            Vector3 localPosition = target.localPosition;
            localPosition.y      += DOVirtual.EasedValue(0f, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
            target.localPosition  = localPosition;
        })).Join(DOTween.To(() => target.localPosition, delegate(Vector3 x)
        {
            target.localPosition = x;
        }, new Vector3(0f, 0f, endValue.z), duration).SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)).Join(DOTween.To(() => target.localPosition, delegate(Vector3 x)
        {
            target.localPosition = x;
        }, new Vector3(0f, jumpPower, 0f), duration / (float)(numJumps * 2)).SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad)
                                                                                                                        .SetRelative()
                                                                                                                        .SetLoops(numJumps * 2, LoopType.Yoyo))
        .SetTarget(target)
        .SetEase(DOTween.defaultEaseType);
        return(s);
    }
Esempio n. 2
0
    private void OnHoleGenerated(Transform hole, Transform holeWall)
    {
        holeWall.localScale = new Vector3(1, 50, 1);

        // Less shaking for holes farther from camera
        var distance                  = Vector3.Distance(Camera.main.transform.position, holeWall.position);
        var percentageDistance        = Mathf.Clamp01((distance - minD) / (maxD - minD));
        var distanceFromCameraPenalty = (1 - percentageDistance) * 1.2f;

        var shapeLength = MyMaths.ShapeLength(hole.GetComponent <MeshFilter>().mesh.vertices);

        var lenghtBonus = 1 + (Mathf.Clamp01((shapeLength - minL) / (maxL - minL)) * .5f);

        // Debug.Log($"shapeLength={shapeLength} lenghtBonus={lenghtBonus} distance={distance} distanceFromCameraPenalty={distanceFromCameraPenalty}");

        Sequence sequence = DOTween.Sequence();

        sequence.AppendCallback(() =>
        {
            holeWall.gameObject.SetActive(true);
            Signals.Get <ShakeCameraSignal>().Dispatch(beamDuration, shakeMagnitude * distanceFromCameraPenalty * lenghtBonus);
            hole.gameObject.SetActive(true);
        });
        sequence.AppendInterval(beamDuration);
        sequence.AppendCallback(() =>
        {
            holeWall.gameObject.SetActive(false);
        });
        sequence.AppendCallback(() =>
        {
            var mat = hole.GetComponent <Renderer>().material;
            DOVirtual.Float(.05f, 1, 2.5f, (percentage) =>
            {
                var eased = DOVirtual.EasedValue(0, 1, percentage, Ease.OutQuad);
                mat.SetFloat(SliceAmount, eased);
            });
        });
    }
Esempio n. 3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (started)
        {
            if (col.transform.tag == "Ground")
            {
                DOVirtual.DelayedCall(JumpCooldown, () => {
                    canJump = true;
                });

                string ShakeName = "ShakeJump";
                ProCamera2DShake.Instance.Shake(ShakeName);

                Debug.Log(stockedSpeed);

                //float tmpSpeed;
                SpeedIncrease = DOVirtual.EasedValue(stockedSpeed, stockedSpeed / 12, .25f, Ease.Linear);
                DOVirtual.DelayedCall(.4f, () => {
                    SpeedIncrease = DOVirtual.EasedValue(stockedSpeed, stockedSpeed, .15f, Ease.Linear);
                });
            }
        }
    }
Esempio n. 4
0
    IEnumerator Spin()
    {
        float currentTime    = 0;
        float totalTime      = 3f;
        float totalRotations = 1f;
        float totalDegrees   = totalRotations * 360f;

        var startingRotation = this.transform.rotation;

        float lastDegree = 0;

        while (currentTime < totalTime)
        {
            currentTime += Time.deltaTime;
            float nextDegree  = DOVirtual.EasedValue(0f, totalDegrees, Mathf.Clamp01(currentTime / totalTime), Ease.Linear);
            float deltaDegree = nextDegree - lastDegree;
            lastDegree = nextDegree;

            this.transform.RotateAround(transform.position, Vector3.up, deltaDegree);
            yield return(new WaitForEndOfFrame());
        }

        Debug.Log("spawned");
    }
    private static int EasedValue(IntPtr L)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(L);
            if (num == 4 && TypeChecker.CheckTypes(L, 1, typeof(float), typeof(float), typeof(float), typeof(AnimationCurve)))
            {
                float          from = (float)LuaDLL.lua_tonumber(L, 1);
                float          to   = (float)LuaDLL.lua_tonumber(L, 2);
                float          lifetimePercentage = (float)LuaDLL.lua_tonumber(L, 3);
                AnimationCurve easeCurve          = (AnimationCurve)ToLua.ToObject(L, 4);
                float          num2 = DOVirtual.EasedValue(from, to, lifetimePercentage, easeCurve);
                LuaDLL.lua_pushnumber(L, (double)num2);
                result = 1;
            }
            else if (num == 4 && TypeChecker.CheckTypes(L, 1, typeof(float), typeof(float), typeof(float), typeof(Ease)))
            {
                float from2 = (float)LuaDLL.lua_tonumber(L, 1);
                float to2   = (float)LuaDLL.lua_tonumber(L, 2);
                float lifetimePercentage2 = (float)LuaDLL.lua_tonumber(L, 3);
                Ease  easeType            = (Ease)((int)ToLua.ToObject(L, 4));
                float num3 = DOVirtual.EasedValue(from2, to2, lifetimePercentage2, easeType);
                LuaDLL.lua_pushnumber(L, (double)num3);
                result = 1;
            }
            else if (num == 5 && TypeChecker.CheckTypes(L, 1, typeof(float), typeof(float), typeof(float), typeof(Ease), typeof(float)))
            {
                float from3 = (float)LuaDLL.lua_tonumber(L, 1);
                float to3   = (float)LuaDLL.lua_tonumber(L, 2);
                float lifetimePercentage3 = (float)LuaDLL.lua_tonumber(L, 3);
                Ease  easeType2           = (Ease)((int)ToLua.ToObject(L, 4));
                float overshoot           = (float)LuaDLL.lua_tonumber(L, 5);
                float num4 = DOVirtual.EasedValue(from3, to3, lifetimePercentage3, easeType2, overshoot);
                LuaDLL.lua_pushnumber(L, (double)num4);
                result = 1;
            }
            else if (num == 6 && TypeChecker.CheckTypes(L, 1, typeof(float), typeof(float), typeof(float), typeof(Ease), typeof(float), typeof(float)))
            {
                float from4 = (float)LuaDLL.lua_tonumber(L, 1);
                float to4   = (float)LuaDLL.lua_tonumber(L, 2);
                float lifetimePercentage4 = (float)LuaDLL.lua_tonumber(L, 3);
                Ease  easeType3           = (Ease)((int)ToLua.ToObject(L, 4));
                float amplitude           = (float)LuaDLL.lua_tonumber(L, 5);
                float period = (float)LuaDLL.lua_tonumber(L, 6);
                float num5   = DOVirtual.EasedValue(from4, to4, lifetimePercentage4, easeType3, amplitude, period);
                LuaDLL.lua_pushnumber(L, (double)num5);
                result = 1;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, "invalid arguments to method: DG.Tweening.DOVirtual.EasedValue");
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Esempio n. 6
0
 void UpdateCallback(float val)
 {
     vector.x = DOVirtual.EasedValue(15, 100, val, Ease.InQuad);
     vector.y = DOVirtual.EasedValue(15, 100, val, Ease.OutQuad);
     Debug.Log(vector);
 }
Esempio n. 7
0
        public static Sequence DOJump(
            this Transform target,
            Vector3 endValue,
            float jumpPower,
            int jumpNum,
            float duration,
            AxisConstraint aix,
            bool snapping = false)
        {
            if (jumpNum < 1)
            {
                jumpNum = 1;
            }
            float    startPosOfAix     = 0.0f;
            float    offsetAix         = -1f;
            bool     isOffsetAixSetted = false;
            Sequence sequence          = DOTween.Sequence();

            Vector3 jumpVector3 = new Vector3(aix == AxisConstraint.X ? jumpPower : 0,
                                              aix == AxisConstraint.Y ? jumpPower : 0, aix == AxisConstraint.Z ? jumpPower : 0);
            Tween yTween = DOTween
                           .To(() => target.position, x => target.position = x, jumpVector3, duration / (jumpNum * 2))
                           .SetOptions(aix, snapping).SetEase(Ease.OutQuad).SetRelative().SetLoops(jumpNum * 2, LoopType.Yoyo)
                           .OnStart(
                () =>
            {
                switch (aix)
                {
                case AxisConstraint.X:
                    startPosOfAix = target.position.x;
                    break;

                case AxisConstraint.Y:
                    startPosOfAix = target.position.y;
                    break;

                case AxisConstraint.Z:
                    startPosOfAix = target.position.z;
                    break;
                }
            });


            switch (aix)
            {
            case AxisConstraint.X:
                sequence.Append(DOTween
                                .To(() => target.position, x => target.position = x, new Vector3(0, endValue.y, 0.0f), duration)
                                .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.Linear));
                sequence.Join(DOTween
                              .To(() => target.position, x => target.position = x, new Vector3(0.0f, 0.0f, endValue.z),
                                  duration).SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear));
                break;

            case AxisConstraint.Y:
                sequence.Append(DOTween
                                .To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0.0f, 0.0f), duration)
                                .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear));
                sequence.Join(DOTween
                              .To(() => target.position, x => target.position = x, new Vector3(0.0f, 0.0f, endValue.z),
                                  duration).SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear));
                break;

            case AxisConstraint.Z:
                sequence.Append(DOTween
                                .To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0.0f, 0.0f), duration)
                                .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear));
                sequence.Join(DOTween
                              .To(() => target.position, x => target.position = x, new Vector3(0.0f, endValue.y, 0),
                                  duration).SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.Linear));
                break;
            }


            sequence.Join(yTween).SetTarget(target).SetEase(DOTween.defaultEaseType);
            yTween.OnUpdate(() =>
            {
                if (!isOffsetAixSetted)
                {
                    isOffsetAixSetted = true;
                    switch (aix)
                    {
                    case AxisConstraint.X:
                        offsetAix = sequence.isRelative ? endValue.x : endValue.x - startPosOfAix;
                        break;

                    case AxisConstraint.Y:
                        offsetAix = sequence.isRelative ? endValue.y : endValue.y - startPosOfAix;
                        break;

                    case AxisConstraint.Z:
                        offsetAix = sequence.isRelative ? endValue.z : endValue.z - startPosOfAix;
                        break;
                    }
                }

                float y          = DOVirtual.EasedValue(0.0f, offsetAix, yTween.ElapsedPercentage(), Ease.OutQuad);
                Vector3 position = target.position + new Vector3(aix == AxisConstraint.X ? y : 0,
                                                                 aix == AxisConstraint.Y ? y : 0, aix == AxisConstraint.Z ? y : 0);

                target.position = position;
            });
            return(sequence);
        }
Esempio n. 8
0
 /// <summary>
 /// 计算Ease曲线插值
 /// </summary>
 /// <param name="from">区间左端点</param>
 /// <param name="to">区间右端点</param>
 /// <param name="t">区间百分比 0-1</param>
 /// <param name="easeType"></param>
 /// <returns></returns>
 public static float CalcEase(float from, float to, float t, Ease easeType)
 {
     return(DOVirtual.EasedValue(from, to, t, easeType));
 }
Esempio n. 9
0
    public IEnumerator DanceCo(List <Player> currentPlayers, Player byPlayer, OrbitInput orbitInput, OrbitFollow orbitFollow, Camera camera)
    {
        foreach (var currentPlayer in currentPlayers)
        {
            currentPlayer.SetInputEnabled(false);
        }

        orbitInput.enabled  = false;
        orbitFollow.enabled = false;
        orbitFollow.SetAngle(0);

        float circumferenceSpeed = 15f;

        Vector3   oldTarget       = orbitFollow.FollowTransform.position;
        Transform targetTransform = byPlayer.danceTarget;
        Vector3   target          = targetTransform.position;
        Vector3   forward         = targetTransform.forward;

        Vector3 cameraStartPosition = camera.transform.position;
        Vector3 cameraEndPosition   = target + forward.normalized * 5f + Vector3.up * 0.25f;

        { //get into cameraEndPosition, looking at the Dance Target
            Vector3 midpoint = cameraStartPosition + ((cameraEndPosition - cameraStartPosition) / 2f);

            float startAngle = AngleOnXZ(midpoint, cameraStartPosition);
            float endAngle   = AngleOnXZ(midpoint, cameraEndPosition);

            float angleToMove = startAngle - endAngle;

            float radius        = Vector3.Distance(new Vector3(midpoint.x, 0, midpoint.z), new Vector3(cameraStartPosition.x, 0, cameraStartPosition.z));
            float circumference = Mathf.PI * 2f * radius;

            float      distanceToMove = circumference * (Mathf.Abs(angleToMove) / 360f);
            float      timeToMove     = distanceToMove / circumferenceSpeed;
            Quaternion startRotation  = camera.transform.rotation;
            float      currentTime    = 0f;
            float      lastDegree     = 0f;
            while (currentTime < timeToMove)
            {
                currentTime += Time.deltaTime;
                float nextDegree = DOVirtual.EasedValue(0f, angleToMove, currentTime / timeToMove, Ease.OutCubic);
                camera.transform.RotateAround(midpoint, Vector3.up, nextDegree - lastDegree);
                lastDegree = nextDegree;

                float clamp = Mathf.Clamp(currentTime, 0f, timeToMove - 0.25f);

                Vector3 cam = camera.transform.position;
                cam.y = DOVirtual.EasedValue(cameraStartPosition.y, cameraEndPosition.y, clamp / (timeToMove - 0.2f), Ease.InOutCubic); //subtract a bit so it finishes early?
                camera.transform.position = cam;

                camera.transform.LookAt(target + ((oldTarget - target) * (1 - DOVirtual.EasedValue(0, 1f, clamp / (timeToMove - 0.25f), Ease.OutCubic))));

                yield return(new WaitForEndOfFrame());
            }

            Debug.Log(angleToMove / timeToMove);
        }

        yield return(new WaitForSeconds(0.1f));

        foreach (var currentPlayer in currentPlayers)
        {
            currentPlayer.Dance();
            yield return(new WaitForSeconds(0.25f));
        }

        fireworkController.Spawn(byPlayer.danceTarget.position);


        {//spin around the guy
            //translate circumferenceSpeed into degreesPerSecond
            float radius                    = Vector3.Distance(new Vector3(target.x, 0, target.z), new Vector3(camera.transform.position.x, 0, camera.transform.position.z));
            float circumference             = Mathf.PI * 2f * radius;
            float timeToTravelCircumference = circumference / 10f;

            float totalDegrees       = 360f * 2f;                         //two revolutions
            float timeToTravelDegree = timeToTravelCircumference / 360f;  //time per degree
            float totalTime          = timeToTravelDegree * totalDegrees; //degree * time per degree

            float currentTime = 0f;
            float lastDegree  = 0f;
            while (currentTime < totalTime)
            {
                currentTime += Time.deltaTime;

                float nextDegree  = DOVirtual.EasedValue(0f, totalDegrees, currentTime / totalTime, Ease.InOutQuad);
                float degreeDelta = nextDegree - lastDegree;
                lastDegree = nextDegree;

                camera.transform.RotateAround(target, Vector3.up, degreeDelta);

                if (currentTime / totalTime > 0.25f)
                {
                    camera.transform.position -= camera.transform.forward * Time.deltaTime * 2f;
                    camera.transform.LookAt(target);
                }

                yield return(new WaitForEndOfFrame());
            }
        }

        if (false)
        {
            orbitFollow.SetInputs(1, new Vector2(0, 0));
            orbitInput.enabled  = true;
            orbitFollow.enabled = true;
            orbitFollow.SetAngle(45f);

            foreach (var currentPlayer in currentPlayers)
            {
                currentPlayer.StopDance();
                currentPlayer.SetInputEnabled(true);
            }
        }
    }