
Unity 라이브러리 추천 - RestClient게임 엔진/Unity2024. 3. 24. 02:19
Table of Contents
RestClient
https://github.com/proyecto26/RestClient
GitHub - proyecto26/RestClient: 🦄 A Promise based REST and HTTP client for Unity 🎮
🦄 A Promise based REST and HTTP client for Unity 🎮 - proyecto26/RestClient
github.com
웹서버와 통신을 할때 조금 더 깔끔하고 편하게 코드를 짤 수있게 도와주는 라이브러리다.
코드를 조금 더 단촐하게 바꿀 수 있으며,
//그냥 사용할때
IEnumerator Start()
{
UnityWebRequest webRequest = UnityWebRequest.Get(url);
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
var data = JsonUtility.FromJson<User>(webRequest.downloadHandler.text);
Debug.Log(data.NickName);
}
else
{
Debug.Log("통신 실패!");
}
}
//라이브러리 사용
public void Request()
{
RestClient.Get(url).Then(res =>
{
var data = JsonUtility.FromJson<User>(res.Text);
Debug.Log(data.NickName);
}).Catch(ex =>
{
Debug.Log($"에러! {ex.Message}");
});
}
//라이브러리 사용
public void Request()
{
RestClient.Get<User>(url).Then(res =>
{
Debug.Log(res.NickName);
}).Catch(ex =>
{
Debug.Log($"에러! {ex.Message}");
});
}
이런식으로 제네릭을 이용하면 res에 바로 해당 클래스가 역직렬화가 되어서 돌아온다.
//라이브러리 사용
public void Request()
{
RestClient.Get<User>(url).Then(res =>
{
Debug.Log(res.NickName);
return RestClient.Get<User2>(url);
}).Then(res =>
{
Debug.Log(res.Inventory[0]);
}).Catch(ex =>
{
Debug.Log($"에러! {ex.Message}");
});
}
이런식으로 다른 요청을 return 해주어서 Then 함수를 통해 이어받아 콜백을 실행하는것도 가능하다.
Get,Post,Put,Delete,Head 를 지원한다.
'게임 엔진 > Unity' 카테고리의 다른 글
[어드레서블] - 기본 및 사용법 (0) | 2024.08.07 |
---|---|
Jenkins로 유니티 빌드 자동화 (1) | 2024.05.09 |
Github Action으로 Unity 자동 빌드 제작해보기 (CI/CD) - 3편 (1) | 2024.03.23 |
Github Action으로 Unity 자동 빌드 제작해보기 (CI/CD) - 2편 (0) | 2024.03.23 |
Github Action으로 Unity 자동 빌드 제작해보기 (CI/CD) - 1편 (0) | 2024.03.23 |
@데브준우 :: 개발초보 JW의 성장일기
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!