Unity 读取本地文件夹图片

下面脚本实现的功能:

1.将本地图片(PNG和JPG)加载到UGUI上的Button的Image

Unity 读取本地文件夹图片_第1张图片

2.用Scroll View组件自动排列

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

public class Choose : MonoBehaviour
{
    private GameObject canvas;
    private Button _btn;
    private GameObject button;


    private List images = new List();

    void Start()
    {
        canvas = GameObject.Find("Canvas/Scroll View/Viewport/Content");

       
        load();

        for (int i = 0; i < images.Count; i++)
        {
            button = new GameObject("Button" + i, typeof(Button), typeof(RectTransform), typeof(Image));  //创建一个GameObject 加入Button组件

            button.transform.SetParent(this.canvas.transform);  //把Canvas设置成Button的父物体

            _btn = button.GetComponent

@Liam:有用→收藏→关注   听说长得好看的人都这么做!

你可能感兴趣的:(Unity)