当前位置:   article > 正文

Unity 上传自定义头像_unity 头像选择

unity 头像选择

使用NativeGallery插件

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class NewBehaviourScript : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. }
  11. // Update is called once per frame
  12. void Update()
  13. {
  14. }
  15. public RawImage head;
  16. public void TakePhoto(int maxSize = -1)
  17. {
  18. //调用插件自带接口,拉取相册,内部有区分平台
  19. NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
  20. {
  21. Debug.Log("Image path: " + path);
  22. if (path != null)
  23. {
  24. // 此Action为选取图片后的回调,返回一个Texture2D
  25. Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
  26. if (texture == null)
  27. {
  28. Debug.Log("Couldn't load texture from " + path);
  29. return;
  30. }
  31. Debug.Log(texture.name);
  32. head.texture = texture;//将选择的图片对我们的RawImage进行赋值
  33. }
  34. }, "选择图片", "image/png", maxSize);
  35. }
  36. }

安卓设备需要设置权限到外部储存卡 PlayerSetting-Player-OtherSetting-WritePermission-External

上传服务器 把图片转成字节上传就可以

项目下载https://download.csdn.net/download/qq_36715529/86882031

参照CSDN博主「YOLO_TO_GAME」的原创文章,链接https://blog.csdn.net/weixin_39706943/article/details/81196089

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/636950
推荐阅读
相关标签
  

闽ICP备14008679号