最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity3D選擇本地圖片并加載

 更新時間:2021年10月12日 16:36:40   作者:測試貓  
這篇文章主要為大家詳細介紹了Unity3D選擇本地圖片并加載,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Unity3D選擇本地圖片并加載的具體代碼,供大家參考,具體內(nèi)容如下

①找到System.Windows.Forms.dll:在unity的安裝目錄中找到它,如 

E:\ProgramFiles(x86)\Unity\Editor\Data\Mono\lib\mono\2.0

②設置.NET 2.0集:Untiy默認是.NET 2.0 Subset。在Edit->Project Settings->Player->OtherSettings中修改

③任意打開一項目,新建Plugins文件夾,將找到的System.Windows.Forms.dll復制進去工程文件中(Project)

using UnityEngine;
using System.Collections;
using System;
using System.Windows.Forms;
using System.IO;
using UnityEngine.UI;
public class AddHead : MonoBehaviour {
 private Texture2D img=null;
 public Image image;
 public Sprite sprite;
// Use this for initialization
 void Start () {
 }
 // Update is called once per frame
 void Update () {
 }
 /*void OnGUI(){
 if (GUI.Button (new Rect (0, 0, 100, 20), "選擇文件")) {
 }*/
 public void addhead(){
 OpenFileDialog od=new OpenFileDialog();
 od.Title="請選擇頭像圖片";
 od.Multiselect=false;
 od.Filter="圖片文件(*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp";
 if(od.ShowDialog()==DialogResult.OK){
 //Debug.Log(od.FileName);
 StartCoroutine(GetTexture("file://"+od.FileName));
 }
 /*if (img != null) {
 //GUI.DrawTexture(new Rect(0,20,img.width,img.height),img);
 image.sprite=sprite;
 }*/
 }
 IEnumerator GetTexture(string url){
 WWW www = new WWW (url);
 yield return www;
 if (www.isDone && www.error == null) {
 img=www.texture;
 sprite=Sprite.Create(img,new Rect(0,0,img.width,img.height),new Vector2(0.5f,0.5f)); 
 image.sprite=sprite;
 //Debug.Log(img.width+" "+img.height);
 byte[] date=img.EncodeToPNG();
 }
 }
}

為按鈕綁定一個addhead()的方法

在編輯器運行,當出現(xiàn)此彈窗,確定忽略即可。發(fā)布成桌面客戶端是不會有這個彈窗的。

看運行效果

——》——》

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

文昌市| 铜山县| 万荣县| 分宜县| 吉木乃县| 维西| 昔阳县| 建昌县| 正定县| 江山市| 无极县| 郁南县| 尤溪县| 瑞金市| 襄汾县| 新平| 隆安县| 鄂托克前旗| 古田县| 绥棱县| 铅山县| 广灵县| 土默特左旗| 荣成市| 云安县| 团风县| 玉环县| 阿合奇县| 西平县| 白河县| 安西县| 望城县| 贺州市| 乌兰察布市| 晋城| 专栏| 千阳县| 温州市| 英德市| 赞皇县| 朝阳市|