| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | |
|
| | 5 | | public class CatalogGroupListView : ListView<Dictionary<string, List<CatalogItem>>> |
| | 6 | | { |
| | 7 | | public Canvas generalCanvas; |
| | 8 | | public CatalogAssetGroupAdapter categoryItemAdapterPrefab; |
| | 9 | | public DynamicScrollSensitivity dynamicScrollSensitivity; |
| | 10 | |
|
| | 11 | | public System.Action<CatalogItem> OnCatalogItemClicked; |
| | 12 | | public System.Action<CatalogItem, CatalogItemAdapter> OnCatalogItemStarDragging; |
| | 13 | | public System.Action<CatalogItem, CatalogItemAdapter> OnCatalogItemFavorite; |
| | 14 | | public System.Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInAdapter; |
| | 15 | | public System.Action<PointerEventData, CatalogItemAdapter> OnPointerExitInAdapter; |
| | 16 | |
|
| | 17 | | public override void AddAdapters() |
| | 18 | | { |
| 0 | 19 | | base.AddAdapters(); |
| | 20 | |
|
| 0 | 21 | | if (contentList == null) |
| 0 | 22 | | return; |
| | 23 | |
|
| 0 | 24 | | foreach (Dictionary<string, List<CatalogItem>> assetPackGroups in contentList) |
| | 25 | | { |
| 0 | 26 | | foreach (KeyValuePair<string, List<CatalogItem>> assetPackGroup in assetPackGroups) |
| | 27 | | { |
| 0 | 28 | | CatalogAssetGroupAdapter adapter = Instantiate(categoryItemAdapterPrefab, contentPanelTransform).GetComp |
| 0 | 29 | | adapter.SetContent(assetPackGroup.Key, assetPackGroup.Value); |
| 0 | 30 | | SubscribeToEvents(adapter); |
| | 31 | | } |
| | 32 | | } |
| | 33 | |
|
| 0 | 34 | | if (dynamicScrollSensitivity != null) |
| 0 | 35 | | dynamicScrollSensitivity.RecalculateSensitivity(); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void RemoveAdapters() |
| | 39 | | { |
| 0 | 40 | | if (contentPanelTransform == null || |
| | 41 | | contentPanelTransform.transform == null || |
| | 42 | | contentPanelTransform.transform.childCount == 0) |
| 0 | 43 | | return; |
| | 44 | |
|
| 0 | 45 | | for (int i = 0; i < contentPanelTransform.transform.childCount; i++) |
| | 46 | | { |
| 0 | 47 | | CatalogAssetGroupAdapter toRemove = contentPanelTransform.transform.GetChild(i).GetComponent<CatalogAssetGro |
| 0 | 48 | | if (toRemove != null) |
| | 49 | | { |
| 0 | 50 | | UnsubscribeToEvents(toRemove); |
| 0 | 51 | | Destroy(toRemove.gameObject); |
| | 52 | | } |
| | 53 | | } |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | public void SubscribeToEvents(CatalogAssetGroupAdapter adapter) |
| | 57 | | { |
| 1 | 58 | | adapter.OnCatalogItemClicked += CatalogItemSelected; |
| 1 | 59 | | adapter.OnCatalogItemFavorite += CatalogItemFavorite; |
| 1 | 60 | | adapter.OnAdapterStartDragging += AdapterStartDragging; |
| 1 | 61 | | adapter.OnPointerEnterInAdapter += OnPointerEnter; |
| 1 | 62 | | adapter.OnPointerExitInAdapter += OnPointerExit; |
| 1 | 63 | | } |
| | 64 | |
|
| | 65 | | public void UnsubscribeToEvents(CatalogAssetGroupAdapter adapter) |
| | 66 | | { |
| 0 | 67 | | adapter.OnCatalogItemClicked -= CatalogItemSelected; |
| 0 | 68 | | adapter.OnCatalogItemFavorite -= CatalogItemFavorite; |
| 0 | 69 | | adapter.OnAdapterStartDragging -= AdapterStartDragging; |
| 0 | 70 | | adapter.OnPointerEnterInAdapter -= OnPointerEnter; |
| 0 | 71 | | adapter.OnPointerExitInAdapter -= OnPointerExit; |
| 0 | 72 | | } |
| | 73 | |
|
| 18 | 74 | | private void AdapterStartDragging(CatalogItem catalogItemClicked, CatalogItemAdapter adapter, BaseEventData data) { |
| | 75 | |
|
| 0 | 76 | | private void CatalogItemSelected(CatalogItem sceneObject) { OnCatalogItemClicked?.Invoke(sceneObject); } |
| | 77 | |
|
| 0 | 78 | | private void CatalogItemFavorite(CatalogItem sceneObject, CatalogItemAdapter adapter) { OnCatalogItemFavorite?.Invok |
| | 79 | |
|
| 0 | 80 | | private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInAdapter?.Invok |
| | 81 | |
|
| 0 | 82 | | private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInAdapter?.Invoke( |
| | 83 | | } |