< Summary

Class:ListView[T]
Assembly:BuilderInWorldCommon
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/BuilderInWorldCommon/ListView.cs
Covered lines:14
Uncovered lines:8
Coverable lines:22
Total lines:63
Line coverage:63.6% (14 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ListView()0%110100%
SetContent(...)0%110100%
RefreshDisplay()0%110100%
AddAdapters()0%2100%
RemoveAdapters()0%42600%
CheckEmptyContent()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/BuilderInWorldCommon/ListView.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5/// <summary>
 6///  This class is a generic implementantion for a view that list items. It should be use when you want to list items in
 7///
 8///  The general logic of this class is that it will instanciate one adapter per one item in the list you set. The adapt
 9///  while this class will manage the availability of the adapters. This way you can switch adapter to show them in dife
 10///
 11///  You will need to implement at least one adapter in the AddAdapters function and instanciated it as a children of th
 12///
 13///  You are required to implement the AddAdapters with your own adapter logic, this is done in order to mantain it more
 14/// </summary>
 15public class ListView<T> : MonoBehaviour
 16{
 17
 18    public Transform contentPanelTransform;
 19    public GameObject emptyContentMark;
 20
 26321    protected List<T> contentList = new List<T>();
 22    public void SetContent(List<T> content)
 23    {
 2924        contentList = content;
 2925        RefreshDisplay();
 2926    }
 27
 28    public virtual void RefreshDisplay()
 29    {
 3630        RemoveAdapters();
 3631        AddAdapters();
 3632        CheckEmptyContent();
 3633    }
 34
 035    public virtual void AddAdapters() { }
 36
 37    public virtual void RemoveAdapters()
 38    {
 039        if (contentPanelTransform == null ||
 40            contentPanelTransform.transform == null ||
 41            contentPanelTransform.transform.childCount <= 0)
 042            return;
 43
 44
 045        for (int i = 0; i < contentPanelTransform.transform.childCount; i++)
 46        {
 047            GameObject toRemove = contentPanelTransform.transform.GetChild(i).gameObject;
 048            if (toRemove != null)
 049                Destroy(toRemove);
 50        }
 051    }
 52
 53    private void CheckEmptyContent()
 54    {
 3655        bool contentIsEmpty = contentList.Count == 0;
 56
 3657        if (contentPanelTransform != null)
 3658            contentPanelTransform.gameObject.SetActive(!contentIsEmpty);
 59
 3660        if (emptyContentMark != null)
 761            emptyContentMark.SetActive(contentIsEmpty);
 3662    }
 63}