Unity3d SuperScrollView超级好用的ScrollView(Super ScrollView for UGUI 2.2)

你不必知道它内部怎么排版,只需要知道你需要多少个实例,实例需要的信息

 

例如我们需要点击查看问题和忽略问题,并且提示数字会变化

1.储存信息 定义一个personinfo

public class PersonInfo
    {
        public string m_name;
        public string m_info;
        public string m_time;
        public string Question;
        public string URl;
        public Color m_GetColor;
        /// <summary>
        /// 是否被查看过
        /// </summary>
        public bool IsLookOver;
        /// <summary>
        /// 搜索物体名字
        /// </summary>
        public Transform SearchGame;
        /// <summary>
        /// 被选中点击
        /// </summary>
        public bool OnClick;
}

2.创建一个储存personinfo实例的脚本

 public class DataResouce 
{
        /// <summary>
        ///实时数据
        /// </summary>
        public static List<PersonInfo> RealTimeInfo= new List<PersonInfo>();
        /// <summary>
        ///搜索筛选
        /// </summary>
        public static List<PersonInfo> SearchLitem = new List<PersonInfo>();
}

3.启动排序实例化物体,这个脚本挂在LoopListView2物体上

using SuperScrollView;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace JWGS
{
    public class RealTimeInfoVertical : VerticalBase
    {
        public static RealTimeInfoVertical Instance;
        private static TextMeshProUGUI Questioncount;
        private string url;
        private void Awake()
        {
            Instance = this;
        }
        // Use this for initialization
        void Start()
        {
            Questioncount = ConstantUtils.FindObject<TextMeshProUGUI>("Right-Top/Login/Reminder/count/TextMeshPro");
            mLoopListView = GetComponent<LoopListView2>();
            StartCoroutine(PersonName(url));
            GetMy.AddListener(() => {
                int p = 0;
                for(int i=0;i< DataResouce.RealTimeInfo.Count;i++)
                {
                    if(!DataResouce.RealTimeInfo[i].IsLookOver)
                    {
                        p++;
                     
                    }
                }
                Questioncount.text = p.ToString(); });
        }


        // Update is called once per frame
        void Update()
        {




        }
        bool first;
        public static MyEvent GetMy = new MyEvent();
        //private static int Count=0;
        //public static int P { get { return Count; } set { Count = value;
        //        if (GetMy != null)
        //            GetMy.Invoke();
        //    } }
        private IEnumerator PersonName(string url)
        {
            yield return null;

            int d = UnityEngine.Random.Range(6,10);
            for (int i = 0; i < d; i++)
            {
            
                PersonInfo info = new PersonInfo();
                info.m_name = "吴宗亮"+i;
                info.URl = "wwwww";
                info.Question = "发起新的质量问题";
                info.m_info = "质量";
                info.m_GetColor = new Color(0.8f, 0.3f, 0.3f);
                DataResouce.RealTimeInfo.Insert(0, info);
                GetMy.Invoke();
            }
            if (!first)
            {
                mLoopListView.InitListView(DataResouce.RealTimeInfo.Count, OnGetItemByIndex);//实例化prefab
                first = true;
            }
            else
            {

                addRefresh(d);
            }
            OnJumpBtnClicked(DataResouce.RealTimeInfo.Count);//调到顶置位置
        }
        LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
        {
            if (index < 0 || index >= DataResouce.RealTimeInfo.Count)
            {
                return null;
            }

            PersonInfo itemData = DataResouce.RealTimeInfo[index];
            if (itemData == null)
            {
                return null;
            }
            LoopListViewItem2 item = listView.NewListViewItem("ItemPrefab1");
            RealTimeInfoItem itemScript = item.GetComponent<RealTimeInfoItem>();
            if (item.IsInitHandlerCalled == false)
            {
                item.IsInitHandlerCalled = true;
                itemScript.Init();
                itemScript.myEvent.AddListener(OnDeleteBtnClicked);
                itemScript.LookOver.AddListener(OnLookBtnClicked);
            }

            itemScript.SetItemData(itemData, index);
            return item;
        }

        private void OnLookBtnClicked(int arg0)
        {
            DataResouce.RealTimeInfo[arg0].IsLookOver= true;
            GetMy.Invoke();
        }

        void OnJumpBtnClicked(int i)
        {
            if (i < 0)
                return;
            mLoopListView.MovePanelToItemIndex(i, 0);
        }

        void OnAddItemBtnClicked(int i)
        {
            if (mLoopListView.ItemTotalCount < 0)
            {
                return;
            }

            i = mLoopListView.ItemTotalCount + i;
            if (i < 0 || i > DataResouce.RealTimeInfo.Count)
            {
                return;
            }
            mLoopListView.SetListItemCount(i, false);
        }

        void OnSetItemCountBtnClicked(int i)
        {


            if (i < 0 || i > DataResouce.RealTimeInfo.Count)
            {
                return;
            }
            mLoopListView.SetListItemCount(i, false);
        }
        public void addRefresh(int i)
        {
            OnAddItemBtnClicked(i);
            // OnJumpBtnClicked(ScrollRectpanel.Get.TotalItemCount);
        }
        void OnDeleteBtnClicked(int i)
        {
           
            DataResouce.RealTimeInfo.RemoveAt(i);
            mLoopListView.SetListItemCount(DataResouce.RealTimeInfo.Count, false);
            mLoopListView.RefreshAllShownItem();
            OnJumpBtnClicked(DataResouce.RealTimeInfo.Count);
            GetMy.Invoke();
        }
    }
}

