< Summary

Class:ScrollRectSensitivityHandler
Assembly:HUDCommon
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Common/ScrollRectSensitivityHandler.cs
Covered lines:9
Uncovered lines:11
Coverable lines:20
Total lines:75
Line coverage:45% (9 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
SetScrollRectSensitivity()0%110100%
GetScrollMultiplier()0%10.45040%
GetCurrentOperatingSystem()0%110100%
ObtainOsFromWebGLAgent()0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Common/ScrollRectSensitivityHandler.cs

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.UI;
 3using MainScripts.DCL.WebPlugin;
 4using 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))]
 10public 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    {
 23123        myScrollRect = GetComponent<ScrollRect>();
 23124        defaultSens = myScrollRect.scrollSensitivity;
 23125        SetScrollRectSensitivity();
 23126    }
 27
 28    private void SetScrollRectSensitivity()
 29    {
 23130        myScrollRect.scrollSensitivity = defaultSens * GetScrollMultiplier();
 23131    }
 32
 33    private float GetScrollMultiplier() {
 23134        switch (GetCurrentOperatingSystem())
 35        {
 36            case OperatingSystemFamily.Windows:
 037                return WINDOWS_SENSITIVITY_MULTIPLIER;
 38            case OperatingSystemFamily.Linux:
 23139                return LINUX_SENSITIVITY_MULTIPLIER;
 40            case OperatingSystemFamily.MacOSX:
 041                return MAC_SENSITIVITY_MULTIPLIER;
 42            default:
 043                return DEFAULT_SENSITIVITY_MULTIPLIER;
 44        }
 45    }
 46
 47    private OperatingSystemFamily GetCurrentOperatingSystem() {
 48#if UNITY_WEBGL
 49        return ObtainOsFromWebGLAgent();
 50#else
 23151        return SystemInfo.operatingSystemFamily;
 52#endif
 53    }
 54
 55    private OperatingSystemFamily ObtainOsFromWebGLAgent() {
 056        String agentInfo = WebGLPlugin.GetUserAgent();
 057        if (agentInfo.ToLower().Contains("windows"))
 58        {
 059            return OperatingSystemFamily.Windows;
 60        }
 061        else if (agentInfo.ToLower().Contains("mac") || agentInfo.ToLower().Contains("osx") || agentInfo.ToLower().Conta
 62        {
 063            return OperatingSystemFamily.MacOSX;
 64        }
 065        else if (agentInfo.ToLower().Contains("linux"))
 66        {
 067            return OperatingSystemFamily.Linux;
 68        }
 69        else
 70        {
 071            return OperatingSystemFamily.Other;
 72        }
 73    }
 74
 75}