ارسال داده های فرم به وب سرور به زبان سیشارپ در یونیتی
جمعه, ۲۴ مهر ۱۳۹۴، ۱۱:۳۶ ب.ظ
منبع :gameover.blog.ir
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 یا ... رو بدید.(اون پیشفرض pl داده که یه سایت رو معرفی کرده به زبان تحت سرور perl ساخته شده.پسوند فایل های پرل pl هستش)
۹۴/۰۷/۲۴
سلام میشه یه توضیح کامل درباره این کد بدین که چیکار میکنه و چطوری استفاده کنیم؟