< Summary

Class:DCL.IdleChecker
Assembly:IdleChecker
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/IdleChecker/IdleChecker.cs
Covered lines:25
Uncovered lines:9
Coverable lines:34
Total lines:81
Line coverage:73.5% (25 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
IdleChecker(...)0%110100%
Subscribe(...)0%2100%
Unsubscribe(...)0%2100%
Initialize()0%330100%
SetMaxTime(...)0%2100%
GetMaxTime()0%2100%
Update()0%5.935066.67%
SetIdleState(...)0%220100%
IdleCheck()0%110100%
isIdle()0%2100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/IdleChecker/IdleChecker.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL
 5{
 6    public class IdleChecker : IIdleChecker
 7    {
 6308        Vector3 lastMouseCoordinate = Vector3.zero;
 6309        private int maxTime = 60;
 10        private float lastActivityTime = 0.0f;
 11        private bool idle = false;
 12        private IUpdateEventHandler updateEventHandler;
 13        public event IIdleChecker.ChangeStatus OnChangeStatus;
 14
 015        public void Subscribe(IIdleChecker.ChangeStatus callback) { OnChangeStatus += callback; }
 16
 017        public void Unsubscribe(IIdleChecker.ChangeStatus callback) { OnChangeStatus -= callback; }
 18
 63019        public IdleChecker (IUpdateEventHandler eventHandler = null)
 20        {
 63021            this.updateEventHandler = eventHandler;
 63022        }
 23
 24        public void Initialize()
 25        {
 63026            lastActivityTime = Time.time;
 27
 63028            if (this.updateEventHandler == null)
 63029                this.updateEventHandler = DCL.Environment.i.platform.updateEventHandler;
 30
 63031            updateEventHandler?.AddListener(IUpdateEventHandler.EventType.Update, Update);
 62932        }
 33
 034        public void SetMaxTime(int time) { maxTime = time; }
 35
 036        public int GetMaxTime() { return maxTime; }
 37
 38        public void Update()
 39        {
 699440            Vector3 mouseDelta = Input.mousePosition - lastMouseCoordinate;
 41
 699442            bool mouseMoved = mouseDelta.sqrMagnitude > 0.0001f;
 43
 699444            if (Input.anyKey || mouseMoved)
 45            {
 046                lastActivityTime = Time.time;
 47            }
 48
 699449            lastMouseCoordinate = Input.mousePosition;
 50
 699451            if (idle)
 52            {
 053                if (!IdleCheck())
 054                    SetIdleState(false);
 055            }
 56            else
 57            {
 699458                if (IdleCheck())
 159                    SetIdleState(true);
 60            }
 699461        }
 62
 63        private void SetIdleState(bool status)
 64        {
 165            idle = status;
 66
 167            OnChangeStatus?.Invoke(idle);
 68
 169            DCL.Interface.WebInterface.ReportIdleStateChanged(idle);
 170        }
 71
 699472        private bool IdleCheck() { return Time.time - lastActivityTime > maxTime; }
 73
 074        public bool isIdle() { return idle; }
 75
 76        public void Dispose()
 77        {
 62978            updateEventHandler?.RemoveListener(IUpdateEventHandler.EventType.Update, Update);
 62979        }
 80    }
 81}