读取文件夹内容并显示到UGUI

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;


public class TestCreateText : MonoBehaviour {


    public GameObject prefabText;


    public string loadPath;


    public int i;
    // Use this for initialization
    void Start () {
        
        DirectoryInfo folder = new DirectoryInfo(loadPath);
        foreach (FileInfo file in folder.GetFiles())
        {
            GameObject te = Instantiate(prefabText);
            i += 1;
            te.name = file.Name;
            te.transform.parent = this.gameObject.transform;
            te.transform.localScale = new Vector3(1, 1, 1);
            te.GetComponent<Text>().text = file.Name;
        }
        gameObject.GetComponent<RectTransform>().offsetMin = new Vector2(GetComponent<RectTransform>().offsetMin.x, -i * 30 + 180);
    }
}
博主设置当前文章不允许评论。

没有更多推荐了,返回首页