网上有两个常用的方法,我先用了第一种。
第一种方法:
需要注意三点,首先导入system.window.Forms.dll库,导进去后一定记得要修改playersetting下的optimization->API compatibility level为.NET 2.0,至于为什么改成这样,可以参考unity3d 的解释:http://game.ceeger.com/Manual/MobileDotnet.html。
还要注意一点:加载的本地图片地址一定不能带有中文路径
另外,www新建的时候要加上“file://” + url;
WWW www = new WWW("file://" + url); //注意要加上"file://"
只需要一个脚本,其中代码如下:
using UnityEngine;
using System.Collections;
using System.Windows.Forms;
using System.IO;
public class UploadImg: MonoBehaviour {
public Texture2D img = null;
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 100, 20), "选择文件"))
{
OpenFileDialog od = new OpenFileDialog();
od.Title = "请选择头像图片";
od.Mult