1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
我已經(jīng)把它們放在一起了,現(xiàn)在這對(duì)我來說非常有用:
注意:我注釋掉了與示例無關(guān)的所有內(nèi)容(或者您沒有添加到問題代碼中的內(nèi)容)
public class FilesExample : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
ListMap();
}
public static FileSystemInfo[] info;
public void ListMap()
{
/*
* If you already called this before you already have child objects
* So I would destroy the old ones before instantiating new ones
*/
//foreach(Transform child in Parentcontent)
foreach(Transform child in transform)
{
Destroy(child.gameObject);
}
//panellist.SetActive(true);
/*
* preferred to use streamingAssetsPath for testing
*/
//var mainpath = Application.persistentDataPath;
var mainpath = Application.streamingAssetsPath;
var dir = new DirectoryInfo(mainpath);
info = dir.GetFileSystemInfos("*.json").OrderBy(i => i.CreationTime).ToArray();
for (var i = 1; i <= info.Length; i++)
{
/*
* Instead of instantiating I simply created new empty objects
* just as example
*/
//var lisobj = Instantiate(prefabpanellist);
var lisobj = new GameObject(i + " " + info[i - 1].Name);
//lisobj.transform.SetParent(Parentcontent);
lisobj.transform.SetParent(transform);
// Though I'm sure this should already have the correct order
// you could still do SetLastSibling to move the
// created/instantiated object to the bottom
lisobj.transform.SetAsLastSibling();
//number.text = i.ToString();
//mapnamedb.text = info[i - 1].Name;
/*
* NOTE: I would simply do the buttons thing in the same
* loop. That saves you a lot of storing and accessing lists
*/
//var index = i;
//var button = lisobj.GetComponentInChildren<Button>(true);
//button.onClick.AddListener(() => Deleteinformation(index));
}
}
public void Deleteinformation(int index)
{
Debug.Log("Index is " + index);
Debug.Log("Path is " + info[index].FullName);
File.Delete( info[index].FullName);
// update the scene list
ListMap();
}
}
結(jié)果
驅(qū)動(dòng)器上的文件按名稱排序
驅(qū)動(dòng)器上的文件按創(chuàng)建日期排序
導(dǎo)致 Unity 按創(chuàng)建日期排序
- 1 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報(bào)