开局先吐槽,百度真不是个东西,广告一大堆,要找的东西永远藏在后面,恶心,恶心。
但是他喵的百度的东西杂乱无章,对于前面没大腿趟过路并分享过经验的东西,东捡一枝,西拿一叶,反而能构建出自己的理解,唉。
首先上官网nas的技术介绍网址:华为家庭存储|说明书|售后维修价格-华为官网
注意:这里上传用到了NativeGallery插件,一个打开安卓文件夹选择文件的插件,用NativeGallery不要用中文路径,这插件不支持中文,这问题坑了我几天
前提:手机、NAS、PC都在同一局域网。
流程PC:
1.打开“控制面板”,
2.打开控制面板的“程序和功能”,
3.打开程序和功能的“启用或关闭Windows功能”
4.找到“xxx 文件共享支持”并勾上,
5.重启。
流程手机:
1.打开华为的“智慧生活”App,选择设备栏;
2.扫描添加好nas设备,点进设备;
3选择应用服务,再选择下面的网络邻居,打开共享权限。
using UnityEngine;
using System.IO;
using System;
using UnityEngine.UI;
using System.Runtime.InteropServices;
using System.Collections;
using System.Net;
using NASLibrary;
public class ImageUploader : MonoBehaviour
{
public string ipAddress; // 共享文件夹所在电脑的 IP 地址
public string shareFolderPath; // 共享文件夹路径
//public string userName; // 共享文件夹登录用户名
//public string password; // 共享文件夹登录密码
public RawImage rimg;
public Text txt;
public Texture2D tex = null;
private string texPath = null;
private void Start()
{
//开启安卓的读写权限,注意,这里的坑花了我三天时间测试找bug,fk
//UnityEngine.Android.Permission.RequestUserPermission(UnityEngine.Android.Permission.ExternalStorageRead);
//UnityEngine.Android.Permission.RequestUserPermission(UnityEngine.Android.Permission.ExternalStorageWrite);
rimg.texture = tex;
}
public void UploadImageEvent()
{
txt.text += "开始上传;";
// 在图片库中选择一张图片
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
{
texPath = path; txt.text += texPath;
UploadImage();
}, "Select an image", "image/*");
}
private void ChooseImage()
{
}
private void UploadImage()
{
tex = new Texture2D(2, 2);
byte[] fileBuffer = File.ReadAllBytes(texPath);
tex.LoadImage(fileBuffer);
tex.Apply();
string targetPath = @"\\" + ipAddress + @"\" + shareFolderPath + @"\lallalTexture.jpg";
byte[] imageBuffer = tex.EncodeToJPG();
File.WriteAllBytes(targetPath, imageBuffer);
txt.text += targetPath;
Debug.Log("上传成功");
}
//上传都搞定了,下载就懒得说了,路径跑通了,有了路径,下载就跟普通的局域网共享文件夹的资源加载一样
}