| | 1 | | using MainScripts.DCL.WebPlugin; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.HUD.Common |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Attaching this component to a scroll rect to apply the scroll sensitivity based on the os based stored sensitivi |
| | 10 | | /// </summary> |
| | 11 | | [RequireComponent(typeof(ScrollRect))] |
| | 12 | | public class ScrollRectSensitivityHandler : MonoBehaviour |
| | 13 | | { |
| | 14 | | private const float WINDOWS_SENSITIVITY_MULTIPLIER = 4.5f; |
| | 15 | | private const float MAC_SENSITIVITY_MULTIPLIER = 1.5f; |
| | 16 | | private const float LINUX_SENSITIVITY_MULTIPLIER = 1.125f; |
| | 17 | | private const float DEFAULT_SENSITIVITY_MULTIPLIER = 1.32f; |
| | 18 | |
|
| | 19 | | private ScrollRect myScrollRect; |
| | 20 | | private float defaultSens; |
| | 21 | |
|
| | 22 | | private void Awake() |
| | 23 | | { |
| 650 | 24 | | myScrollRect = GetComponent<ScrollRect>(); |
| 650 | 25 | | defaultSens = myScrollRect.scrollSensitivity; |
| 650 | 26 | | SetScrollRectSensitivity(); |
| 650 | 27 | | } |
| | 28 | |
|
| | 29 | | private void SetScrollRectSensitivity() |
| | 30 | | { |
| 650 | 31 | | float scrollSensitivity = defaultSens * GetScrollMultiplier(); |
| 650 | 32 | | myScrollRect.scrollSensitivity = scrollSensitivity; |
| 650 | 33 | | } |
| | 34 | |
|
| | 35 | | private float GetScrollMultiplier() |
| | 36 | | { |
| 650 | 37 | | OperatingSystemFamily currentOperatingSystem = GetCurrentOperatingSystem(); |
| | 38 | |
|
| | 39 | | switch (currentOperatingSystem) |
| | 40 | | { |
| | 41 | | case OperatingSystemFamily.Windows: |
| 0 | 42 | | return WINDOWS_SENSITIVITY_MULTIPLIER; |
| | 43 | | case OperatingSystemFamily.Linux: |
| 650 | 44 | | return LINUX_SENSITIVITY_MULTIPLIER; |
| | 45 | | case OperatingSystemFamily.MacOSX: |
| 0 | 46 | | return MAC_SENSITIVITY_MULTIPLIER; |
| | 47 | | default: |
| 0 | 48 | | return DEFAULT_SENSITIVITY_MULTIPLIER; |
| | 49 | | } |
| | 50 | | } |
| | 51 | |
|
| | 52 | | private OperatingSystemFamily GetCurrentOperatingSystem() { |
| | 53 | | #if UNITY_WEBGL |
| | 54 | | return ObtainOsFromWebGLAgent(); |
| | 55 | | #else |
| 650 | 56 | | return SystemInfo.operatingSystemFamily; |
| | 57 | | #endif |
| | 58 | | } |
| | 59 | |
|
| | 60 | | private OperatingSystemFamily ObtainOsFromWebGLAgent() { |
| 0 | 61 | | string agentInfo = WebGLPlugin.GetUserAgent(); |
| | 62 | |
|
| 0 | 63 | | if (agentInfo.Contains("windows", StringComparison.OrdinalIgnoreCase)) |
| 0 | 64 | | return OperatingSystemFamily.Windows; |
| | 65 | |
|
| 0 | 66 | | if (agentInfo.Contains("mac", StringComparison.OrdinalIgnoreCase) |
| | 67 | | || agentInfo.Contains("osx", StringComparison.OrdinalIgnoreCase) |
| | 68 | | || agentInfo.Contains("os x", StringComparison.OrdinalIgnoreCase)) |
| 0 | 69 | | return OperatingSystemFamily.MacOSX; |
| | 70 | |
|
| 0 | 71 | | if (agentInfo.Contains("linux", StringComparison.OrdinalIgnoreCase)) |
| 0 | 72 | | return OperatingSystemFamily.Linux; |
| | 73 | |
|
| 0 | 74 | | return OperatingSystemFamily.Other; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | } |
| | 78 | | } |