unity 选择文件夹下所有png文件
时间: 2024-10-04 13:02:39 浏览: 100
在Unity中,如果你想要选择文件夹下的所有PNG文件,你可以通过脚本来实现。首先,在Unity项目中创建一个新的C#脚本,然后添加以下内容:
```csharp
using UnityEngine;
using System.IO;
public class SelectPNGFiles : MonoBehaviour
{
public string folderPath; // 文件夹路径
void Start()
{
if (!Directory.Exists(folderPath))
{
Debug.LogError("指定的文件夹路径不存在!");
return;
}
var pngFiles = Directory.GetFiles(folderPath, "*.png");
if (pngFiles.Length > 0)
{
foreach (var file in pngFiles)
{
Debug.Log($"找到文件:{file}");
// 这里可以添加对选中文件的操作,比如加载到游戏中、显示在UI上等
}
}
else
{
Debug.Log("未找到PNG文件.");
}
}
}
```
把这个脚本拖放到Unity场景中的任何GameObject上,然后在Inspector窗口设置`folderPath`为你需要选择PNG文件的文件夹路径。运行游戏后,它会检查并列出该目录下的所有PNG文件。
阅读全文
相关推荐


















