最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

先看一下效果

這里用到了 SuperScrollView 這個插件 來實現(xiàn)功能

ListText.cs  // 核心控制類  代碼寫的比較隨意 大概的功能已經(jīng)實現(xiàn),需要根據(jù)實際需要進行優(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 + "測試");
 
 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 低版本也可以打開

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

相關(guān)文章

  • C#裝箱與拆箱操作的深入講解

    C#裝箱與拆箱操作的深入講解

    這篇文章主要給大家介紹了關(guān)于C#裝箱與拆箱操作的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Unity實現(xiàn)局域網(wǎng)聊天室功能

    Unity實現(xiàn)局域網(wǎng)聊天室功能

    這篇文章主要為大家詳細(xì)介紹了Unity實現(xiàn)局域網(wǎng)聊天室功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 利用C#與PLC通信實現(xiàn)設(shè)備遠(yuǎn)程控制與管理

    利用C#與PLC通信實現(xiàn)設(shè)備遠(yuǎn)程控制與管理

    PLC是工業(yè)自動化中用于控制機械設(shè)備、生產(chǎn)線等的核心設(shè)備,通過與PLC的通信,我們可以實現(xiàn)設(shè)備的遠(yuǎn)程監(jiān)控、數(shù)據(jù)采集等功能,C#作為一種現(xiàn)代化的編程語言,能夠非常方便地與PLC進行通信,本文將介紹如何利用C#與PLC進行通信,并實現(xiàn)設(shè)備的遠(yuǎn)程控制與管理
    2025-02-02
  • C#播放音頻文件的詳細(xì)步驟

    C#播放音頻文件的詳細(xì)步驟

    這篇文章主要介紹了C#播放音頻文件的詳細(xì)步驟,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-01-01
  • 為IObservable實現(xiàn)自己的運算符(詳解)

    為IObservable實現(xiàn)自己的運算符(詳解)

    下面小編就為大家?guī)硪黄獮镮Observable實現(xiàn)自己的運算符(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • C#控件閃爍的解決方法

    C#控件閃爍的解決方法

    這篇文章主要介紹了C#控件閃爍的解決方法,涉及SetStyle函數(shù)的使用技巧,需要的朋友可以參考下
    2015-01-01
  • C#接口在派生類和外部類中的調(diào)用方法示例

    C#接口在派生類和外部類中的調(diào)用方法示例

    這篇文章主要介紹了C#接口在派生類和外部類中的調(diào)用方法,結(jié)合實例形式分析了C#接口的定義與具體使用方法,需要的朋友可以參考下
    2017-02-02
  • C#知識整理

    C#知識整理

    本文主要介紹了C#的相關(guān)知識。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • C#使用泛型隊列Queue實現(xiàn)生產(chǎn)消費模式

    C#使用泛型隊列Queue實現(xiàn)生產(chǎn)消費模式

    這篇文章介紹了C#使用泛型隊列Queue實現(xiàn)生產(chǎn)消費模式的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-10-10
  • c#循環(huán)左移字符示例

    c#循環(huán)左移字符示例

    這篇文章主要介紹了c#循環(huán)左移字符示例,需要的朋友可以參考下
    2014-04-04

最新評論

麦盖提县| 梁山县| 白山市| 元氏县| 德阳市| 洛扎县| 张北县| 嘉兴市| 苏州市| 增城市| 苏尼特左旗| 三台县| 额济纳旗| 阿克陶县| 朝阳县| 调兵山市| 新安县| 阿坝| 广丰县| 萍乡市| 大渡口区| 边坝县| 阳谷县| 长宁县| 西充县| 中江县| 含山县| 康马县| 柘荣县| 德清县| 改则县| 蚌埠市| 香河县| 保定市| 都安| 成安县| 新疆| 吉水县| 房产| 正镶白旗| 峨边|