背包系统的组件有:UIGrid,UIScrollview(循环)
NGUI原生的的UIsrollview 是没循环功能的,因此要想背包系统运行流畅,就必须将所有物品放在循环的scrollview中
不废话,直接上代码和效果图
NGUI原生的的UIsrollview 是没循环功能的,因此要想背包系统运行流畅,就必须将所有物品放在循环的scrollview中
不废话,直接上代码和效果图
效果图:
代码:
1 循环scrollview ( BackpackLoopScrollView )
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using cl_ls;
using cl_gs;
using cl_gs_ex;
using cl_gs_checkpoint;
using System.Collections.Generic;
using System;
using evt;
using fil;
using tools;
using System.IO;
using enumtype;
[RequireComponent(typeof(UIGrid))]
public class BackpackLoopScrollView : MonoBehaviour
{
#region Members
private List<List<ITEM>> _dataList;
private List<UIWidget> _itemsList = new List<UIWidget>(); // 存储物件列表
private Vector4 _posParam;
private Transform _cachedTransform;
private int _startIndex; // 起始下标
private int _maxCount; // 最大长度
public UIScrollView _scrollView; // 父ScrollView
private UIGrid _grid;
private bool _canSlideToleft=false; //是否可以向左互动
private bool _canSlideToRight=false; //是否可以向右滑动
#endregion
void Awake()
{
_cachedTransform = this.transform;
_scrollView = _cachedTransform.parent.GetComponent<UIScrollView>();
// 设置Cull
_scrollView.GetComponent<UIPanel>().cullWhileDragging = true;
_grid = this.transform.GetComponent<UIGrid>();
float cellWidth = _grid.cellWidth;
float cellHeight = _grid.cellHeight;
_posParam = new Vector4(cellWidth,cellHeight,_grid.arrangement == UIGrid.Arrangement.Horizontal ? 1 : 0