< Summary

Class:CatalogAssetGroupAdapter
Assembly:BuilderInWorldCatalog
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Catalog/UI/Adapters/CatalogAssetGroupAdapter.cs
Covered lines:7
Uncovered lines:24
Coverable lines:31
Total lines:75
Line coverage:22.5% (7 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetContent(...)0%12300%
SubscribeToEvents(...)0%110100%
UnsubscribeToEvents(...)0%2100%
RemoveAdapters()0%12300%
CatalogItemClicked(...)0%6200%
CatalogItemFavorite(...)0%6200%
AdapterStartDragging(...)0%220100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Catalog/UI/Adapters/CatalogAssetGroupAdapter.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.EventSystems;
 6
 7public class CatalogAssetGroupAdapter : MonoBehaviour
 8{
 9    public TextMeshProUGUI categoryTxt;
 10    public GameObject categoryContentGO;
 11    public System.Action<CatalogItem> OnCatalogItemClicked;
 12    public System.Action<CatalogItem, CatalogItemAdapter> OnCatalogItemFavorite;
 13    public System.Action<CatalogItem, CatalogItemAdapter, BaseEventData> OnAdapterStartDragging;
 14    public System.Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInAdapter;
 15    public System.Action<PointerEventData, CatalogItemAdapter> OnPointerExitInAdapter;
 16
 17    [Header("Prefab References")]
 18    public GameObject catalogItemAdapterPrefab;
 19
 20    public void SetContent(string category, List<CatalogItem> catalogItemList)
 21    {
 022        categoryTxt.text = category.ToUpper();
 023        RemoveAdapters();
 024        foreach (CatalogItem catalogItem in catalogItemList)
 25        {
 026            if (catalogItem.IsSmartItem())
 27                continue;
 28
 029            CatalogItemAdapter adapter = Instantiate(catalogItemAdapterPrefab, categoryContentGO.transform).GetComponent
 030            adapter.SetContent(catalogItem);
 031            SubscribeToEvents(adapter);
 32        }
 033    }
 34
 35    public void SubscribeToEvents(CatalogItemAdapter adapter)
 36    {
 137        adapter.OnCatalogItemClicked += CatalogItemClicked;
 138        adapter.OnCatalogItemFavorite += CatalogItemFavorite;
 139        adapter.OnAdapterStartDrag += AdapterStartDragging;
 140        adapter.OnPointerEnterInAdapter += OnPointerEnter;
 141        adapter.OnPointerExitInAdapter += OnPointerExit;
 142    }
 43
 44    public void UnsubscribeToEvents(CatalogItemAdapter adapter)
 45    {
 046        adapter.OnCatalogItemClicked -= CatalogItemClicked;
 047        adapter.OnCatalogItemFavorite -= CatalogItemFavorite;
 048        adapter.OnAdapterStartDrag -= AdapterStartDragging;
 049        adapter.OnPointerEnterInAdapter -= OnPointerEnter;
 050        adapter.OnPointerExitInAdapter -= OnPointerExit;
 051    }
 52
 53    public void RemoveAdapters()
 54    {
 055        for (int i = 0; i < categoryContentGO.transform.childCount; i++)
 56        {
 057            CatalogItemAdapter toRemove = categoryContentGO.transform.GetChild(i).GetComponent<CatalogItemAdapter>();
 058            if (toRemove != null)
 59            {
 060                UnsubscribeToEvents(toRemove);
 061                Destroy(toRemove.gameObject);
 62            }
 63        }
 064    }
 65
 066    private void CatalogItemClicked(CatalogItem catalogItemClicked) { OnCatalogItemClicked?.Invoke(catalogItemClicked); 
 67
 068    private void CatalogItemFavorite(CatalogItem catalogItemClicked, CatalogItemAdapter adapter) { OnCatalogItemFavorite
 69
 1870    private void AdapterStartDragging(CatalogItem catalogItemClicked, CatalogItemAdapter adapter, BaseEventData data) { 
 71
 072    private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInAdapter?.Invok
 73
 074    private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInAdapter?.Invoke(
 75}