입니다. 그래서 지금은 서버에 HTTP 요청을하고 있지만 일부 JSON 데이터와 함께 GET 요청을 보내야합니다. 내가 지금하고있는 일은 "일"하지만, 각 요청이 거의 15FPS까지 떨어지기 때문에 끔찍한 일이다. 여기 내 코드가있다.Unity에서 서버에 GET 요청을하는 가장 좋은 방법은
private IEnumerator SetJsonData()
{
// Make a new web request with the .net WebRequest
request = WebRequest.Create(elk_url);
yield return null;
request.ContentType = "application/json";
request.Method = "POST";
buffer = Encoding.GetEncoding("UTF-8").GetBytes(queryString);
// Put this yield here so that I get higher FPS
yield return null;
requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
// Again this is about getting higher FPS
yield return null;
response = (HttpWebResponse)request.GetResponse();
// Wait until we have all of the data we need from the response to continue
yield return requestStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
reader = new StreamReader(requestStream);
// Set my string to the response from the website
JSON_String = reader.ReadToEnd();
yield return null;
// Cleanup the streams and the response.
reader.Close();
requestStream.Close();
response.Close();
yield return null;
// As long as we are not null, put this in as real C# data
if (JSON_String != null)
{
// Wait until we finish converting the string to JSON data to continue
yield return StartCoroutine(StringToJson());
}
if(dataObject != null)
{
// Send the data to the game controller for all of our hits
for(int i = 0; i < dataObject.hits.hits.Length; i++)
{
StartCoroutine(
gameControllerObj.CheckIpEnum(dataObject.hits.hits[i]._source));
}
}
// As long as we didn't say to stop yet
if (keepGoing)
{
yield return null;
// Start this again
StartCoroutine(SetJsonData());
}
}
: 실제로 요청을 할 내가 설정 한 공동 coutine 여기
void Start()
{
queryString = File.ReadAllText(Application.streamingAssetsPath +"/gimmeData.json");
StartCoroutine(SetJsonData());
}
됩니다 : 여기
{
"query": {
"match_all": {}
},
"size": 1,
"sort": [{
"@timestamp": {
"order": "desc"
}
}]
}
내 시작 방법 : 여기
내 GET 쿼리입니다
FPS가 이미 개선 된 때문에 "수익률 반환 null"이 있습니다.
어떻게 최적화 할 수 있습니까? 거기에 GET 데이터를 보낼 수있는 웹 요청을 만드는 더 좋은 방법이 있습니까? UnityWebRequest가 문제라는 것을 알고 있습니다. 그렇다고해서 제가 가지고있는 JSON 데이터를 보낼 수는 없습니다.