using UnityEngine; using NativeFileBrowser; using System.Collections.Generic; using System.Linq; using System.IO; using ToneTuneToolkit.Common; public class ImageLoader : SingletonMaster { /// /// 弹窗获取图片路径 /// /// 图片路径 public static string GetImagePath() { string title = "Select Image"; ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Image Files", "png", "jpg", "jpeg"), new ExtensionFilter("JPG ", "jpg", "jpeg"), new ExtensionFilter("PNG ", "png"), }; // 标题、类型筛选器、是否允许选择多个文件 List paths = StandaloneFileBrowser.OpenFilePanel(title, extensions, false).ToList(); if (paths.Count == 0) { return null; } // Debug.Log(paths[0]); return paths[0]; } /// /// 获取图片 /// /// /// public static Texture2D GetImageTexture(string path) { if (!File.Exists(path)) { return null; } byte[] bytes = File.ReadAllBytes(path); Texture2D texture2D = new Texture2D(2, 2); texture2D.LoadImage(bytes); texture2D.Apply(); return texture2D; } }