public virtual void UpdateTransientSharpness(float newSharpness) { TransientSharpness = newSharpness; TransientSharpnessText.text = NiceVibrationsDemoHelpers.Round(newSharpness, 2).ToString(); SharpnessProgressBar.UpdateBar(TransientSharpness, 0f, 1f); TargetCurve.UpdateCurve(TransientIntensity, TransientSharpness); }
public virtual void UpdateContinuousIntensity(float newIntensity) { ContinuousIntensity = newIntensity; IntensityProgressBar.UpdateBar(ContinuousIntensity, 0f, 1f); ContinuousIntensityText.text = NiceVibrationsDemoHelpers.Round(newIntensity, 2).ToString(); UpdateContinuous(); }
public virtual void UpdateContinuousSharpness(float newSharpness) { ContinuousSharpness = newSharpness; SharpnessProgressBar.UpdateBar(ContinuousSharpness, 0f, 1f); ContinuousSharpnessText.text = NiceVibrationsDemoHelpers.Round(newSharpness, 2).ToString(); UpdateContinuous(); }
protected virtual void DrawCurve() { _startPosition = StartPoint.transform.position; _startPosition.z -= 0.1f; _endPosition = EndPoint.transform.position; _endPosition.z -= 0.1f; Points.Clear(); for (int i = 0; i < PointsCount; i++) { float t = NiceVibrationsDemoHelpers.Remap(i, 0, PointsCount, 0f, 1f); float sinValue = MMSignal.GetValue(t, MMSignal.SignalType.Sine, 1f, AmplitudeFactor, Period, 0f, false); float triangleValue = MMSignal.GetValue(t, MMSignal.SignalType.Triangle, 1f, AmplitudeFactor, Period, 0f, false); if (Move) { sinValue = MMSignal.GetValue(t + Time.time * MovementSpeed, MMSignal.SignalType.Sine, 1f, AmplitudeFactor, Period, 0f, false); triangleValue = MMSignal.GetValue(t + Time.time * MovementSpeed, MMSignal.SignalType.Triangle, 1f, AmplitudeFactor, Period, 0f, false); } float finalValue = Mathf.Lerp(sinValue, triangleValue, Sharpness); _workPoint.x = Mathf.Lerp(_startPosition.x, _endPosition.x, t); _workPoint.y = finalValue * Intensity + _startPosition.y; _workPoint.z = _startPosition.z; Points.Add(_workPoint); } _targetLineRenderer.positionCount = PointsCount; _targetLineRenderer.SetPositions(Points.ToArray()); }
protected virtual void UpdateContinuousDemo() { if (_timeLeft > 0f) { ContinuousProgressBar.UpdateBar(_timeLeft, 0f, ContinuousDuration); _timeLeft -= Time.deltaTime; Logo.Shaking = true; TargetCurve.Move = true; Logo.Intensity = NiceVibrationsDemoHelpers.Remap(ContinuousIntensity, 0f, 1f, 1f, 8f); Logo.Sharpness = NiceVibrationsDemoHelpers.Remap(ContinuousSharpness, 0f, 1f, 10f, 25f); } else { ContinuousProgressBar.UpdateBar(0f, 0f, ContinuousDuration); Logo.Shaking = false; TargetCurve.Move = false; if (_continuousActive) { MMVibrationManager.StopContinuousHaptic(true); OnHapticsStopped(); } } if ((_sharpnessLastFrame != ContinuousSharpness) || (_intensityLastFrame != ContinuousIntensity)) { TargetCurve.UpdateCurve(ContinuousIntensity, ContinuousSharpness); } _intensityLastFrame = ContinuousIntensity; _sharpnessLastFrame = ContinuousSharpness; }
/// <summary> /// Plays a continuous haptic of the specified intensity, sharpness and duration /// </summary> /// <param name="intensity"></param> /// <param name="sharpness"></param> /// <param name="duration"></param> public static void ContinuousHaptic(float intensity, float sharpness, float duration, HapticTypes fallbackOldiOS = HapticTypes.None, MonoBehaviour mono = null) { if (!_vibrationsActive) { return; } DebugLog("[MMVibrationManager] Continuous Haptic"); if (Android()) { intensity = NiceVibrationsDemoHelpers.Remap(intensity, 0f, 1f, 0, 255); MMNVAndroid.AndroidVibrate((long)(duration * 1000), (int)(intensity)); } else if (iOS()) { if (iOSVersion >= 13) { MMNViOSCoreHaptics.PlayContinuousHapticPattern(intensity, sharpness, duration, mono); } else { MMNViOS.iOSTriggerHaptics(fallbackOldiOS); } } }
protected virtual void Update() { if (!Active) { Dragging = false; _image.color = InactiveColor; return; } else { _image.color = ActiveColor; } if (!Dragging) { return; } Vector2 v1 = Vector2.down; Vector2 v2 = this.transform.position - GetWorldPosition(_pointerEventData.position); float angle = Vector2.SignedAngle(v1, v2); angle = Mathf.Clamp(angle, -130f, 130f); _rotation.z = NiceVibrationsDemoHelpers.Remap(angle, -130f, 130f, MaximumAngle, MinimumAngle); _rectTransform.SetPositionAndRotation(this.transform.position, Quaternion.Euler(_rotation)); Value = NiceVibrationsDemoHelpers.Remap(angle, -130f, 130f, 1f, 0f); }
public virtual void SetValue(float value) { SetRotation(MinimumAngle); Value = value; float angle = NiceVibrationsDemoHelpers.Remap(value, 0f, 1f, MinimumAngle, MaximumAngle); _rotation.z = angle; _rectTransform.SetPositionAndRotation(this.transform.position, Quaternion.Euler(_rotation)); }
protected virtual void Start() { _canvas = GetComponentInParent <Canvas>(); float horizontalF = (ContentZone.rect.width - 2 * Padding) / (PrefabSize.x + Margin); float verticalF = (ContentZone.rect.height - 2 * Padding) / (PrefabSize.y + Margin); int horizontal = Mathf.FloorToInt(horizontalF); int vertical = Mathf.FloorToInt(verticalF); float centerH = (ContentZone.rect.width - (Padding * 2) - (horizontal * PrefabSize.x) - (horizontal - 1) * Margin) / 2f; float centerV = (ContentZone.rect.height - (Padding * 2) - (vertical * PrefabSize.x) - (vertical - 1) * Margin) / 2f; Buttons = new List <WobbleButton>(); for (int i = 0; i < horizontal; i++) { for (int j = 0; j < vertical; j++) { _position.x = centerH + Padding + PrefabSize.x / 2f + i * (PrefabSize.x + Margin); _position.y = centerV + Padding + PrefabSize.y / 2f + j * (PrefabSize.y + Margin); _position.z = 0f; WobbleButton button = Instantiate(WobbleButtonPrefab); button.transform.SetParent(ContentZone.transform); Buttons.Add(button); RectTransform rectTransform = button.GetComponent <RectTransform>(); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.zero; button.name = "WobbleButton" + i + j; button.transform.localScale = Vector3.one; rectTransform.anchoredPosition3D = _position; button.TargetCamera = ButtonCamera; button.Initialization(); } } int counter = 0; foreach (WobbleButton wbutton in Buttons) { float newPitch = NiceVibrationsDemoHelpers.Remap(counter, 0f, Buttons.Count, 0.3f, 1f); wbutton.SetPitch(newPitch); counter++; } }
protected virtual void UpdateCar() { float targetSpeed = _carStarted ? NiceVibrationsDemoHelpers.Remap(Knob.Value, MinimumKnobValue, 1f, 0f, 1f) : 0f; CarSpeed = Mathf.Lerp(CarSpeed, targetSpeed, Time.deltaTime * 1f); CarEngineAudioSource.volume = CarSpeed; CarEngineAudioSource.pitch = NiceVibrationsDemoHelpers.Remap(CarSpeed, 0f, 1f, 0.5f, 1.25f); LeftWheel.Rotate(CarSpeed * Time.deltaTime * WheelRotationSpeed, Space.Self); RightWheel.Rotate(CarSpeed * Time.deltaTime * WheelRotationSpeed, Space.Self); _carPosition.x = _initialCarPosition.x + 0f; _carPosition.y = _initialCarPosition.y + 10 * CarSpeed * Mathf.PerlinNoise(Time.time * 10f, CarSpeed * 10f); _carPosition.z = 0f; CarBody.localPosition = _carPosition; }
/// <summary> /// Converts a AHAP string into a MMNVAndroidWaveForm /// </summary> /// <param name="AHAPasString"></param> /// <returns></returns> public static MMNVAndroidWaveForm AHAPtoAndroidWaveForm(string AHAPasString) { MMNVAHAP ahap = JsonConvert.DeserializeObject <MMNVAHAP>(AHAPasString); List <long> patterns = new List <long>(); List <int> amplitudes = new List <int>(); double totalTimeStamp = 0f; double previousTimeStamp = 0f; foreach (MMNVAHAPPattern pattern in ahap.Pattern) { if (pattern.ParameterCurve != null) { if (pattern.ParameterCurve.ParameterID == "HapticIntensityControl") { foreach (MMNVAHAPParameterCurveControlPoint point in pattern.ParameterCurve.ParameterCurveControlPoints) { double timeStamp = point.Time - previousTimeStamp; totalTimeStamp += timeStamp; patterns.Add((long)(timeStamp * 1000)); float originalIntensity = (float)point.ParameterValue; int intensity = (int)NiceVibrationsDemoHelpers.Remap(originalIntensity, 0f, 1f, 0f, 255f); amplitudes.Add(intensity); previousTimeStamp = point.Time; } } } } MMNVAndroidWaveForm returnWaveForm = new MMNVAndroidWaveForm(); returnWaveForm.Amplitudes = amplitudes.ToArray(); returnWaveForm.Pattern = patterns.ToArray(); return(returnWaveForm); }
/// <summary> /// Plays a transient haptic, a single, short haptic feedback, of the specified intensity and sharpness /// </summary> /// <param name="intensity"></param> /// <param name="sharpness"></param> public static void TransientHaptic(float intensity, float sharpness) { if (!_vibrationsActive) { return; } DebugLog("[MMVibrationManager] Transient Haptic"); if (Android()) { intensity = NiceVibrationsDemoHelpers.Remap(intensity, 0f, 1f, 0, 255); MMNVAndroid.AndroidVibrate(100, (int)(intensity)); } else if (iOS()) { if (iOSVersion >= 13) { MMNViOSCoreHaptics.PlayTransientHapticPattern(intensity, sharpness); } else { if (intensity < 0.3f) { MMNViOS.iOSTriggerHaptics(HapticTypes.LightImpact); } else if ((intensity >= 0.3f) && (intensity < 0.6f)) { MMNViOS.iOSTriggerHaptics(HapticTypes.MediumImpact); } else { MMNViOS.iOSTriggerHaptics(HapticTypes.HeavyImpact); } } } }
protected virtual IEnumerator TransitionCoroutine(int previous, int next, bool goingRight) { _position.y = Pages[previous].localPosition.y; _position.z = Pages[previous].localPosition.z; foreach (RectTransform page in Pages) { _position.x = 1200f; page.localPosition = _position; } Pages[next].gameObject.SetActive(true); float timeSpent = 0f; while (timeSpent < PageTransitionDuration) { if (goingRight) { _position.x = Mathf.Lerp(0f, -1200f, TransitionCurve.Evaluate(NiceVibrationsDemoHelpers.Remap(timeSpent, 0f, PageTransitionDuration, 0f, 1f))); Pages[previous].localPosition = _position; _position.x = Mathf.Lerp(1200f, 0f, TransitionCurve.Evaluate(NiceVibrationsDemoHelpers.Remap(timeSpent, 0f, PageTransitionDuration, 0f, 1f))); Pages[next].localPosition = _position; } else { _position.x = Mathf.Lerp(0f, 1200f, TransitionCurve.Evaluate(NiceVibrationsDemoHelpers.Remap(timeSpent, 0f, PageTransitionDuration, 0f, 1f))); Pages[previous].localPosition = _position; _position.x = Mathf.Lerp(-1200f, 0f, TransitionCurve.Evaluate(NiceVibrationsDemoHelpers.Remap(timeSpent, 0f, PageTransitionDuration, 0f, 1f))); Pages[next].localPosition = _position; } timeSpent += Time.deltaTime; yield return(null); } Pages[previous].gameObject.SetActive(false); }
public virtual void UpdateContinuousDuration(float newDuration) { ContinuousDuration = newDuration; DurationProgressBar.UpdateBar(ContinuousDuration, 0f, 5f); ContinuousDurationText.text = NiceVibrationsDemoHelpers.Round(newDuration, 2).ToString(); }