< Summary

Class:ListVariable_Legacy[T]
Assembly:BaseVariable
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/ListVariable_Legacy.cs
Covered lines:2
Uncovered lines:30
Coverable lines:32
Total lines:80
Line coverage:6.2% (2 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnAdded(...)0%2100%
remove_OnAdded(...)0%2100%
add_OnRemoved(...)0%2100%
remove_OnRemoved(...)0%2100%
ListVariable_Legacy()0%2100%
Add(...)0%2.152066.67%
Add(...)0%6200%
Remove(...)0%12300%
Remove(...)0%6200%
Get(...)0%6200%
GetList()0%2100%
Clear()0%12300%
OnEnable()0%2100%
CleanUp()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/ListVariable_Legacy.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4public class ListVariable_Legacy<T> : ScriptableObject
 5{
 6    public delegate void Added(T addedValue);
 7
 8    public delegate void Removed(T removedValue);
 9
 10    private event Added OnAddedElementValue;
 11    private event Removed OnRemovedElementValue;
 12
 013    public virtual event Added OnAdded { add => OnAddedElementValue += value; remove => OnAddedElementValue -= value; }
 14
 015    public virtual event Removed OnRemoved { add => OnRemovedElementValue += value; remove => OnRemovedElementValue -= v
 16
 017    [SerializeField] protected List<T> list = new List<T>();
 18
 19    public void Add(T newValue)
 20    {
 121        list.Add(newValue);
 122        OnAddedElementValue?.Invoke(newValue);
 023    }
 24
 25    public void Add(T[] newValues)
 26    {
 027        int count = newValues.Length;
 028        for (int i = 0; i < count; ++i)
 29        {
 030            Add(newValues[i]);
 31        }
 032    }
 33
 34    public void Remove(T value)
 35    {
 036        if (!list.Contains(value))
 037            return;
 38
 039        list.Remove(value);
 040        OnRemovedElementValue?.Invoke(value);
 041    }
 42
 43    public void Remove(T[] values)
 44    {
 045        int count = values.Length;
 046        for (int i = 0; i < count; ++i)
 47        {
 048            Remove(values[i]);
 49        }
 050    }
 51
 052    public T Get(int index) { return list.Count >= index + 1 ? list[index] : default(T); }
 53
 054    public List<T> GetList() { return list; }
 55
 56    public void Clear()
 57    {
 058        for (int i = 0; i < list.Count; i++)
 59        {
 060            OnRemovedElementValue?.Invoke(list[i]);
 61        }
 62
 063        list.Clear();
 064    }
 65
 66#if UNITY_EDITOR
 67    private void OnEnable()
 68    {
 069        Application.quitting -= CleanUp;
 070        Application.quitting += CleanUp;
 071    }
 72
 73    private void CleanUp()
 74    {
 075        Application.quitting -= CleanUp;
 076        if (UnityEditor.AssetDatabase.Contains(this)) //It could happen that the base variable has been created in runti
 077            Resources.UnloadAsset(this);
 078    }
 79#endif
 80}