سورس ارسال داده های فرم به وب سرور
شنبه, ۴ مهر ۱۳۹۴، ۱۰:۴۲ ب.ظ
منبع:gameover.blog.ir
(اسم اسکریپت باید طبق کلاس داخلی، WWWFormImage باشه.
ارسال داده های فرم به وب سرور :
کد سیشارپ:
using UnityEngine; using System.Collections; public class WWWFormImage : MonoBehaviour { public string screenShotURL= "http://www.my-server.com/cgi-bin/screenshot.pl"; // Use this for initialization void Start () { StartCoroutine(UploadPNG()); } IEnumerator UploadPNG() { // We should only read the screen after all rendering is complete yield return new WaitForEndOfFrame(); // Create a texture the size of the screen, RGB24 format int width = Screen.width; int height = Screen.height; var tex = new Texture2D( width, height, TextureFormat.RGB24, false ); // Read screen contents into the texture tex.ReadPixels( new Rect(0, 0, width, height), 0, 0 ); tex.Apply(); // Encode texture into PNG byte[] bytes = tex.EncodeToPNG(); Destroy( tex ); // Create a Web Form WWWForm form = new WWWForm(); form.AddField("frameCount", Time.frameCount.ToString()); form.AddBinaryData("fileUpload", bytes, "screenShot.png", "image/png"); // Upload to a cgi script WWW w = new WWW(screenShotURL, form); yield return w; if (!string.IsNullOrEmpty(w.error)) { print(w.error); } else { print("Finished Uploading Screenshot"); } } }به متغیر screenShotURL آدرس صفحه ی دریافت کننده php یا ... رو بدید.
۹۴/۰۷/۰۴