C# 从unity中的图库中选择多个图像

C# 从unity中的图库中选择多个图像,c#,android,unity3d,C#,Android,Unity3d,yasirkula提供的Android和iOS原生图库,可用于一次从图库中选择多幅图像下面是一个单幅图像选择的示例代码。请有人帮助您一次选择多幅图像。 private void PickImage( int maxSize ) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery( ( path ) => { Debug.Log( "Image path:

yasirkula提供的Android和iOS原生图库,可用于一次从图库中选择多幅图像下面是一个单幅图像选择的示例代码。请有人帮助您一次选择多幅图像。

private void PickImage( int maxSize )
{
    NativeGallery.Permission permission = NativeGallery.GetImageFromGallery( ( path ) =>
    {
        Debug.Log( "Image path: " + path );
        if( path != null )
        {
            // Create Texture from selected image
            Texture2D texture = NativeGallery.LoadImageAtPath( path, maxSize );
            if( texture == null )
            {
                Debug.Log( "Couldn't load texture from " + path );
                return;
            }

            // Assign texture to a temporary quad and destroy it after 5 seconds
            GameObject quad = GameObject.CreatePrimitive( PrimitiveType.Quad );
            quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
            quad.transform.forward = Camera.main.transform.forward;
            quad.transform.localScale = new Vector3( 1f, texture.height / (float) texture.width, 1f );

            Material material = quad.GetComponent<Renderer>().material;
            if( !material.shader.isSupported ) // happens when Standard shader is not included in the build
                material.shader = Shader.Find( "Legacy Shaders/Diffuse" );

            material.mainTexture = texture;

            Destroy( quad, 5f );

            // If a procedural texture is not destroyed manually, 
            // it will only be freed after a scene change
            Destroy( texture, 5f );
        }
    }, "Select a PNG image", "image/png" );

    Debug.Log( "Permission result: " + permission );
}
private void PickImage(int maxSize)
{
NativeGallery.Permission Permission=NativeGallery.GetImageFromGallery((路径)=>
{
Log(“映像路径:+path”);
if(路径!=null)
{
//从选定图像创建纹理
Texture2D纹理=NativeGallery.LoadImageAtPath(路径,最大尺寸);
如果(纹理==null)
{
Log(“无法从“+路径”加载纹理);
返回;
}
//将纹理指定给临时四边形,并在5秒后将其销毁
GameObject quad=GameObject.CreatePrimitive(PrimitiveType.quad);
quad.transform.position=Camera.main.transform.position+Camera.main.transform.forward*2.5f;
quad.transform.forward=Camera.main.transform.forward;
quad.transform.localScale=新矢量3(1f,texture.height/(float)texture.width,1f);
材质材质=quad.GetComponent().Material;
如果(!material.shader.isSupported)//在生成中不包括标准着色器时发生
material.shader=shader.Find(“遗留着色器/漫反射”);
material.main纹理=纹理;
破坏(方形,5f);
//如果未手动销毁程序纹理,
//它将仅在场景更改后释放
破坏(纹理,5f);
}
},“选择PNG图像”,“图像/PNG”);
Debug.Log(“权限结果:+权限”);
}

已经有了一种方法:因此(假设您的其余代码按预期工作),只需使用该方法,然后对结果进行迭代,如

NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((paths) =>
{
    foreach(var path in paths)
    {
        Debug.Log("Image path: " + path);
        if(path != null)
        {
            // Create Texture from selected image
            Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
            ....
        }
    }
}, "Select PNG images", "image/png");