From 30fbb2afb6ce83812a1ae7ddf5c16650874e13ca Mon Sep 17 00:00:00 2001 From: tverona1 Date: Sun, 8 Sep 2019 17:54:38 -0700 Subject: [PATCH] Accelerate scroll speed over time This change accelerates scroll speed of the grid view over time, so make it faster to scroll through large content. --- Assets/Resources/OVRBuildConfig.asset | 2 +- Assets/Scripts/ScrollRectOverride.cs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Assets/Resources/OVRBuildConfig.asset b/Assets/Resources/OVRBuildConfig.asset index f2d36f8..cf5cd6c 100644 --- a/Assets/Resources/OVRBuildConfig.asset +++ b/Assets/Resources/OVRBuildConfig.asset @@ -12,6 +12,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 20553fac56ec59645857c0732b787431, type: 3} m_Name: OVRBuildConfig m_EditorClassIdentifier: - androidSDKPath: C:\Users\tvero\AppData\Local\Android\Sdk + androidSDKPath: gradlePath: jdkPath: diff --git a/Assets/Scripts/ScrollRectOverride.cs b/Assets/Scripts/ScrollRectOverride.cs index dc9e3b1..be35277 100644 --- a/Assets/Scripts/ScrollRectOverride.cs +++ b/Assets/Scripts/ScrollRectOverride.cs @@ -9,7 +9,17 @@ namespace QuestAppLauncher public class ScrollRectOverride : ScrollRect, IMoveHandler, IPointerClickHandler, IScrollHandler { // Scrolling speed multiplier - private const float speedMultiplier = 15f; + private const float SpeedMultiplier = 15f; + + // Maximum speed multiplier + private const float MaxSpeedMultiplier = 150f; + + // Speed multiplier increase percentage per frame + // How the value is calculated: We want to increase from 15 -> 150 in ~2 sec. At 90Hz, that's ~180 frames. So 150=15*(x)^180. + private const float SpeedMultiplierIncrease = 1.0128f; + + // Last frame's speed multiplier + private float lastSpeedMultiplier = 0f; // Height of a single cell in the grid private float cellHeight = 0f; @@ -89,7 +99,8 @@ namespace QuestAppLauncher if (moveVector.y == 0) { - // No y-movement, so return + // No y-movement, so return. Also reset the speed multiplier + this.lastSpeedMultiplier = 0; return; } @@ -97,11 +108,13 @@ namespace QuestAppLauncher // and map this to a fraction of the total viewport size: // moveVector.y: The thumbstick vertical position normalized to [-1,1]. // Time.deltaTime: The time delta since last frame - // speedMultiplier: Just a multiplier to get a good scrolling speed. + // speedMultiplier: Just a multiplier to get a good scrolling speed. Increase over time to speed up scrolling. // So, moveVector.y * Time.deltaTime * speedMultiplier = the amount to scroll in "units" // proportional to thumbstick position since last frame. // this.cellHeight / this.content.sizeDelta.y = cell height / total content height. + float speedMultiplier = Mathf.Clamp(this.lastSpeedMultiplier * SpeedMultiplierIncrease, SpeedMultiplier, MaxSpeedMultiplier); float verticalIncrement = moveVector.y * Time.deltaTime * speedMultiplier * this.cellHeight / this.content.sizeDelta.y; + this.lastSpeedMultiplier = speedMultiplier; this.verticalNormalizedPosition = Mathf.Clamp01(this.verticalNormalizedPosition + verticalIncrement); }