Last active
April 26, 2020 21:10
-
-
Save burrussmp/ea8c35b55ac4e0038bd68607bb53a14b to your computer and use it in GitHub Desktop.
GET face data from server and parse it into a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UnityWebRequest www = UnityWebRequest.Get("http://SERVERIP:PORT/data"); | |
yield return www.SendWebRequest(); | |
Debug.Log(www.responseCode); | |
if(www.isNetworkError || www.isHttpError || www.responseCode == 500) { | |
GameObject myObject = GameObject.Find("ARCamera"); | |
myObject.GetComponent<Buttons>().showError("Need to Capture Front and Side!"); | |
yield return new WaitForSeconds(3); | |
myObject.GetComponent<Buttons>().clearError(); | |
} | |
else { | |
// Show results as text | |
Debug.Log(www.downloadHandler.text); | |
string inputTextString = www.downloadHandler.text; | |
int next = 0; | |
var list = new List<List<float>>(); | |
while (next != -1){ | |
int start = inputTextString.IndexOf('N',next); | |
int num_delimiter = inputTextString.IndexOf(',',start); | |
next = inputTextString.IndexOf('N',start+1); | |
int num_samples = Int16.Parse(inputTextString.Substring(start+1,num_delimiter-start-1)); | |
string sub_input; | |
if (next != -1){ | |
sub_input = inputTextString.Substring(num_delimiter+1,next-num_delimiter-1); | |
} else { | |
sub_input = inputTextString.Substring(num_delimiter+1,inputTextString.Length-num_delimiter-1); | |
} | |
sub_input = sub_input.Replace("[",""); | |
sub_input = sub_input.Replace("]",""); | |
var myList = sub_input.Split(',').Select(Convert.ToSingle).ToList(); | |
myList.Add(Convert.ToSingle(num_samples)); | |
list.Add(myList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment