본문 바로가기

Unity/뒤끝

[뒤끝 파헤치기] #10. 사용자 게임 정보 읽기

반응형

해당 강의는 PC환경에 최적화 된 글 입니다.

목록 바로가기

https://cheolmini.tistory.com/53

 

[뒤끝 파헤치기] #10. 사용자 게임 정보 읽기

뒤끝 파헤치기 열번째 강의글 입니다.

 

동기, 비동기식으로 사용자의 게임 정보를 읽어오도록 하겠습니다.

 

해당 강의글에서는 가장 기초만 설명하고 있으며 참고글을 가보시면 더 많은 옵션이 있습니다.


1. 예외 처리 함수

 

참고만 해주세요!

 

void Error(string errorCode, string type)
    {
        if (errorCode == "DuplicatedParameterException")
        {
            if (type == "UserFunc") print("중복된 사용자 아이디 입니다.");
            else if (type == "UserNickname") print("중복된 닉네임 입니다.");
        }
        else if (errorCode == "BadUnauthorizedException")
        {
            if (type == "UserFunc") print("잘못된 사용자 아이디 혹은 비밀번호 입니다.");
        }
        else if (errorCode == "UndefinedParameterException")
        {
            if (type == "UserNickname") print("닉네임을 다시 입력해주세요");
        }
        else if (errorCode == "BadParameterException")
        {
            if (type == "UserNickname") print("닉네임 앞/뒤 공백이 있거나 20자 이상입니다.");
            else if (type == "UserPW") print("잘못된 이메일입니다.");
            else if (type == "ReadData") print("잘못된 유형의 테이블 입니다.");
        }
        else if (errorCode == "NotFoundException")
        {
            if (type == "UserPW") print("등록된 이메일이 없습니다.");
            else if (type == "Coupon") print("중복 사용이거나 기간이 만료된 쿠폰입니다.");
            else if (type == "gameData") print("해당 테이블을 찾을 수 없습니다.");
            else if (type == "ReadData") print("존재하지 않는 테이블 입니다");
        }
        else if (errorCode == "Too Many Request")
        {
            if (type == "UserPW") print("요청 횟수를 초과하였습니다. (1일 5회)");
        }
        else if (errorCode == "PreconditionFailed")
        {
            if (type == "gameData" || type == "ReadData") print("해당 테이블은 비활성화 된 테이블 입니다.");
        }
        else if (errorCode == "ServerErrorException")
        {
            if (type == "gameData") print("하나의 row이 400KB를 넘습니다");
        }
    }


동기 방식


1. 사용자 정보 읽기

 

Backend.GameInfo.GetPublicContents ( "tableName" ) ;

Backend.GameInfo.GetPrivateContents ( "tableName" ) ;

 

해당 테이블의 정보를 가져옵니다.

 

inDate 값은 추후 정보 수정에 사용될 값이니 저장해주세요.

 

    public void readData()
    {
        BackendReturnObject BRO = Backend.GameInfo.GetPrivateContents("character");

        if (BRO.IsSuccess())
        {
            JsonData jsonData = BRO.GetReturnValuetoJSON()["rows"][0];
            string level = jsonData["level"][0].ToString();
            string exp = jsonData["exp"][0].ToString();
            string gunLevel = jsonData["weapon"][0]["gun"][0].ToString();
            string knifeLevel = jsonData["weapon"][0]["knife"][0].ToString();
            string punchLevel = jsonData["weapon"][0]["punch"][0].ToString();

            dataIndate = jsonData["inDate"][0].ToString();

            print($"Level : {level}    Exp : {exp}");
            print($"Gun : LV.{gunLevel}    Knife : LV.{knifeLevel}    Punch : LV.{punchLevel}");
            print("동기 방식 정보 읽기 완료");
        }
        else Error(BRO.GetErrorCode(), "ReadData");
    }


비동기 방식


1. 사용자 정보 읽기

 

BackendAsyncClass.BackendAsync(Backend.GameInfo.GetPublicContents, "tableName", ( callback ) => { // 이후 처리 });

BackendAsyncClass.BackendAsync(Backend.GameInfo.GetPrivateContents, "tableName", ( callback ) => { // 이후 처리 });

 

    public void readDataAsync()
    {
        BackendAsyncClass.BackendAsync(Backend.GameInfo.GetPrivateContents, "character", (callback) =>
        {
            if (callback.IsSuccess())
            {
                JsonData jsonData = callback.GetReturnValuetoJSON()["rows"][0];
                string level = jsonData["level"][0].ToString();
                string exp = jsonData["exp"][0].ToString();
                string gunLevel = jsonData["weapon"][0]["gun"][0].ToString();
                string knifeLevel = jsonData["weapon"][0]["knife"][0].ToString();
                string punchLevel = jsonData["weapon"][0]["punch"][0].ToString();

                dataIndate = jsonData["inDate"][0].ToString();

                print($"Level : {level}    Exp : {exp}");
                print($"Gun : LV.{gunLevel}    Knife : LV.{knifeLevel}    Punch : LV.{punchLevel}");
                print("비동기 방식 정보 읽기 완료");
            }
            else Error(callback.GetErrorCode(), "ReadData");
        });
    }

UI 구성하기

 

버튼 2개를 더 추가하였습니다.

 


결과

 

동기 방식 정보 읽기

 

비동기 방식 정보 읽기


참고 글

https://developer.thebackend.io/unity3d/guide/gameData/readv1_2/

 

뒤끝 개발자

모바일 게임 서버를 쉽게 생성, 관리 할 수 있는 뒤끝의 개발자 사이트입니다.

developer.thebackend.io


모든 프로젝트는 깃 허브에 업데이트 할 예정입니다.

 

https://github.com/CM-Games/BackEnd

읽어 주셔서 감사합니다.

 

더보기

검색어

뒤끝베이스

뒤끝강좌

뒤끝

뒤끝매치

뒤끝챗

유니티뒤끝

백앤드

유니티백앤드

유니티서버

유니티데이터저장

뒤끝기초

뒤끝서버

반응형