Ejemplo n.º 1
0
    private void OnValidate()
    {
        if (_isSpecialConveyor)
        {
            switch (_specialBeltType)
            {
            case SpecialBeltType.SpeedUp:
                if (_heldSpeed.Abs() <= _speed.Abs())
                {
                    Debug.LogWarning("Speed-up belt's held speed is lower than initial speed!", this);
                }

                break;

            case SpecialBeltType.SpeedDown:
                if (_heldSpeed.Abs() >= _speed.Abs())
                {
                    Debug.LogWarning("Slow-down belt's held speed is higher than initial speed!", this);
                }

                break;
            }

            if (_heldSpeed > 0 && _speed < 0 || _heldSpeed < 0 && _speed > 0)
            {
                Debug.LogWarning("Special belt's held speed will reverse the belt's direction!");
            }
        }
    }
Ejemplo n.º 2
0
 static float Copysign(float a, float b)
 {
     if (b < 0)
     {
         return(-a.Abs( ));
     }
     return(a.Abs( ));
 }
Ejemplo n.º 3
0
 float GetSegmentsByAngle(float angle)
 {
     if (angle.Abs() <= 1)
     {
         return(1);
     }
     else if (angle.Abs() < 90)//proportionaly twice as many segments for small angle canvases
     {
         return(baseCircleSegments * (Mathf.Abs(angle).Remap(0, 90, 0.01f, 0.5f)));
     }
     else
     {
         return(baseCircleSegments * (Mathf.Abs(angle).Remap(90, 360.0f, 0.5f, 1)));
     }
 }
Ejemplo n.º 4
0
 private void Consider(ref float val, float newVal)
 {
     if (newVal.Abs() > val.Abs())
     {
         val = newVal;
     }
 }
Ejemplo n.º 5
0
    private void CheckForWall()
    {
        if (!Controller.OnGround())
        {
            if (Controller.Input.VerticalAxisRaw.Abs() > 0f)
            {
                Vector3 startLocation = Controller.Model.position +
                                        ((Controller.MyCamera.transform.forward.With(y: 0f) * .25f) *
                                         Controller.Input.VerticalAxisRaw);

                zMovement =
                    (Physics.CheckCapsule(startLocation, startLocation + Vector3.up, .15f, Controller.MovementData.GroundLayer)) ?
                    0f : 1f;
            }

            if (Controller.Input.HorizontalAxisRaw.Abs() > 0f)
            {
                Vector3 startLocation = Controller.Model.position +
                                        ((Controller.MyCamera.transform.right.With(y: 0f) * .25f) *
                                         Controller.Input.HorizontalAxisRaw);

                xMovement =
                    (Physics.CheckCapsule(startLocation, startLocation + Vector3.up, .15f, Controller.MovementData.GroundLayer)) ?
                    0f : 1f;
            }
        }
        else
        {
            if (xMovement.Abs() <= 0f || zMovement.Abs() <= 0f)
            {
                xMovement = zMovement = 1f;
            }
        }
    }
Ejemplo n.º 6
0
        public static bool EqualsWithDelta(this float value, float other, float absolute = 1e-6f, float relative = 1e-6f)
        {
            if (float.IsNaN(value) ^ float.IsNaN(other))
            {
                return(false);
            }
            if (float.IsNaN(value) && float.IsNaN(other))
            {
                return(true);
            }
            if (float.IsInfinity(value) ^ float.IsInfinity(other))
            {
                return(false);
            }
            if (float.IsPositiveInfinity(value) && float.IsPositiveInfinity(other))
            {
                return(true);
            }
            if (float.IsNegativeInfinity(value) && float.IsNegativeInfinity(other))
            {
                return(true);
            }
            float abs = (value - other).Abs();

            if (abs < absolute)
            {
                return(true);
            }
            return(abs <= absolute.Max(relative * value.Abs().Max(other.Abs())));
        }
Ejemplo n.º 7
0
        internal static float GoTowardsWithin360(this float from, double to, double step)
        {
            var diff = to - from;

            if (diff.Abs() >= 180)
            {
                if (to.Abs() >= from.Abs())
                {
                    if (to < 0)
                    {
                        to += 360;
                    }
                    else
                    {
                        to -= 360;
                    }
                }
                else
                {
                    if (from < 0)
                    {
                        from += 360;
                    }
                    else
                    {
                        from -= 360;
                    }
                }
            }
            return(from.GoTowards(to, step));
        }
