< Summary

Class:ListVariable_Legacy[T]
Assembly:ScriptableObjects
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ScriptableObject/Variables/ListVariable_Legacy.cs
Covered lines:2
Uncovered lines:30
Coverable lines:32
Total lines:79
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/ScriptableObject/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    public delegate void Removed(T removedValue);
 8
 9    private event Added OnAddedElementValue;
 10    private event Removed OnRemovedElementValue;
 11
 012    public virtual event Added OnAdded { add => OnAddedElementValue += value; remove => OnAddedElementValue -= value; }
 13
 014    public virtual event Removed OnRemoved { add => OnRemovedElementValue += value; remove => OnRemovedElementValue -= v
 15
 016    [SerializeField] protected List<T> list = new List<T>();
 17
 18    public void Add(T newValue)
 19    {
 120        list.Add(newValue);
 121        OnAddedElementValue?.Invoke(newValue);
 022    }
 23
 24    public void Add(T[] newValues)
 25    {
 026        int count = newValues.Length;
 027        for (int i = 0; i < count; ++i)
 28        {
 029            Add(newValues[i]);
 30        }
 031    }
 32
 33    public void Remove(T value)
 34    {
 035        if (!list.Contains(value))
 036            return;
 37
 038        list.Remove(value);
 039        OnRemovedElementValue?.Invoke(value);
 040    }
 41
 42    public void Remove(T[] values)
 43    {
 044        int count = values.Length;
 045        for (int i = 0; i < count; ++i)
 46        {
 047            Remove(values[i]);
 48        }
 049    }
 50
 051    public T Get(int index) { return list.Count >= index + 1 ? list[index] : default(T); }
 52
 053    public List<T> GetList() { return list; }
 54
 55    public void Clear()
 56    {
 057        for (int i = 0; i < list.Count; i++)
 58        {
 059            OnRemovedElementValue?.Invoke(list[i]);
 60        }
 61
 062        list.Clear();
 063    }
 64
 65#if UNITY_EDITOR
 66    private void OnEnable()
 67    {
 068        Application.quitting -= CleanUp;
 069        Application.quitting += CleanUp;
 070    }
 71
 72    private void CleanUp()
 73    {
 074        Application.quitting -= CleanUp;
 075        if (UnityEditor.AssetDatabase.Contains(this)) //It could happen that the base variable has been created in runti
 076            Resources.UnloadAsset(this);
 077    }
 78#endif
 79}