Skip to content

Instantly share code, notes, and snippets.

@bholota
Last active November 24, 2015 21:31
Show Gist options
  • Select an option

  • Save bholota/e459577cd07f0efd76d7 to your computer and use it in GitHub Desktop.

Select an option

Save bholota/e459577cd07f0efd76d7 to your computer and use it in GitHub Desktop.
Fire and forget Unity3d remote logger for mobile (Android/iOS) devices
using UnityEngine;
using System.Collections;
public class Logger : MonoBehaviour
{
public static string URL = "XXX";
void Start()
{
if (Input.location.isEnabledByUser)
{
Input.location.Start();
}
}
public void AndroidLog(string message)
{
StartCoroutine(uploadLog(message));
}
private IEnumerator uploadLog(string msg)
{
string deviceInfo = SystemInfo.deviceModel + " " + SystemInfo.deviceName + " " + SystemInfo.deviceType;
string lastLocation = null;
if (Input.location.status == LocationServiceStatus.Running)
{
lastLocation = Input.location.lastData.latitude + "," + Input.location.lastData.longitude;
}
WWWForm form = new WWWForm();
form.AddField("message", deviceInfo + " " + lastLocation + " " + msg);
WWW w = new WWW(URL, form);
yield return w;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment