public static double RemapFromSeedDecimal(double min, double max, System.Random randomSeed) { double zeroToOneValue = randomSeed.NextDouble(); double minToMaxValue = ExtMathf.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
public static float RemapFromSeedDecimal(float min, float max, System.Random randomSeed) { float zeroToOneValue = (float)randomSeed.NextDouble(); float minToMaxValue = ExtMathf.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
/// <summary> /// here we have a min & max, we remap the random 0,1 value finded to this min&max /// warning: we cast it into an int at the end /// use: /// System.Random seed = ExtRandom.Seedrandom("hash"); /// int randomInt = ExtRandom.RemapFromSeed(0, 50, seed); /// </summary> public static int RemapFromSeed(double min, double max, System.Random randomSeed) { double zeroToOneValue = randomSeed.NextDouble(); int minToMaxValue = (int)ExtMathf.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
public float GetCurrentSpeedForwardClamped01() { float currentVelocity = entityController.GetActualAccelerationForward().magnitude; float velocityRemapped = ExtMathf.Remap(currentVelocity, 0, 10, 0, 1); //Debug.Log("velocity forward not mapped: " + currentVelocity); return(Mathf.Clamp01(velocityRemapped)); }
public float GetCurrentSpeedClamped01() { float currentVelocity = entityController.GetActualVelocity(); float velocityRemapped = ExtMathf.Remap(currentVelocity, 0, 10, 0, 1); //Debug.Log("velocity remapped: " + velocityRemapped + "(actual: " + currentVelocity + ")"); return(Mathf.Clamp01(velocityRemapped)); }
/// <summary> /// move up-down in the dolly /// </summary> private void InputDolly() { Vector2 dirInput = _cameraInput; if (Mathf.Abs(dirInput.y) >= _deadZoneVerti) { float remapedInput = ExtMathf.Remap(Mathf.Abs(dirInput.y), _deadZoneVerti, 1f, 0f, 1f); _followPercent -= _speedDolly * remapedInput * Mathf.Sign(dirInput.y) * Time.deltaTime; _followPercent = Mathf.Clamp(_followPercent, 0, 1f); } _follow.SetPercent(_followPercent); }
/// <summary> /// return a value from 0 to 1, representing the "player input", with rb acceleration /// </summary> /// <returns></returns> public float GetMagnitudeAcceleration() { float playerInput = entityAction.GetMagnitudeInput(); //TODO: a super lerp; //min: minAcceleration //max: speedMove //current: currentSpeedMove float remapCurrentSpeed = ExtMathf.Remap(currentSpeedMove, minAcceleration, speedMove, 0, 1); return(remapCurrentSpeed * playerInput); }
/// <summary> /// tel to zoom /// </summary> /// <param name="zoomRatio">between -1 and 1</param> public void InputZoom(float speedRatio = 1f) { if (Mathf.Abs(_trigerZoom) >= _deadZoneZoom) { float remapedInput = ExtMathf.Remap(Mathf.Abs(_trigerZoom), _deadZoneVerti, 1f, 0f, 1f); float localScaleAllAxis = _toScale.localScale.x; localScaleAllAxis += _speedZoom * remapedInput * speedRatio * Mathf.Sign(_trigerZoom) * Time.deltaTime; localScaleAllAxis = Mathf.Clamp(localScaleAllAxis, _minMaxZoom.x, _minMaxZoom.y); _toScale.localScale = new Vector3(localScaleAllAxis, localScaleAllAxis, localScaleAllAxis); SetAimPosition(); } }
/// <summary> /// rotate left-right /// </summary> private void InputRotate() { //start or continue ease rotate Vector2 dirInput = _cameraInput; //if margin turn is ok for HORIZ move if (Mathf.Abs(dirInput.x) >= _deadZoneHoriz) { _easeRotate.StartOrContinue(); float remapedInput = ExtMathf.Remap(Mathf.Abs(dirInput.x), _deadZoneHoriz, 1f, 0f, 1f) * Mathf.Sign(dirInput.x); _toRotate.Rotate(0, _easeRotate.EvaluateWithDeltaTime() * remapedInput, 0); } else { _easeRotate.BackToTime(); } }
public void CalculateEmptyCellIndexBasedOnPosition(float heightItem, float margin) { if (!IsDragging || HowManyCellAreDisplayed < 2 || FirstItem.y == 0 || LastItem.y == 0) { return; } float min = FirstItem.y + margin; float max = LastItem.y + heightItem + margin; float mousePosition = SetBetween(Event.current.mousePosition.y, min, max); int numberItem = HowManyCellAreDisplayed; float percent = 1 - ExtMathf.Remap(mousePosition, min, max, 0f, 1f); float indexPrecise = ExtMathf.Remap(percent, 0, 1, 0, numberItem); int index = Mathf.RoundToInt(indexPrecise - (1f / numberItem)); index = SetBetween(index, 0, numberItem); CurrentIndexShouldPointEmptyCell = index; }
public void DisplayRight() { if (!EditorPrefs.GetBool(UnityEssentialsPreferences.SHOW_PEEK_MENU, true)) { return; } float percent = EditorPrefs.GetFloat(UnityEssentialsPreferences.POSITION_IN_TOOLBAR, UnityEssentialsPreferences.DEFAULT_TOOLBAR_POSITION); if (percent <= 0.5f) { return; } Rect left = ToolbarExtender.GetRightRect(); percent = ExtMathf.Remap(percent, 0.5f, 1f, 0f, 1f); float width = (left.width - SIZE_SLIDER) / 1 * percent; GUILayout.Label("", GUILayout.MinWidth(0), GUILayout.Width(width)); #if UNITY_2018_3_OR_NEWER Rect finalRect = SetupLocalRect(width); AddRightClickBehavior(finalRect); #endif DisplayPeek(); }