Making an http call to your server is simple. When you create a new gate, it becomes instantly accessible. To communicate with your database, in a Unity application your server builds a comprehensive set of Calls that you can make to your Server to communicate with it
The General Protocol in C#
Here is an example of signing in.
/**
* Signs into login server by sending a POST Request
* and verifying the user delivered the correct
* credentials for access
*
* ******************************************************USERNAME/PASSWORD SIGN IN
* */
public void SignIn()
{
try
{
GameObject uName = GameObject.Find("Username");
GameObject pWord = GameObject.Find("Password");
InputField inputFieldU = uName.GetComponent<InputField>();
InputField inputFieldP = pWord.GetComponent<InputField>();
string logURL = BASEURL + "Login/";
//Debug.Log("URL: " + logURL);
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["a"] = inputFieldU.text;
data["b"] = inputFieldP.text;
var response = wb.UploadValues(logURL, "POST", data);
string responseInString = Encoding.UTF8.GetString(response);
//Debug.Log(responseInString); // DEBUG STATEMENT
if (responseInString.Equals("-1"))
{
error.text = "Password not correct for username provided";
error.gameObject.SetActive(true);
errorBack.gameObject.SetActive(true);
}
else if (responseInString.Equals("0"))
{
error.text = "User not found";
error.gameObject.SetActive(true);
errorBack.gameObject.SetActive(true);
}
else
{
setPlayerPreferences(responseInString);
PlayerPrefs.SetInt("registered", 2);
PlayerPrefs.Save();
SceneManager.LoadScene(mainMenuSceneString);
}
}
}
catch (Exception e)
{
// Debug.Log("LOGIN ERROR: " + e.Message);
}
}
This method can be abstracted to make communication even easier. All members get instant access to many free scripts as well as other exclusive offers!