using System.Collections.Generic; using UnityEngine; using Wizard.Scripts.Network.Data.TableData; public class DialogRewardScroll : MonoBehaviour { [SerializeField] private UIWrapContentWizard WrapContent; [SerializeField] private GameObject Item; [SerializeField] private UIScrollBarWrapContent ScrollBar; [SerializeField] private WrapContentsScrollBarSize WrapScrollbar; [SerializeField] private UIScrollView ScrollView; [SerializeField] private UILabel _emptyLabel; private const int SCROLL_ITEM_COUNT = 10; private const int HISTORY_ITEM_SPRITE_WIDTH = 800; private GameObject[] Items; private List _currentList; public List CurrentList { get { return _currentList; } set { _currentList = value; _emptyLabel.gameObject.SetActive(_currentList.Count == 0); } } public ResourceHandler Handler { get; set; } public void Start() { CreateSomeItems(); WrapContent.onInitializeItem = InitScrollItem; ScrollBar.m_WrapContents = WrapContent; } public void resetScrollWrap() { WrapContent.minIndex = -(CurrentList.Count - 1); WrapContent.maxIndex = 0; ScrollView.ResetPosition(); WrapContent.resetItems(); WrapScrollbar.ContentUpdate(); ScrollView.ResetPosition(); ScrollBar.gameObject.SetActive(value: true); ScrollView.UpdateScrollbars(); } private void InitScrollItem(GameObject obj, int wrapIndex, int realIndex) { GameObject gameObject = obj.transform.GetChild(0).gameObject; if (-realIndex < 0 || -realIndex >= CurrentList.Count) { gameObject.SetActive(value: false); return; } gameObject.SetActive(value: true); int num = -realIndex; SetHistoryItem(gameObject, CurrentList[num], num == CurrentList.Count - 1); } private void SetHistoryItem(GameObject item, ItemAcquireHistory history, bool isLastItem) { item.GetComponent().width = 800; item.GetComponent().SetHistoryItem(history, !isLastItem, Handler); } private void CreateSomeItems() { Items = new GameObject[10]; for (int i = 0; i < 10; i++) { GameObject gameObject = new GameObject(); Transform obj = gameObject.transform; obj.parent = WrapContent.transform; obj.localPosition = Vector3.zero; obj.localRotation = Quaternion.identity; obj.localScale = Vector3.one; gameObject.layer = WrapContent.gameObject.layer; NGUITools.AddChild(gameObject, Item).SetActive(value: true); gameObject.SetActive(value: true); Items[i] = gameObject; } } }