4.需要实例化的prefab上挂载的脚本

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace JWGS
{
    public enum Select
    {
        Realtime=0,
        Relevantfile
    }
    
    public class RealTimeInfoItem : ListItemBase
    {
        public TextMeshProUGUI m_question;
        private string url;
        /// <summary>
        ///查看
        /// </summary>
        private UGUIEventListenerContainDrag m_examine;
        /// <summary>
        ///忽略
        /// </summary>
        private UGUIEventListenerContainDrag m_neglect;
        public MyEvent<int> myEvent=new MyEvent<int>();
        public MyEvent<int> LookOver= new MyEvent<int>();
        private string info;
        private int m_itemIndex;
        // Use this for initialization
        void Start()
        {

        }
        public override void Init()
        {
            m_examine = ConstantUtils.FindObject<UGUIEventListenerContainDrag>("查看", transform);
            m_examine.onClick += delegate {
                LookOver.Invoke(m_itemIndex);
  
            };
            m_neglect = ConstantUtils.FindObject<UGUIEventListenerContainDrag>("忽略", transform);
            m_neglect.onClick += delegate { Debug.Log(url + "忽略");
                if (myEvent != null)
                    myEvent.Invoke(m_itemIndex);
            };

        }
        // Update is called once per frame
        public void SetItemData(PersonInfo info, int itemIndex)
        {
             m_itemIndex = itemIndex;
             Name.text = info.m_name;
             m_question.text = info.Question;
             url = info.URl;
           this.info = info.m_info;
        }
        void Update()
        {

        }
    }
}

附上事件处理 

    public class MyEvent : UnityEvent { };
    public class MyEvent<T1> : UnityEvent<T1> { };
    public class MyEvent<T1, T2> : UnityEvent<T1, T2> { };
    public class MyEvent<T1, T2, T3> : UnityEvent<T1, T2, T3> { };
    public class MyEvent<T1, T2, T3, T4> : UnityEvent<T1, T2, T3, T4> { };

最后说一下UGUIEventListenerContainDrag是继承处理ui事件的接口

using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text;
using TMPro;
using DG.Tweening;
using UnityEngine.UI;
using UnityEngine.Events;
using System.Security.Cryptography;
namespace JWGS
{
    public static class ConstantUtils
    {
          
        /// <summary>
        /// 返回组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="game"></param>
        /// <returns></returns>
        public static T AddCompnent<T>(GameObject game) where T : Component
        {
            T ts = game.GetComponent<T>();
            if (!ts)
                ts = game.AddComponent<T>();
            return ts;
        }
        /// <summary>
        /// 协程委托
        /// </summary>
        /// <param name="action"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public static IEnumerator ActionTor(Action action, float time)
        {
            yield return new WaitForSeconds(time);
            action();
        }
         /// <summary>
    /// 找到物体添加组件并返回
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="path"></param>
    /// <param name="parent"></param>
    /// <returns></returns>
    public static T FindObject<T>(string path, Transform parent = null) where T : Component
    {
        if (parent == null)
        {
            GameObject game = GameObject.Find(path);
            if (game == null)
            {
                return null;
            }
            return AddCompnent<T>(game);
        }
        else
        {
            Transform tr = parent.Find(path);
            if (tr == null)
            {
                return null;
            }
            GameObject game = parent.Find(path).gameObject;

            return AddCompnent<T>(game);
        }
    }
    
    }

}

 

通过以上基础我们可以设置更复杂的滑块,插件很实用

 

