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