예제 #1
0
        protected override void UpdateIn()
        {
            base.UpdateIn();

            if (Holding)
            {
                canvasGroup.alpha = 0f;

                KnobValue  = Mathf.Clamp(YValue, 0f, 100f);
                KnobValue /= 100f;

                UpdatePullableOrientation();
            }

            if (mouseEntered)
            {
                FColorMethods.LerpMaterialColor(markerMaterial, "_Color", Color.green);
            }
            else
            {
                FColorMethods.LerpMaterialColor(markerMaterial, "_Color", Color.black);
            }
        }
        protected override void UpdateIn()
        {
            base.UpdateIn();

            transform.localRotation = Quaternion.Slerp(transform.localRotation, initialRotation * offsetRotation, Time.deltaTime * 9f * rotationIncreaser);

            float angleDiff = Quaternion.Angle(transform.localRotation, offsetRotation);

            if (Holding)
            {
                Vector3 forwardA = transform.localRotation * Vector3.forward;
                Vector3 forwardB = (initialRotation * offsetRotation) * Vector3.forward;
                float   angleA   = Mathf.Atan2(forwardA.x, forwardA.z) * Mathf.Rad2Deg;
                float   angleB   = Mathf.Atan2(forwardB.x, forwardB.z) * Mathf.Rad2Deg;
                float   diff     = -Mathf.DeltaAngle(angleA, angleB);
                if (ReversePull)
                {
                    diff = -diff;
                }

                if (YValue < 0f)
                {
                    YValue = 0f;
                }
                if (YValue > 100f)
                {
                    YValue = 100f;
                }

                velocity = Mathf.Lerp(velocity, diff, Time.deltaTime * 9f);
            }
            else
            {
                velocity = Mathf.Lerp(velocity, 0f, Time.deltaTime * Deceleration);
                //YValue += velocity * 0.5f;
                //PullValue += (velocity / 100f) * 0.5f;
                float yAdd = velocity * 2.5f; // * Mathf.Abs(RotationRanges.x - RotationRanges.y)
                YValue += yAdd * Time.deltaTime * 12f;

                if (YValue < 0f)
                {
                    YValue = 0f;
                }
                if (YValue > 100f)
                {
                    YValue = 100f;
                }

                PullValue = YValue / 100f;
                //PullValue += yAdd / 100f;

                float range = Mathf.Lerp(RotationRanges.x, RotationRanges.y, PullValue);
                offsetRotation = Quaternion.Euler(range * RotationAxis.x, range * RotationAxis.y, range * RotationAxis.z);
            }

            rotationIncreaser = Mathf.Lerp(rotationIncreaser, Mathf.Lerp(2f, 4f, Mathf.InverseLerp(5f, 45f, angleDiff)), Time.deltaTime * 10f);

            if (angleDiff < 0.01f && velocity < 0.01f)
            {
                animationFinished = true;
            }
            else
            {
                animationFinished = false;
            }

            if (Holding)
            {
                canvasGroup.alpha = 0f;
                Sensitivity       = startSensitivity;
                if (ReversePull)
                {
                    Sensitivity *= -1f;
                }

                // Checking if pull should behave in reverse way
                if (EnteredTransform)
                {
                    if (lookDot < 0f)
                    {
                        Sensitivity *= -1f;
                    }
                }

                PullValue  = Mathf.Clamp(YValue, 0f, 100f);
                PullValue /= 100f;

                UpdatePullableOrientation();
            }
            else
            {
                if (animationFinished)
                {
                    conditionalExit = false;
                }
            }

            if (ToEmmit)
            {
                if (mouseEntered)
                {
                    FColorMethods.LerpMaterialColor(ToEmmit.material, "_EmissionColor", Color.white * 0.3f);
                }
                else
                {
                    FColorMethods.LerpMaterialColor(ToEmmit.material, "_EmissionColor", Color.black);
                }
            }
        }
예제 #3
0
        protected override void UpdateIn()
        {
            base.UpdateIn();

            Vector3 startPos  = transform.localPosition;
            Vector3 startPosW = transform.position;

            transform.localPosition = Vector3.Lerp(transform.localPosition, initialLocalPosition + transform.TransformVector(targetPositionOffset), Time.deltaTime * 7f * translationIncreaser);
            Vector3 postPosW = transform.position;

            float diff = Vector3.Distance(transform.localPosition, initialLocalPosition + transform.TransformVector(targetPositionOffset));

            translationIncreaser = Mathf.Lerp(translationIncreaser, Mathf.Lerp(1f, 3f, Mathf.InverseLerp(0.001f, 0.3f, diff)), Time.deltaTime * 8f);

            if (diff < 0.005f && velocity < 0.005f)
            {
                animationFinished = true;
            }
            else
            {
                animationFinished = false;
            }

            if (Holding)
            {
                canvasGroup.alpha = 0f;

                Sensitivity = -startSensitivity;

                if (ReversePull)
                {
                    Sensitivity *= -1f;
                }

                if (EnteredTransform)
                {
                    if (lookDot > 0f)
                    {
                        Sensitivity *= -1f;
                    }
                }

                PullValue  = Mathf.Clamp(YValue, 0f, 100f);
                PullValue /= 100f;

                if (YValue < 0f)
                {
                    YValue = 0f;
                }
                if (YValue > 100f)
                {
                    YValue = 100f;
                }

                UpdatePullableOrientation();

                float diffVel;
                if (NoDiffVelo)
                {
                    //Debug.Log("PRe pos, now pos: " + startPos + " , " + transform.position + " sum = " + SumVector(startPos) + " , " + SumVector(transform.position) + " diff = " + ((SumVector(startPos) - SumVector(transform.position))));
                    diffVel = diff * Mathf.Sign((initialLocalPosition - transform.localPosition).magnitude - targetPositionOffset.magnitude);
                }
                else
                {
                    //diffVel = diff * Mathf.Sign(SumVector(transform.position - startPos));
                    diffVel = diff * Mathf.Sign(SumVector(transform.InverseTransformVector(postPosW) - transform.InverseTransformVector(startPosW)));
                }

                //if (!ReversePull) diffVel = -diffVel;
                velocity = Mathf.Lerp(velocity, diffVel, Time.deltaTime * 12f);
            }
            else
            {
                velocity = Mathf.Lerp(velocity, 0f, Time.deltaTime * Deceleration);
                YValue  += velocity * (40 / DrawedPositionOffset.magnitude) * Time.deltaTime * 12f;

                if (YValue < 0f)
                {
                    YValue = 0f;
                }
                if (YValue > 100f)
                {
                    YValue = 100f;
                }

                PullValue = Mathf.Clamp(YValue, 0f, 100f);
                PullValue = YValue / 100f;

                targetPositionOffset = Vector3.Lerp(Vector3.zero, DrawedPositionOffset, PullValue);

                if (animationFinished)
                {
                    conditionalExit = false;
                }
            }

            if (ToEmmit)
            {
                if (mouseEntered)
                {
                    FColorMethods.LerpMaterialColor(ToEmmit.material, "_EmissionColor", Color.white * 0.3f);
                }
                else
                {
                    FColorMethods.LerpMaterialColor(ToEmmit.material, "_EmissionColor", Color.black);
                }
            }
        }