Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How could I update the list without having to recreate the pooling #13

Open
andrehrferreira opened this issue Mar 27, 2023 · 1 comment

Comments

@andrehrferreira
Copy link

andrehrferreira commented Mar 27, 2023

Hello, I'm using this script in my project, but there is a small performance problem when updating the list, because when I update the list I need to call the function _recyclableScrollRect.ReloadData(); however from what I saw the script recreates the pooling when it calls this function in the InitCoroutine routine, is there any way to update the list without having to recreate the pooling? because in theory the items that are in the pooling are already of the same type so there is no need to instantiate again

I will leave the script of one of the screens where I use the script as an example

`using System.Collections.Generic;
using UnityEngine;
using PolyAndCode.UI;

public class StashDialog : MonoBehaviour, IRecyclableScrollRectDataSource
{
[SerializeField]
RecyclableScrollRect _recyclableScrollRect;

  public Canvas Canvas;
  private List<SlotItemInfo> _list = new List<SlotItemInfo>();

  public bool Opened = false;

  void Start()
  {
      if (_recyclableScrollRect != null)
          _recyclableScrollRect.DataSource = this;

      gameObject.SetActive(false);

      Opened = false;

      ItemContainerManager.StashContainer.Added += (uint itemId, ItemReference itemReference) => Refresh();
      ItemContainerManager.StashContainer.Removed += (uint itemId, ItemReference itemReference) => Refresh();
      ItemContainerManager.StashContainer.Cleared += () => Refresh();
      ItemContainerManager.StashContainer.WeightChanged += (uint itemId) => Refresh();
  }

  public void Refresh()
  {
      if (Opened)
      {
          List<SlotItemInfo> list = new List<SlotItemInfo>();

          foreach (var item in ItemContainerManager.StashContainer.ItemsMapping)
          {
              list.Add(new SlotItemInfo()
              {
                  itemRef = item.Value,
                  canvas = Canvas
              });
          }

          _list = list;

          if (_recyclableScrollRect.isActiveAndEnabled)
              _recyclableScrollRect.ReloadData();
      }            
  }

  public int GetItemCount()
  {
      return _list.Count;
  }

  public void SetCell(ICell cell, int index)
  {
      var item = cell as SlotItem;

      item.ConfigureCell(_list[index], index);
  }

  public void Show()
  {
      gameObject.SetActive(true);

      WindowManager.Instance.HideInventoryComplement();

      if (WindowManager.Instance.TradeDialog.Opened)
          WindowManager.Instance.TradeDialog.Close();

      Opened = true;

      Refresh();
  }

  public void Close()
  {
      _list.Clear();

      gameObject.SetActive(false);

      Opened = false;
  }

}
`

@ethanfischer
Copy link

ethanfischer commented May 10, 2024

Same issue. In my case, calling ReloadData is causes a bump in texture memory which eventually causes our ipad app to crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants