亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Unity實(shí)現(xiàn)首字母檢索器

 更新時(shí)間:2020年11月29日 13:27:51   作者:依舊im  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)首字母檢索器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)首字母檢索器的具體代碼,供大家參考,具體內(nèi)容如下

需要實(shí)現(xiàn)一個(gè)類似 “城市選擇器”的功能 網(wǎng)上基本都是用原生或者前端來(lái)實(shí)現(xiàn)功能 其他大概的思路都差不多 這里提供一個(gè)Unity 實(shí)現(xiàn)的思路

先看一下效果

這里用到了 SuperScrollView 這個(gè)插件 來(lái)實(shí)現(xiàn)功能

ListText.cs  // 核心控制類  代碼寫(xiě)的比較隨意 大概的功能已經(jīng)實(shí)現(xiàn),需要根據(jù)實(shí)際需要進(jìn)行優(yōu)化。

using SuperScrollView;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class ListText : MonoBehaviour
{
 public LoopListView2 mLoopListView;
 public Text Select_Text;
 public RectTransform Right_Content;
 public GameObject Tag_Prefab;
 public string[] Tags = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#" };
 
 public int TreeViewItemCount
 {
 get
 {
 return mItemDataList.Count;
 }
 }
 // Start is called before the first frame update
 void Start()
 {
 Init();
 
 Keys.Clear();
 for (int i = 0; i < Tags.Length; ++i)
 {
 CityData cityData = new CityData();
 cityData.Key = Tags[i];
 List<string> value = new List<string>();
 value.Add("Item" + Tags[i] + Random.Range(0, 6).ToString());
 cityData.Value = value;
 
 Keys.Add(cityData);
 }
 DoRefreshDataSource();
 int count = TreeViewItemCount;
 //tells mTreeItemCountMgr there are how many TreeItems and every TreeItem has how many ChildItems.
 for (int i = 0; i < count; ++i)
 {
 int childCount = GetItemDataByIndex(i).ChildCount;
 //second param "true" tells mTreeItemCountMgr this TreeItem is in expand status, that is to say all its children are showing.
 AddTreeItem(childCount, true);
 }
 
 mLoopListView.InitListView(GetTotalItemAndChildCount(), OnGetItemByIndex);
 }
 
 public void AddTreeItem(int count, bool isExpand)
 {
 KeyData data = new KeyData();
 data.mTreeItemIndex = mTreeItemDataList.Count;
 data.mChildCount = count;
 data.mIsExpand = isExpand;
 mTreeItemDataList.Add(data);
 mIsDirty = true;
 }
 public int GetTotalItemAndChildCount()
 {
 int count = mTreeItemDataList.Count;
 if (count == 0)
 {
 return 0;
 }
 UpdateAllTreeItemDataIndex();
 return mTreeItemDataList[count - 1].mEndIndex + 1;
 }
 LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
 {
 if (index < 0)
 {
 return null;
 }
 
 KeyData countData = QueryTreeItemByTotalIndex(index);
 if (countData == null)
 {
 return null;
 }
 int treeItemIndex = countData.mTreeItemIndex;
 ValueData treeViewItemData = GetItemDataByIndex(treeItemIndex);
 if (countData.IsChild(index) == false)// if is a TreeItem
 {
 //get a new TreeItem
 LoopListViewItem2 item = listView.NewListViewItem("KeyItem");
 KeyItem itemScript = item.GetComponent<KeyItem>();
 if (item.IsInitHandlerCalled == false)
 {
 item.IsInitHandlerCalled = true;
 itemScript.Init();
 //itemScript.SetClickCallBack(this.OnExpandClicked);
 }
 //update the TreeItem's content
 itemScript.mText.text = treeViewItemData.mName;
 itemScript.SetItemData(treeItemIndex, countData.mIsExpand);
 return item;
 }
 else // if is a TreeChildItem
 {
 //childIndex is from 0 to ChildCount.
 //for example, TreeChildItem0_0 is the 0'th child of TreeItem0
 //and TreeChildItem1_2 is the 2'th child of TreeItem1
 int childIndex = countData.GetChildIndex(index);
 ItemData itemData = treeViewItemData.GetChild(childIndex);
 if (itemData == null)
 {
 return null;
 }
 //get a new TreeChildItem
 LoopListViewItem2 item = listView.NewListViewItem("ValueItem");
 ValueItem itemScript = item.GetComponent<ValueItem>();
 if (item.IsInitHandlerCalled == false)
 {
 item.IsInitHandlerCalled = true;
 itemScript.Init();
 }
 //update the TreeChildItem's content
 itemScript.SetItemData(itemData, treeItemIndex, childIndex);
 return item;
 }
 
 }
 
 List<ValueData> mItemDataList = new List<ValueData>();
 
 int mTreeViewItemCount = 20;
 int mTreeViewChildItemCount = 30;
 
 // List<string, List<string>> keys = new List<string, List<string>>();
 
 
 ArrayList Keys = new ArrayList();
 
 void DoRefreshDataSource()
 {
 mItemDataList.Clear();
 
 
 for (int i = 0; i < Keys.Count; i++)
 {
 ValueData tData = new ValueData();
 CityData city = Keys[i] as CityData;
 tData.mName = "" + city.Key;
 mItemDataList.Add(tData);
 // int childCount = Random.Range(0, 6);
 for (int j = 0; j < city.Value.Count; j++)
 {
 ItemData childItemData = new ItemData();
 childItemData.mName = "Item" + city.Value[j] + ":Child" + j;
 childItemData.mDesc = "Item Desc For " + childItemData.mName;
 childItemData.mStarCount = Random.Range(0, 6);
 childItemData.mFileSize = Random.Range(20, 999);
 tData.AddChild(childItemData);
 }
 }
 //for (int i = 0; i < keys.Count; ++i)
 //{
 // ValueData tData = new ValueData();
 // tData.mName = "" + keys[]
 // mItemDataList.Add(tData);
 // int childCount = Random.Range(0, 6);
 
 //}
 }
 
 public void AddItem()
 {
 // string key = Tags[Random.Range(0, Tags.Length)];
 // int itemIndex = Random.Range(0, Tags.Length);
 int itemIndex = 0;
 CityData cityData = Keys[itemIndex] as CityData;
 
 cityData.Value.Add(cityData.Key + "測(cè)試");
 
 Keys[itemIndex] = cityData;
 
 // int itemIndex = 0;
 int childIndex = 0;
 
 if (childIndex < 0)
 {
 childIndex = 0;
 }
 KeyData itemCountData = GetTreeItem(itemIndex);
 if (itemCountData == null)
 {
 return;
 }
 AddNewItemChildForTest(itemIndex, childIndex);
 int childCount = itemCountData.mChildCount;
 SetItemChildCount(itemIndex, childCount + 1);
 DoRefreshDataSource();
 mLoopListView.SetListItemCount(GetTotalItemAndChildCount(), false);
 
 mLoopListView.RefreshAllShownItem();
 }
 public void SetItemChildCount(int treeIndex, int count)
 {
 if (treeIndex < 0 || treeIndex >= mTreeItemDataList.Count)
 {
 return;
 }
 mIsDirty = true;
 KeyData data = mTreeItemDataList[treeIndex];
 data.mChildCount = count;
 }
 public void AddNewItemChildForTest(int itemIndex, int AddToBeforeChildIndex)
 {
 if (itemIndex < 0 || itemIndex >= mItemDataList.Count)
 {
 return;
 }
 ValueData tData = mItemDataList[itemIndex];
 List<ItemData> childItemDataList = tData.mChildItemDataList;
 ItemData childItemData = new ItemData();
 childItemData.mName = "Item" + itemIndex + ":" + AddToBeforeChildIndex;
 childItemData.mDesc = "Item Desc For " + childItemData.mName;
 childItemData.mStarCount = Random.Range(0, 6);
 childItemData.mFileSize = Random.Range(20, 999);
 if (AddToBeforeChildIndex < 0)
 {
 childItemDataList.Insert(0, childItemData);
 }
 else if (AddToBeforeChildIndex >= childItemDataList.Count)
 {
 childItemDataList.Add(childItemData);
 }
 else
 {
 childItemDataList.Insert(AddToBeforeChildIndex, childItemData);
 }
 
 }
 
 public ValueData GetItemDataByIndex(int index)
 {
 if (index < 0 || index >= mItemDataList.Count)
 {
 return null;
 }
 return mItemDataList[index];
 }
 
 List<KeyData> mTreeItemDataList = new List<KeyData>();
 KeyData mLastQueryResult = null;
 bool mIsDirty = true;
 public KeyData QueryTreeItemByTotalIndex(int totalIndex)
 {
 if (totalIndex < 0)
 {
 return null;
 }
 int count = mTreeItemDataList.Count;
 if (count == 0)
 {
 return null;
 }
 UpdateAllTreeItemDataIndex();
 if (mLastQueryResult != null)
 {
 if (mLastQueryResult.mBeginIndex <= totalIndex && mLastQueryResult.mEndIndex >= totalIndex)
 {
 return mLastQueryResult;
 }
 }
 int low = 0;
 int high = count - 1;
 KeyData data = null;
 while (low <= high)
 {
 int mid = (low + high) / 2;
 data = mTreeItemDataList[mid];
 if (data.mBeginIndex <= totalIndex && data.mEndIndex >= totalIndex)
 {
 mLastQueryResult = data;
 return data;
 }
 else if (totalIndex > data.mEndIndex)
 {
 low = mid + 1;
 }
 else
 {
 high = mid - 1;
 }
 }
 return null;
 }
 void UpdateAllTreeItemDataIndex()
 {
 if (mIsDirty == false)
 {
 return;
 }
 mLastQueryResult = null;
 mIsDirty = false;
 int count = mTreeItemDataList.Count;
 if (count == 0)
 {
 return;
 }
 KeyData data0 = mTreeItemDataList[0];
 data0.mBeginIndex = 0;
 data0.mEndIndex = (data0.mIsExpand ? data0.mChildCount : 0);
 int curEnd = data0.mEndIndex;
 for (int i = 1; i < count; ++i)
 {
 KeyData data = mTreeItemDataList[i];
 data.mBeginIndex = curEnd + 1;
 data.mEndIndex = data.mBeginIndex + (data.mIsExpand ? data.mChildCount : 0);
 curEnd = data.mEndIndex;
 }
 }
 public KeyData GetTreeItem(int treeIndex)
 {
 if (treeIndex < 0 || treeIndex >= mTreeItemDataList.Count)
 {
 return null;
 }
 return mTreeItemDataList[treeIndex];
 }
 public void OnJumpBtnClicked(int itemIndex)
 {
 // int itemIndex = 0;
 int childIndex = 0;
 int finalIndex = 0;
 if (childIndex < 0)
 {
 childIndex = 0;
 }
 KeyData itemCountData = GetTreeItem(itemIndex);
 if (itemCountData == null)
 {
 return;
 }
 int childCount = itemCountData.mChildCount;
 if (itemCountData.mIsExpand == false || childCount == 0 || childIndex == 0)
 {
 finalIndex = itemCountData.mBeginIndex;
 }
 else
 {
 if (childIndex > childCount)
 {
 childIndex = childCount;
 }
 if (childIndex < 1)
 {
 childIndex = 1;
 }
 finalIndex = itemCountData.mBeginIndex + childIndex;
 }
 mLoopListView.MovePanelToItemIndex(finalIndex, 0);
 }
 
 
 public void Init()
 {
 int Index = 0;
 foreach (string Value in Tags)
 {
 GameObject go = Instantiate(Tag_Prefab, Right_Content);
 go.name = "Tag-" + Value;
 Tag_Item tag_Item = go.GetComponent<Tag_Item>();
 tag_Item.Select_Text = Select_Text;
 tag_Item.Init(Value);
 tag_Item.Index = Index;
 tag_Item.KeyStr = Value;
 tag_Item.listText = this;
 Index += 1;
 }
 }
 
 
}
 
public class CityData
{
 public string Key;
 public List<string> Value;
}

這里提供 源碼下載  unity版本2019.4.6 低版本也可以打開(kāi)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C# WinForm-Timer控件的使用

    C# WinForm-Timer控件的使用

    這篇文章主要介紹了C# WinForm-Timer控件的使用,幫助大家更好的理解和學(xué)習(xí)c# winform,感興趣的朋友可以了解下
    2020-11-11
  • C#生成不重復(fù)隨機(jī)字符串類

    C#生成不重復(fù)隨機(jī)字符串類

    這篇文章主要介紹了C#生成不重復(fù)隨機(jī)字符串類,涉及C#隨機(jī)數(shù)與字符串的操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • C# 常用不同日志庫(kù)的區(qū)別與示例解析

    C# 常用不同日志庫(kù)的區(qū)別與示例解析

    C# 作為一種流行的編程語(yǔ)言,有許多優(yōu)秀的日志庫(kù)可供選擇,本文將介紹一些常見(jiàn)的 C# 日志庫(kù),包括 NLog、log4net、Serilog 和 Microsoft.Extensions.Logging,并通過(guò)示例展示它們的使用方法及區(qū)別,感興趣的朋友一起看看吧
    2024-06-06
  • C#控制鍵盤(pán)按鍵的常用方法

    C#控制鍵盤(pán)按鍵的常用方法

    這篇文章主要介紹了C#控制鍵盤(pán)按鍵的常用方法,涉及C#針對(duì)鍵盤(pán)大寫(xiě)、滾動(dòng)、數(shù)字的開(kāi)啟與鎖定等功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-05-05
  • WPF自定義實(shí)現(xiàn)雷達(dá)圖控件的示例詳解

    WPF自定義實(shí)現(xiàn)雷達(dá)圖控件的示例詳解

    雷達(dá)圖用于表示不同內(nèi)容的占比關(guān)系,在項(xiàng)目中有廣泛的應(yīng)用,但是目前未曾有封裝良好的雷達(dá)圖控件,所以本文分享了如何封裝一個(gè)通用的雷達(dá)圖控件,希望對(duì)大家有所幫助
    2023-08-08
  • C#多線程系列之任務(wù)基礎(chǔ)(三)

    C#多線程系列之任務(wù)基礎(chǔ)(三)

    本文詳細(xì)講解了C#多線程的任務(wù)基礎(chǔ),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • Winform跨線程操作的簡(jiǎn)單方法

    Winform跨線程操作的簡(jiǎn)單方法

    線程間操作無(wú)效:從不是創(chuàng)建控件“l(fā)abel1”的線程訪問(wèn)它
    2013-04-04
  • c#用for語(yǔ)句輸出一個(gè)三角形的方法

    c#用for語(yǔ)句輸出一個(gè)三角形的方法

    這篇文章主要介紹了c#用for語(yǔ)句輸出一個(gè)三角形的方法,可實(shí)現(xiàn)只用一個(gè)for語(yǔ)句來(lái)輸出三角形的功能,需要的朋友可以參考下
    2015-06-06
  • C#中的Action、Func和Predicate如何使用

    C#中的Action、Func和Predicate如何使用

    這篇文章主要給大家介紹了關(guān)于C#中Action、Func和Predicate如何使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • C#串口通信工具類的封裝

    C#串口通信工具類的封裝

    這篇文章主要為大家詳細(xì)介紹了C#串口通信工具類封裝,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02

最新評(píng)論