unity fairygui 列表第一次滑动先展开

unity fairygui 列表展开效果

简单记录一下
列表第一次滑动,先展开(高度从100 变到300)再滑动

为了避免列表滑动后显示的组件不完整,勾选此按钮unity fairygui 列表第一次滑动先展开_第1张图片

unity fairygui 列表第一次滑动先展开_第2张图片

这是组件代码,内容比较简单

using System;
using FairyGUI;
using FairyGUI.Utils;
using BCore;
using UnityEditor;

public class ListFrame : GComponent
{
    private GList list;
    private bool listOpen;
    private bool listHide;

	public override void ConstructFromXML(XML xml)
    {
        base.ConstructFromXML(xml);
        list = GetChild("list").asList;
        list.scrollPane.onScroll.Add(UpdaeListHeightUp);
        list.scrollPane.onPullDownRelease.Add(UpdateListHeightDown);
        //list.onClick.Add(UpdaeListHeight);
    }

	
	public void OnShow()
	{
        listOpen = false;
        listHide = false;
        list.height = 100;      //  默认高度
        UpdateList();
    }

	public void OnHide()
    {
        BEventMgr.I.removeAllEvent(this);
        list.RemoveChildrenToPool();
    }

    private void UpdateList()
    {
        for(int i = 0; i < 15; i++)
        {
            var cell = list.AddItemFromPool().asCom;
            //  设置该组件信息
        }
    }

    //  如果是下滑
    private void UpdateListHeightDown()
    {
        if (list.height > 150 && list.scrollPane.scrollingPosY <= 0 && !listHide)
        {
            listHide = true;
            listOpen = false;
            NumRoll.I.StartChangeListHeight(list, list.height, 150, 0.5f);
        }
    }

    //  如果是上滑
    private void UpdaeListHeightUp()
    {
        if (list.height < 500 && list.scrollPane.scrollingPosY > 0 && !listOpen) 
        {
            listOpen = true;
            listHide = false;
            NumRoll.I.StartChangeListHeight(list, list.height, 500, 0.5f);
        } 
    }
}

这是使用的协程方法

  private IEnumerator UpdateListHeight(GList list, float startNum, float endNum,float time)
    {
        float interval = time / 30;
        DateTime beginTime = DateTime.Now;
        DateTime endTime = DateTime.Now.AddSeconds(time);
        double delta;
        while (true)
        {
            if(DateTime.Now >= endTime)
            {
                list.height = endNum;
                break;
            }
            delta = (DateTime.Now - beginTime).TotalSeconds;
            float currTime = (float)delta / time;
            float currNum = Mathf.Lerp(startNum, endNum, currTime);
            list.height = currNum;
            yield return new WaitForSeconds(interval);
        }
    }

你可能感兴趣的:(unity,unity3d)