showAndroid.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class showAndroid : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. }
  11. public Text text;
  12. public RawImage img;
  13. public void showImage()
  14. {
  15. NativeGallery.GetImageFromGallery((string path) => {
  16. Debug.Log("Image path: " + path);
  17. if (path != null)
  18. {
  19. text.text = path;
  20. // 此Action为选取图片后的回调,返回一个Texture2D
  21. Texture2D texture = NativeGallery.LoadImageAtPath(path, -1);
  22. if (texture == null)
  23. {
  24. Debug.Log("Couldn't load texture from " + path);
  25. return;
  26. }
  27. Debug.Log(texture.name);
  28. img.texture = texture;
  29. }
  30. });
  31. }
  32. public void showVideo()
  33. {
  34. NativeGallery.GetVideoFromGallery((string path) => {
  35. Debug.Log("Video path: " + path);
  36. text.text = path;
  37. });
  38. }
  39. // Update is called once per frame
  40. void Update()
  41. {
  42. }
  43. }