using System;
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
public class Test : MonoBehaviour
{
public UIScrollView _scrollView;
public UIGrid _grid;
private float _startY;//初始时,ScrollView的高度
private float _boundsHeight;//所有item的总高度
private float _clipHeight;//裁剪区域高度
private bool flag;
void Awake()
{
InvokeRepeating("AddItem", 1, 3);
}
void Start()
{
_startY = _scrollView.transform.localPosition.y;
_boundsHeight = _scrollView.bounds.size.y;
_clipHeight = _scrollView.panel.baseClipRegion.w;
Debug.Log(_startY + " " + _boundsHeight + " " + _clipHeight);
}
void AddItem()
{
GameObject go = Resources.Load<GameObject>("Sprite");
NGUITools.AddChild(_grid.gameObject, go);
_grid.Reposition();
Debug.Log(_boundsHeight);
//判断SrollView是否滑动到底部
if (Math.Abs(_scrollView.transform.localPosition.y-_startY)+_clipHeight<_boundsHeight)
{
Debug.LogError("有新元素添加");
}
else
{
_scrollView.ResetPosition();
_boundsHeight = _scrollView.bounds.size.y;
if (_boundsHeight > _clipHeight)
{
_scrollView.SetDragAmount(0,1,false);
}
}
}
}
NGUI ScrollView是否滑到底部的判断
最新推荐文章于 2019-07-19 14:20:13 发布