< Summary

Class:DCL.UpdateDispatcher
Assembly:UpdateEventHandler
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/UpdateEventHandler/UpdateDispatcher.cs
Covered lines:41
Uncovered lines:5
Coverable lines:46
Total lines:113
Line coverage:89.1% (41 of 46)
Covered branches:0
Total branches:0
Covered methods:13
Total methods:13
Method coverage:100% (13 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UpdateEventCollection()0%110100%
Add(...)0%2.032080%
Remove(...)0%3.013088.89%
Contains(...)0%3.033085.71%
UpdateDispatcher()0%110100%
Awake()0%110100%
EnsureEventType(...)0%220100%
ContainsEventType(...)0%3.213071.43%
Dispatch(...)0%220100%
Update()0%110100%
LateUpdate()0%110100%
FixedUpdate()0%110100%
OnDestroy()0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL
 6{
 7    public class UpdateDispatcher : MonoBehaviour
 8    {
 9        public class UpdateEventCollection
 10        {
 191211            public HashSet<Action> eventHashset = new HashSet<Action>();
 191212            public List<Action> eventList = new List<Action>();
 13
 14            public void Add(Action action)
 15            {
 217616                if (Contains(action))
 017                    return;
 18
 217619                eventList.Add(action);
 217620                eventHashset.Add(action);
 217621            }
 22
 23            public void Remove(Action action)
 24            {
 19925                int count = eventList.Count;
 108626                for (int i = 0; i < count; i++)
 27                {
 54328                    if (eventList[i] == action)
 29                    {
 19930                        eventList.RemoveAt(i);
 19931                        eventHashset.Remove(action);
 19932                        return;
 33                    }
 34                }
 035            }
 36
 37            public bool Contains(Action action)
 38            {
 217639                int count = eventList.Count;
 924640                for (int i = 0; i < count; i++)
 41                {
 244742                    if (eventList[i] == action)
 43                    {
 044                        return true;
 45                    }
 46                }
 217647                return false;
 48            }
 49
 50        }
 51
 47852        public Dictionary<IUpdateEventHandler.EventType, UpdateEventCollection> eventCollections = new Dictionary<IUpdat
 53
 54        void Awake()
 55        {
 47856            EnsureEventType(IUpdateEventHandler.EventType.Update);
 47857            EnsureEventType(IUpdateEventHandler.EventType.LateUpdate);
 47858            EnsureEventType(IUpdateEventHandler.EventType.FixedUpdate);
 47859            EnsureEventType(IUpdateEventHandler.EventType.OnDestroy);
 47860        }
 61
 62        void EnsureEventType(IUpdateEventHandler.EventType eventType)
 63        {
 191264            if (!ContainsEventType(eventType))
 65            {
 191266                eventCollections.Add(eventType, new UpdateEventCollection());
 67            }
 191268        }
 69
 70        private bool ContainsEventType(IUpdateEventHandler.EventType eventType)
 71        {
 956072            foreach (var key in eventCollections.Keys)
 73            {
 286874                if (key == eventType)
 75                {
 076                    return true;
 77                }
 78            }
 191279            return false;
 080        }
 81
 82        void Dispatch( IUpdateEventHandler.EventType eventType )
 83        {
 4201284            var list = eventCollections[eventType].eventList;
 4201285            int count = eventCollections[eventType].eventList.Count;
 86
 23640487            for ( int i = 0; i < count; i++ )
 88            {
 7619089                list[i].Invoke();
 90            }
 4201291        }
 92
 93        void Update()
 94        {
 1936695            Dispatch(IUpdateEventHandler.EventType.Update);
 1936696        }
 97
 98        void LateUpdate()
 99        {
 19366100            Dispatch(IUpdateEventHandler.EventType.LateUpdate);
 19366101        }
 102
 103        void FixedUpdate()
 104        {
 2802105            Dispatch(IUpdateEventHandler.EventType.FixedUpdate);
 2802106        }
 107
 108        private void OnDestroy()
 109        {
 478110            Dispatch(IUpdateEventHandler.EventType.OnDestroy);
 478111        }
 112    }
 113}