using UnityEngine;using System.Collections;using System.Collections.Generic;
public class ListPX : MonoBehaviour{ public List<Texture> ObjList; //目标存储数组 private Dictionary<int, Texture> ObjDir; //临时存储字典,里面键值对对应的是图片名字和图片资源 public string gtName = "Four Areas_"; //统一源文件的共同名字
//快捷菜单 [ContextMenu("PaiXu")] public void PaiXu() { //先把图片名字剔除成123456数字,使用name.Substring(index,length); ObjDir = new Dictionary<int, Texture>(); ObjDir.Clear(); for (int i = 0; i < ObjList.Count; i++) { int nameLength = gtName.Length; Debug.LogError(nameLength); string _name = ObjList[i].name.Substring(nameLength, ObjList[i].name.Length - nameLength); ObjDir.Add(int.Parse(_name), ObjList[i]); Debug.LogError(int.Parse(_name)); }
//利用之前存储在字典内的键值对进行排序,重新排序 for (int i = 0; i < ObjList.Count; i++) { int min = 9999999; Texture texture = null; foreach (var item in ObjDir) { if (item.Key < min) { min = item.Key; texture = item.Value; } }
if (texture == null) Debug.LogError("error null!"); else { ObjDir.Remove(min); ObjList[i] = texture; }
} } }
转载于:https://www.cnblogs.com/weizai1993/p/6364632.html
