資源簡(jiǎn)介
Unity截圖并通過(guò)php把文件上傳圖片到服務(wù)器,并通過(guò)動(dòng)態(tài)生成html實(shí)現(xiàn)圖片分享。

代碼片段和文件信息
using?UnityEngine;
using?System.Collections;
public?class?SavePicture?:?MonoBehaviour?{
string?url?=?“http://localhost/UpLoad/UnityUpload.php“;
string?path;
public???Material???image;
void?Start()
{
path=Application.dataPath?+“/wukuaTurret.jpg“;
}
void?OnGUI()
{
if(GUI.Button(new?Rect(100100100100)“SavePic“))
{
Debug.Log(path);
StartCoroutine(getTexture2d());
}
}
IEnumerator?getTexture2d()??{?
yield?return?new?WaitForEndOfframe();?
int?width?=?Screen.width;
int?height?=?Screen.height;
Texture2D?tex?=?new?Texture2D(width?height?TextureFormat.RGB24?false);
tex.ReadPixels(new?Rect(0?0?width?height)?0?0false);
tex.Apply();
byte[]?bytes?=?tex.EncodeToPNG();
WWWForm?form?=?new?WWWForm?();
form.AddField(“Name““pic1“);
form.AddBinaryData?(“post“?bytes);
WWW?www?=?new?WWW?(urlform);
StartCoroutine?(PostData?(www));
Destroy(tex);
System.IO.File.WriteAllBytes(path?bytes);?
}?
IEnumerator?PostData(WWW?www)
{
yield?return?www;
Debug.Log(www.text);
}
IEnumerator???getCaptureFf(){
path=Application.persistentDataPath;
Debug.Log(“path??“+path);
WWW www=new?WWW(“file://“+path+“/Screenshot.png“);?
yield??return?www;?
image.mainTexture=www.texture;
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-12-02?23:23??UnityToPhpSavePicture\
?????目錄???????????0??2014-12-02?23:23??UnityToPhpSavePicture\Php\
?????目錄???????????0??2014-12-02?23:37??UnityToPhpSavePicture\Php\UpLoad\
?????文件????????1693??2014-12-02?18:40??UnityToPhpSavePicture\Php\UpLoad\UnityUpload.php
?????文件?????????605??2014-12-01?12:30??UnityToPhpSavePicture\Php\UpLoad\Upload.html
?????文件????????1337??2014-12-02?18:40??UnityToPhpSavePicture\Php\UpLoad\dest_page.html
?????文件????????1324??2014-12-02?18:35??UnityToPhpSavePicture\Php\UpLoad\temp.html
?????目錄???????????0??2014-12-02?23:22??UnityToPhpSavePicture\Php\UpLoad\upload\
?????文件????????4860??2014-12-02?15:02??UnityToPhpSavePicture\Php\UpLoad\upload\pic1.png
?????文件????????4860??2014-12-02?18:40??UnityToPhpSavePicture\Php\UpLoad\upload\pic2.png
?????目錄???????????0??2014-12-02?23:23??UnityToPhpSavePicture\Unity\
?????文件????????3069??2014-12-02?11:09??UnityToPhpSavePicture\Unity\Assembly-CSharp-vs.csproj
?????文件????????3069??2014-12-02?11:09??UnityToPhpSavePicture\Unity\Assembly-CSharp.csproj
?????目錄???????????0??2014-12-02?23:26??UnityToPhpSavePicture\Unity\Assets\
?????文件????????1285??2014-12-02?11:12??UnityToPhpSavePicture\Unity\Assets\SavePicture.cs
?????文件?????????178??2014-12-01?22:43??UnityToPhpSavePicture\Unity\Assets\SavePicture.cs.me
?????文件???????17100??2014-12-02?15:02??UnityToPhpSavePicture\Unity\Assets\SavePicture.unity
?????文件??????????90??2014-12-01?22:43??UnityToPhpSavePicture\Unity\Assets\SavePicture.unity.me
?????文件????????4860??2014-12-02?15:02??UnityToPhpSavePicture\Unity\Assets\wukuaTurret.jpg
?????文件?????????981??2014-12-02?15:01??UnityToPhpSavePicture\Unity\Assets\wukuaTurret.jpg.me
?????目錄???????????0??2014-12-02?23:22??UnityToPhpSavePicture\Unity\Library\
?????文件????????4120??2014-12-01?22:42??UnityToPhpSavePicture\Unity\Library\AnnotationManager
?????文件???????????6??2014-12-01?22:43??UnityToPhpSavePicture\Unity\Library\AssetImportState
?????文件????????5284??2014-12-02?15:02??UnityToPhpSavePicture\Unity\Library\AssetServerCacheV3
?????文件???????14336??2014-12-02?15:01??UnityToPhpSavePicture\Unity\Library\AssetVersioning.db
?????文件???????????0??2014-12-01?22:42??UnityToPhpSavePicture\Unity\Library\BuildPla
?????文件????????4120??2014-12-01?22:42??UnityToPhpSavePicture\Unity\Library\BuildSettings.asset
?????文件???????37564??2014-12-02?15:02??UnityToPhpSavePicture\Unity\Library\CurrentLayout.dwlt
?????文件????????4176??2014-12-01?22:42??UnityToPhpSavePicture\Unity\Library\EditorUserBuildSettings.asset
?????文件????????4136??2014-12-01?22:42??UnityToPhpSavePicture\Unity\Library\EditorUserSettings.asset
?????文件???????????0??2014-12-02?15:02??UnityToPhpSavePicture\Unity\Library\FailedAssetImports.txt
............此處省略308個(gè)文件信息
評(píng)論
共有 條評(píng)論