Ejemplo n.º 8
0
    public void UpdateAcceleration(float targetPosition, float currentPosition, float currentSpeed, float deltaTime)
    {
        var dD          = targetPosition - currentPosition;
        var maxAcc      = (((dD / deltaTime) - currentSpeed) / deltaTime).Abs();
        var standardAcc = dD.Sign() * MaxTargetAcceleration.Abs();

        //Si on ne va pas dans la bonne direction, on accelere dans la bonne
        if (currentSpeed.Sign() != dD.Sign())
        {
            CurrentAcceleration = standardAcc;
        }
        else
        {
            var   a     = -(currentSpeed * currentSpeed) / (2 * dD);
            float borne = standardAcc.Abs();
            if (a.Abs() >= borne)
            {
                //On ralentie
                CurrentAcceleration = a.Clamped(-borne, borne);
            }
            else
            {
                //On accelère
                CurrentAcceleration = standardAcc;
            }
        }

        //On clamp l'acceleration pour etre certain de ne pas dépasser la cible en 1 frame
        CurrentAcceleration = CurrentAcceleration.Clamped(-maxAcc, maxAcc);
    }
        /// <summary>
        /// Function to return a formatted string containing the memory amount.
        /// </summary>
        /// <param name="amount">Amount of memory in bytes to format.</param>
        /// <returns>A string containing the formatted amount of memory.</returns>
        /// <remarks>
        /// This overload is like the <see cref="FormatMemory(int)"/> method, only it will return the value with floating point formatting. e.g: "3.25 MB" instead of "3.0 MB"
        /// </remarks>
        public static string FormatMemory(this float amount)
        {
            double scale = amount.Abs() / 1125899906842624.0;

            if (scale >= 1.0)
            {
                return(GetCultureString(scale >= 1.0 ? scale : amount, Resources.GOR_UNIT_MEM_PB));
            }

            scale = amount / 1099511627776.0;

            if (scale >= 1.0)
            {
                return(GetCultureString(scale >= 1.0 ? scale : amount, Resources.GOR_UNIT_MEM_TB));
            }

            scale = amount / 1073741824.0;

            if (scale >= 1.0)
            {
                return(GetCultureString(scale >= 1.0 ? scale : amount, Resources.GOR_UNIT_MEM_GB));
            }

            scale = amount / 1048576.0;

            if (scale >= 1.0)
            {
                return(GetCultureString(scale >= 1.0 ? scale : amount, Resources.GOR_UNIT_MEM_MB));
            }

            scale = amount / 1024.0;

            return(GetCultureString(scale >= 1.0 ? scale : amount, scale >= 1.0 ? Resources.GOR_UNIT_MEM_KB : Resources.GOR_UNIT_MEM_BYTES, false));
        }
Ejemplo n.º 10
0
        public void Abst_ShouldReturnAbsoluteValues()
        {
            // Arrange
            sbyte   aByte    = -10;
            short   aShort   = -20;
            int     aInt     = -30;
            long    aLong    = -40;
            float   aFloat   = -50.0F;
            double  aDouble  = -60.0;
            decimal aDecimal = (decimal) - 70.0;


            // Act

            short   absByte    = aByte.Abs();
            short   absShort   = aShort.Abs();
            int     absInt     = aInt.Abs();
            long    absLong    = aLong.Abs();
            float   absFloat   = aFloat.Abs();
            double  absDouble  = aDouble.Abs();
            decimal absDecimal = aDecimal.Abs();

            // Assert
            Assert.Equal(10, absByte);
            Assert.Equal(20, absShort);
            Assert.Equal(30, absInt);
            Assert.Equal(40, absLong);
            Assert.Equal(50, absFloat);
            Assert.Equal(60, absDouble);
            Assert.Equal(70, absDecimal);
        }
