LoopScrollView

using UnityEngine;
using System.Collections.Generic;

/// <summary>
/// 这个类主要做了一件事,就是优化了,NGUI UIScrollView 在数据量很多都时候,
/// 创建过多都GameObject对象,造成资源浪费.
/// </summary>
public class LoopScrollView : MonoBehaviour
{
	public enum ArrangeDirection
	{
		Left_to_Right,
		Right_to_Left,
		Up_to_Down,
		Down_to_Up,
	}
	/// <summary>
	/// items的排列方式
	/// </summary>
	public ArrangeDirection arrangeDirection = ArrangeDirection.Up_to_Down;

	/// <summary>
	/// 列表脚本
	/// </summary>
	public UIScrollView scrollView;
	public GameObject itemParent;

	/// <summary>
	/// 列表单项模板
	/// </summary>
	public GameObject itemPrefab;

	[HideInInspector]
	public int maxPoolItem = 3;

	/// <summary>
	/// The items list.
	/// </summary>
	public List<LoopItemObject> itemsList;
	/// <summary>
	/// The datas list.
	/// </summary>
	public List<object> datasList;

	/// <summary>
	/// itemsList的第一个元素
	/// </summary>
	LoopItemObject firstItem;
	/// <summary>
	/// itemsList的最后一个元素
	/// </summary>
	LoopItemObject lastItem;


	public delegate void DelegateHandler (LoopItemObject item, object data);
	/// <summary>
	/// 响应
	/// </summary>
	public DelegateHandler OnItemInit;

	/// <summary>
	/// 第一item的起始位置
	/// </summary>
	public Vector3 itemStartPos = Vector3.zero;
	/// <summary>
	/// 菜单项间隙
	/// </summary>
	public float gapDis = 0f;

	// 对象池
	// 再次优化,频繁的创建与销毁
	Queue<LoopItemObject> itemLoop = new Queue<LoopItemObject> ();

	void Awake ()
	{
		if (itemPrefab == null || scrollView == null || itemParent == null) {
			Debug.LogError ("LoopScrollView.Awake() 有属性没有在inspector中赋值");
		}

		// 设置scrollview的movement
		if (arrangeDirection == ArrangeDirection.Up_to_Down || 
			arrangeDirection == ArrangeDirection.Down_to_Up) {
			scrollView.movement = UIScrollView.Movement.Vertical;
		} else {
			scrollView.movement = UIScrollView.Movement.Horizontal;
		}

		scrollView.pane
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值