Super ScrollView for UGUI提供基于UGUI ScrollRect的可轻松定制的ScrollView。它是一组C#脚本,可帮助您创建所需的ScrollView。这是非常强大的和高度优化的性能。 文件 Android演示应用程序 演示: - 聊天消息列表演示 - 水平画廊演示 - 垂直画廊演示 - GridView演示 - PageVew演示 - TreeVew演示 - 与稠粘头演示的TreeView - 旋转日期选择器 - 更改项目高度演示 - 下拉刷新演示 - 拉起来加载更多的演示 - 点击加载更多演示 - 选择并删除演示 - GridView删除项目演示 - 顶部到底部的演示 - 自下而上的演示 - 从左到右的演示 - 右侧演示 - 响应GridView演示 - TreeViewWithChildrenIndent演示 特征: - ListView和GridView和TreeView - 无限的项目 - 项目在不同的大小(高度/宽度) - 具有不同预制的物品 - 在初始时间大小未知的项目 - 垂直滚动视图(从上到下,从下到上) - 水平滚动视图(从左到右,从右到左) - 项目填充 - 滚动到指定的项目 - 滚动到具有偏移量的项目 - 项目计数在运行时更改 - 项目大小(高度/宽度)在运行时更改 - 物品捕捉到视口中的任何位置 - 项目循环,如微调 - 添加/删除项目 - 全部删除/删除所有项目 - 刷新并重新加载项目 - 使用池缓存项目,不要在运行时销毁项目 - 有效回收物品 - 平台无关 - UGUI支持 - 支持Unity平台(IOS / Android / Mac / PC / Console / Winphone / WebGL ...)
### 回答1: Super ScrollView是针对Unity的UGUI框架开发的一个超级滚动视图插件。UGUI本身提供了ScrollRect组件用于实现滚动视图,但是其在处理大量内容和性能方面有一些限制。 Super ScrollView的目标是提供一个更加高效和易用的滚动视图解决方案。它使用C#脚本编写,可以方便地添加到Unity项目中。 Super ScrollView的主要特点是: 1. 高性能:Super ScrollView通过使用对象池和只渲染可见部分的方式,优化了滚动视图的性能。这样可以在处理大量内容时,保持良好的性能表现,避免掉帧和卡顿。 2. 可定制性:Super ScrollView提供了丰富的可定制选项,允许开发者根据自己的需求进行布局和样式的定制。可以灵活地设置滚动速度、滚动方向、内边距等属性,以满足各种滚动视图的设计需求。 3. 支持复用:Super ScrollView支持Item的复用,可以重复使用已经滑出屏幕的Item,减少资源开销。这对于处理大量Item的滚动视图特别有用,可以大大提高内存和性能的使用效率。 4. 丰富的事件回调:Super ScrollView提供了多种事件回调,包括滚动、拖拽、点击等。可以根据需要进行业务逻辑的处理,增强交互体验。 总之,Super ScrollView是一个强大的UGUI滚动视图插件,可以满足开发者处理大量内容时对性能和效果的要求。它的高性能、可定制性和复用机制,使得开发者能够更加轻松地实现各种滚动视图效果。 ### 回答2: Super ScrollView 是一种为 UGUIUnity3D的图形用户界面系统)设计的超级滚动视图。UGUIUnity3D的可视化UI编辑器,Super ScrollView是通过扩展和优化UGUI的滚动视图组件而创建的。 Super ScrollView 作为一个更高级的滚动视图,主要针对UGUI在大数据量下的性能问题进行了优化。在传统的UGUI滚动视图中,当有大量的元素需要滚动时,会出现卡顿且性能下降的问题。而Super ScrollView通过使用对象池、异步处理和延迟更新等技术来解决这些问题。 首先,Super ScrollView通过对象池技术来重复利用已经存在的滚动子项,而不是不断创建和销毁新的子项。这可以减少内存开销和避免频繁的实例化和销毁过程。 其次,Super ScrollView采用异步处理的方式来加载和渲染滚动子项。它可以在滚动过程中异步加载和渲染新的子项,从而避免阻塞主线程,提高了滚动的流畅性。 最后,Super ScrollView还实现了延迟更新的机制。它会在滚动停止后进行一次性的更新,而不是在每次滚动时都更新UI。这有效地减少了UI更新的次数,提高了滚动的响应速度。 总之,Super ScrollView是一个专门为UGUI滚动视图优化设计的解决方案。它通过对象池、异步处理和延迟更新等技术,能够在处理大量数据时提供更好的性能和流畅的滚动体验。 ### 回答3: Super ScrollView是UGUI的一个插件,它是为解决在Unity中使用UGUI时滚动效果不理想的问题而开发的。UGUI原生的ScrollView在滚动大量内容时会有卡顿和性能问题,而Super ScrollView则通过优化算法和批处理技术来提升滚动表现。 Super ScrollView的主要特点有以下几点: 1. 强大的性能优化:Super ScrollView通过减少绘制调用和重用滚动组件来提高性能。它可以自动对可见的内容进行批处理,减少渲染调用,同时通过对象池优化滚动元素的创建和销毁,避免重复开销。 2. 动态元素加载:Super ScrollView支持动态加载元素,可以一次性加载所有元素,也可以根据需要动态加载可见元素,避免一次性加载大量元素造成的性能问题。 3. 弹性滚动效果:Super ScrollView支持弹性滚动效果,可以通过调整阻尼和回弹系数来实现在滚动结束时的回弹效果,提升用户体验。 4. 手势识别:Super ScrollView支持识别多种手势,如拖拽、滑动、缩放等,可以通过手势操作来实现自定义的交互效果。 总之,Super ScrollView是一个强大的UGUI插件,通过性能优化和特殊效果的支持,可以提升Unity中使用UGUI实现滚动列表的体验和性能。它可以解决UGUI原生ScrollView存在的卡顿、性能不佳等问题,是开发者在制作滚动列表时的首选插件之一。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值