< Summary

Class:NotificationFactory
Assembly:NotificationHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationFactory.cs
Covered lines:11
Uncovered lines:4
Coverable lines:15
Total lines:68
Line coverage:73.3% (11 of 15)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EnsueFactoryDictionary()0%440100%
CreateNotificationFromType(...)0%64050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationFactory.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4public class NotificationFactory : ScriptableObject
 5{
 6    public enum Type
 7    {
 8        GENERIC,
 9        SCRIPTING_ERROR,
 10        COMMS_ERROR,
 11        AIRDROPPING,
 12        GENERIC_WITHOUT_BUTTON,
 13        CUSTOM,
 14        UI_HIDDEN,
 15        GRAPHIC_CARD_WARNING,
 16        WARNING
 17    }
 18
 19    [System.Serializable]
 20    public class Item
 21    {
 22        public Type type;
 23        public Notification prefab;
 24    }
 25
 26    public Item[] factoryList;
 27
 28    private Dictionary<Type, Item> factoryDict;
 29
 30    public void EnsueFactoryDictionary()
 31    {
 432        if (factoryDict == null)
 33        {
 134            factoryDict = new Dictionary<Type, Item>();
 35
 1836            for (int i = 0; i < factoryList.Length; i++)
 37            {
 838                Item item = factoryList[i];
 39
 840                if (!factoryDict.ContainsKey(item.type))
 41                {
 842                    factoryDict.Add(item.type, item);
 43                }
 44            }
 45        }
 446    }
 47
 48    public Notification CreateNotificationFromType(Type type, Transform parent = null)
 49    {
 450        EnsueFactoryDictionary();
 51
 452        if (!factoryDict.ContainsKey(type))
 53        {
 54#if UNITY_EDITOR
 055            Debug.LogError("Notification of type " + type + " can't be instantiated because it does not exist in the fac
 56#endif
 057            return null;
 58        }
 59
 460        if (factoryDict[type].prefab == null)
 61        {
 062            Debug.LogError("Prefab for type " + type + " is null!");
 063            return null;
 64        }
 65
 466        return parent == null ? Instantiate(factoryDict[type].prefab) : Instantiate(factoryDict[type].prefab, parent);
 67    }
 68}