[英]How to call a method on server side from c#
我在堆棧溢出時得到此質量檢查- 如何從客戶端javascript函數調用服務器方法后面的代碼?
但是,它是從javascript調用的函數,如何從c#進行調用。 我使用unity3d開發了一個ios應用程序,我之前沒有做過。 有人知道怎么做嗎?
提前致謝。
后端如下所示。 網址:https:// {服務器地址} /注冊參數:
並返回:-user_id,int
我使用正確的參數運行服務器方法 ,如果參數正確,則返回int / user_id返回。
WWW unity3d類,這可能是您想要的。 WWW是
一個小的實用程序模塊,用於檢索URL的內容。
有關使用C#與服務器(PHP)進行交互的詳細信息,我建議您使用這個unitywiki鏈接 。 您將需要執行本教程建議的類似操作。
IEnumerator GetData()
{
gameObject.guiText.text = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);//highscoreURL this is ur url as u said
yield return hs_get;
if (hs_get.error != null)//checking empty or error response etc
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
您可以根據自己的規范定制的重置對象主要是WWW和Co-routine 。
表面上,將WWWForm
作為輔助參數添加到WWW
,然后將其post
到服務器。
using UnityEngine;
using System.Collections;
public class PostJsonDataScript : MonoBehaviour
{
// Use this for initialization
string Url;
void Start()
{
Url = "Url to the service";
PostData(100,"Unity");
}
// Update is called once per frame
void Update()
{
}
void PostData(int Id,string Name)
{
WWWForm dataParameters = new WWWForm();
dataParameters.AddField("Id", Id);
dataParameters.AddField("Name", Name);
WWW www = new WWW(Url,dataParameters);
StartCoroutine("PostdataEnumerator", Url);
}
IEnumerator PostdataEnumerator(WWW www)
{
yield return www;
if (www.error != null)
{
Debug.Log("Data Submitted");
}
else
{
Debug.Log(www.error);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.