Ejemplo n.º 11
0
 public static bool IsCloseTo(this float self, float num)
 {
     if (self == num)
     {
         return(true);
     }
     return((self - num).Abs() / self.Abs().Max(num.Abs()) < 0.0001f);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// If limit is negative, return current.
        /// </summary>
        public static float UpperLimit(this float current, float limit)
        {
            if (limit < 0)
            {
                return(current);
            }

            return(current.Sign() * Mathf.Min(current.Abs(), limit));
        }
Ejemplo n.º 13
0
 // Update is called once per frame
 void Update()
 {
     if (m_target)
     {
         Vector3 toTarget      = m_target.position - m_turretObj.transform.position;
         float   angleToTarget = m_turretObj.transform.forward.GetDiffAngle2D(toTarget);
         float   angleToTurn   = angleToTarget.Sign() * Mathf.Min(angleToTarget.Abs(), m_rotationSpeed * Time.deltaTime);
         m_turretObj.transform.Rotate(Vector3.up, angleToTurn);
     }
 }
Ejemplo n.º 14
0
 public static float MoveTo(this float me, float towards, float byAmount)
 {
     if (me < towards)
     {
         me += byAmount.Abs();
         if (me > towards)
         {
             me = towards;
         }
     }
     else if (me > towards)
     {
         me -= byAmount.Abs();
         if (me < towards)
         {
             me = towards;
         }
     }
     return(me);
 }
Ejemplo n.º 15
0
    internal static float ValueFromSides(this float negativeSide, float positiveSide)
    {
        float v1 = negativeSide.Abs();
        float v2 = positiveSide.Abs();

        if (v1.Approx(v2))
        {
            return(0.0f);
        }
        return((double)v1 > (double)v2 ? -v1 : v2);
    }
Ejemplo n.º 16
0
        public static float ToCircleAngle(this float angle)
        {
            var angleSign = angle.Sign();
            var absAngle  = angle.Abs();

            while (absAngle >= Float.CIRCLE_ANGLE)
            {
                absAngle -= Float.CIRCLE_ANGLE;
            }

            return(absAngle * angleSign);
        }
Ejemplo n.º 17
0
 void FixedUpdate()
 {
     if (speed.Abs() > 0.1f)
     {
         agentBody.MovePosition(transform.position + (transform.forward * Time.fixedDeltaTime * speed));
         pickupCollider.enabled = false;
     }
     else
     {
         pickupCollider.enabled = true;
     }
 }
Ejemplo n.º 18
0
        private void FireBallFromPaddle()
        {
            if (!isOnPaddle || !IsVisible)
            {
                return;
            }

            isOnPaddle = false;
            float randomXSpeed = Randomizer.Current.Get(-0.15f, 0.15f);

            velocity = new Vector2D(randomXSpeed.Abs() < 0.01f ? 0.01f : randomXSpeed, StartBallSpeedY);
            fireBallSound.Play();
        }
Ejemplo n.º 19
0
    public static float Mod(this float value, float modulo)
    {
        if (modulo <= 0)
        {
            return(0);
        }

        if (value < 0)
        {
            value += Mathf.Ceil(value.Abs() / modulo) * modulo;
        }

        return(value % modulo);
    }
Ejemplo n.º 20
0
    void Update()
    {
        target = target.Clamp(min, max);
        offset = offset.TLerp(target, dampening);

                #if UNITY_ANDROID || UNITY_IOS
        if (enableTouchScrolling)
        {
            scrollVelocity += InputF.TouchVelocity(ScreenF.all).y *scrollSpeed;
        }
                #endif

        scrollVelocity += InputWrapper.GetAxis("Mouse ScrollWheel") * -scrollSpeed;



        target        += scrollVelocity * Time.deltaTime;
        scrollVelocity = scrollVelocity.TLerp(0, velocityDampening);

        foreach (Transform t in angles.Keys)
        {
            if (t != null)
            {
                Vector3 pos   = Vector3.zero;
                float   angle = (offset + angles[t]).Clamp(-355, 355);

                float absAngle = angle.Abs();
                t.localScale = Vector3.one * (1 + selectionGrow * (1 - absAngle / 355));

                /*
                 * if (absAngle < 5) {
                 *      if (selected != t) {
                 *              t.SetColor("_Color", Color.red);
                 *              if (selected != null) {
                 *                      selected.SetColor("_Color", Color.white);
                 *              }
                 *              selected = t;
                 *      }
                 *
                 * }
                 * //*/

                pos.y = scales.y * (float)System.Math.Sinh(angle * Mathf.Deg2Rad);
                pos.z = scales.z * (float)System.Math.Cosh(angle * Mathf.Deg2Rad);

                t.localPosition = pos;
            }
        }
    }
Ejemplo n.º 21
0
        private IEnumerator <object> WheelScrollingTask()
        {
            const int wheelScrollingSpeedFactor = 8;

            wheelScrollState = WheelScrollState.Stop;
            float totalScrollAmount = 0f;

            while (true)
            {
                yield return(null);

                var IsScrollingByMouseWheel =
                    !Frame.Input.IsMousePressed() &&
                    (Frame.Input.WasKeyPressed(Key.MouseWheelDown) || Frame.Input.WasKeyPressed(Key.MouseWheelUp)) && CanScroll;
                if (IsScrollingByMouseWheel)
                {
                    var newWheelScrollState = (WheelScrollState)Math.Sign(Frame.Input.WheelScrollAmount);
                    if (newWheelScrollState != wheelScrollState)
                    {
                        totalScrollAmount = 0f;
                        wheelScrollState  = newWheelScrollState;
                    }
                    totalScrollAmount -= Frame.Input.WheelScrollAmount;
                }

                if (totalScrollAmount.Abs() >= 1f && wheelScrollState != WheelScrollState.Stop)
                {
                    StopScrolling();
                    var stepPerFrame       = totalScrollAmount * Task.Current.Delta * wheelScrollingSpeedFactor;
                    var prevScrollPosition = ScrollPosition;
                    ScrollPosition = Mathf.Clamp(ScrollPosition + stepPerFrame, MinScrollPosition, MaxScrollPosition);
                    if (ScrollPosition == MinScrollPosition || ScrollPosition == MaxScrollPosition)
                    {
                        totalScrollAmount = 0f;
                    }
                    else
                    {
                        // If scroll stopped in the middle, we need to round to upper int if we move down
                        // or to lower int if we move up.
                        ScrollPosition     = stepPerFrame > 0 ? ScrollPosition.Ceiling() : ScrollPosition.Floor();
                        totalScrollAmount += (prevScrollPosition - ScrollPosition);
                    }
                }
                else
                {
                    wheelScrollState = WheelScrollState.Stop;
                }
            }
        }
Ejemplo n.º 22
0
        private void OnBrightnessOffsetChanged(float oldValue, float newValue)
        {
            if (oldValue.IsCloseTo(newValue))
            {
                return;
            }

            // Normalize the value
            float value = newValue;

            if (value.Abs() > 100)
            {
                value %= 100;
            }

            brightnessOffset = value;
        }
Ejemplo n.º 23
0
        private void OnHueOffsetChanged(float oldValue, float newValue)
        {
            if (oldValue.IsCloseTo(newValue))
            {
                return;
            }

            // Normalize the value
            float value = newValue;

            if (value.Abs() > 360)
            {
                value %= 360;
            }

            hueOffset = value;
        }
Ejemplo n.º 24
0
        public Animation(
            int[] frames,
            float frameStep,
            PlayMode playMode,
            int maxLoops      = 0,
            Action onFinished = null,
            Action onLoop     = null)
        {
            _frames = frames;
            _initialDelayPerFrame = frameStep.Abs() / _defaultFrameRate;
            _initialMaxLoops      = maxLoops.Abs();
            _initialPlayMode      = playMode;

            Frames     = new ReadOnlyCollection <int>(_frames);
            OnFinished = onFinished;
            OnLoop     = onLoop;
            ResetChanges();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Offsets the specified <see cref="Color"/> by a set of HSB (hue, Saturation, Brightness)
        /// values.
        /// </summary>
        /// <param name="color">
        /// The from <see cref="Color"/>.
        /// </param>
        /// <param name="hueOffset">
        /// The hue offset.
        /// </param>
        /// <param name="saturationOffset">
        /// The staturation offset.
        /// </param>
        /// <param name="brightnessOffset">
        /// The brightness offset.
        /// </param>
        /// <returns>
        /// The <see cref="Color"/> offsets form <paramref name="color"/> by a set of HSB
        /// (hue, Saturation, Brightness) values.
        /// </returns>
        public static Color Offset(
            Color color,
            float hueOffset,
            float saturationOffset,
            float brightnessOffset)
        {
            HsbColor hsbColor = new HsbColor(color);

            // Normalize all HSB values
            if (hueOffset.Abs() > 360)
            {
                hueOffset %= 360;
            }
            if (hueOffset.IsLessThan(0))
            {
                hueOffset += 360;
            }

            if (saturationOffset.Abs() > 100)
            {
                saturationOffset %= 100;
            }
            if (saturationOffset.IsLessThan(0))
            {
                saturationOffset += 100;
            }

            if (brightnessOffset.Abs() > 100)
            {
                brightnessOffset %= 100;
            }
            if (brightnessOffset.IsLessThan(0))
            {
                brightnessOffset += 100;
            }

            HsbColor destinationColor = hsbColor.Offset(
                hueOffset,
                saturationOffset,
                brightnessOffset);

            return((Color)destinationColor);
        }
Ejemplo n.º 26
0
 private IEnumerator <object> InertialScrollingTask(float velocity)
 {
     while (true)
     {
         var   delta   = Task.Current.Delta;
         float damping = InertialScrollingDamping * (ScrollPosition.InRange(MinScrollPosition, MaxScrollPosition) ? 1 : 10);
         velocity -= velocity * damping * delta;
         if (
             velocity.Abs() < InertialScrollingStopVelocity ||
             ScrollPosition == MinScrollPosition - BounceZoneThickness ||
             ScrollPosition == MaxScrollPosition + BounceZoneThickness
             )
         {
             break;
         }
         // Round scrolling position to prevent blurring
         ScrollPosition = ClampScrollPositionWithinBounceZone((ScrollPosition + velocity * delta).Round());
         yield return(null);
     }
     scrollingTask = null;
 }
Ejemplo n.º 27
0
 private void FixedUpdate()
 {
     if (m_IsMovingHorizontally)
     {
         return;
     }
     if (IsClosed)
     {
         m_StartMoveDelta = m_OpeningDelta;
     }
     else if (IsOpen)
     {
         m_StartMoveDelta = m_ClosingingDelta;
         // vertical movement fading out when a finger is released
         if (m_CurMoveSpeed.Abs() > 0.1f)
         {
             m_CurMoveSpeed -= m_FadingSpeed * m_CurMoveSpeed;
             return;
         }
     }
     m_CurMoveSpeed = 0;
 }
Ejemplo n.º 28
0
    void Update()
    {
        Vector3 waypoint = GetCurrentWaypoint().position;
        Vector3 position = transform.position;

        float targetAngle  = position.AngleToPoint(waypoint).Mod(360);
        float currentAngle = graphics.transform.rotation.eulerAngles.y.Mod(360);
        float difference   = (targetAngle - currentAngle).Mod(360);

        if (difference.Abs() > rotationSpeed / 2f && !isLookingAtWaypoint)
        {
            //Debug.Log("Rotate " + targetAngle);
            bool negative = (difference > 180);

            float step = rotationSpeed * Time.deltaTime;
            step = step <= difference ? negative ? -step : step : difference;
            graphics.transform.rotation = Quaternion.Euler(0, graphics.transform.rotation.eulerAngles.y + step, 0);
        }
        else
        {
            if (difference != 0)
            {
                isLookingAtWaypoint         = true;
                graphics.transform.rotation = Quaternion.Euler(0, targetAngle, 0);
            }

            //Debug.Log("Move");
            float step = movementSpeed * Time.deltaTime;
            transform.position = Vector3.MoveTowards(transform.position, waypoint, step);
        }

        CheckMoveNext(position, waypoint);


        fov.SetOrigin(originPoint.position);
        fov.SetAimDirection(focalPoint.position - originPoint.position);
        RaycastCheck();
    }
Ejemplo n.º 29
0
        public bool Check(Collider col, float off, bool vertical, out Vector2 amt)
        {
            amt = default;

            if (off == 0)
            {
                return(false);
            }

            var unit = vertical ? Vector2.UnitY : Vector2.UnitX;
            var len  = (vertical ? col.Height : col.Width) / 2f;
            var norm = unit * off.Sign();
            var dist = len + off.Abs();

            if (Map.CastRay(col.Center, norm, dist, out var hit))
            {
                var dpt = hit.Depth;
                amt = dpt * norm;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 30
0
        public static Vector3 EulerAngle(this Quaternion q)
        {
            float sin   = 2.0f * (q.W * q.X + q.Y * q.Z);
            float cos   = 1.0f - 2.0f * (q.X * q.X + q.Y * q.Y);
            float roll  = ( float )Math.Atan2(sin, cos);
            float sinP  = 2 * (q.W * q.Y - q.Z * q.X);
            float pitch = 0;

            if (sinP.Abs( ) >= 1)
            {
                float p = ( float )(Math.PI / 2.0);
                pitch = Copysign(p, sinP);
            }
            else
            {
                pitch = ( float )Math.Asin(sinP);
            }
            float sinY = 2.0f * (q.W * q.Z + q.X * q.Y);
            float cosY = 1.0f - 2.0f * (q.Y * q.Y + q.Z * q.Z);
            float yaw  = ( float )Math.Atan2(sinY, cosY);

            return(new Vector3(roll.Deg( ), pitch.Deg( ), yaw.Deg( )));
        }