Unity小結(jié)-1
1.Foldout在ListView中顯示混亂的問題處理
private HashSet<int> record = new HashSet<int>(); //展開的ItemIndex
ListView.itemsSourceChanged += () => { record.Clear(); }; //保證新的數(shù)據(jù)源不會(huì)沿用舊有的標(biāo)記信息
Foldout fo;? ?//在makeItem中用折頁的開關(guān)控制ItemIndex的記錄? ? ?
fo.RegisterValueChangedCallback((e) => {
if (e.newValue && !record.Contains(SelectIndex)) record.Add(SelectIndex);
else if (!e.newValue && record.Contains(SelectIndex)) record.Remove(SelectIndex);
});
fo.SetValueWithoutNotify(record.Contains(index)); //在bindItem的回調(diào)中根據(jù)展開登記表設(shè)置折頁的打開關(guān)閉。
2.Unity通過IO加載文件的相對(duì)路徑可以和Assets同級(jí)。(方便路徑設(shè)置)
3.SpriteRenderer或Particle的sort作用大于其所在Canvas,SortingGroup作用大于它們。
4.目錄文件是不區(qū)分大小寫的,即讀取和寫入時(shí),只要路徑在大寫或小寫上有一種情況一致,這兩個(gè)路徑就被視為一個(gè)路徑
5.ListView.makeItem回調(diào)中的style設(shè)置不一定有效,可以在ListView.bindItem中區(qū)設(shè)置
6.自定義的uitoolkit組件在ListView中可能大小無法正常匹配
6.當(dāng)ListView中的條目是動(dòng)態(tài)高度時(shí)(如Foldout),Virtualization Method選dynamic height
7.獲取資源顯示用小圖標(biāo)
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(data.assetPath, typeof(UnityEngine.Object));
Texture2D sprite = AssetPreview.GetMiniThumbnail(obj);
if (sprite == null) sprite = AssetPreview.GetMiniTypeThumbnail(obj.GetType());