0617 GPGS

2021. 6. 17. 11:41Node.js

1. 녹스 설치
2. 구글 플레이 개발자 콘솔 로그인
3. https://github.com/playgameservices/play-games-plugin-for-unity
소스 다운로드
4. 유니티 새 프로젝트 만들기, 안드로이드로 플랫폼 변경

유니티로 임포트 한다.
그냥 yes 누르면 된다.

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

위와 같은 에러가 뜬다면 자바 설치
위 버전 다운로드

 

만일 안드로이드 스튜디어가 깔렸다면 오라클에서 다운받을 필요없음
PATH 추가

https://drehzr.tistory.com/711

 

Unity) Android Resolver ERROR: JAVA_HOME ~

Android Resolver  ERROR: JAVA_HOME ~ Unity에서 Android Resolver를 사용하다 보면 ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOM..

drehzr.tistory.com

위의 블로그 그대로 따라하면 된다.

JAVA_HOME 추가 후 force resolve 하면 됨
안드로이드 플러그인에 뭔가 많이 생김
유니티 허브에서 iOS 모듈도 설치해야한다.
완료


구글 플레이 콘솔에서 앱을 새로 하나 만든다.

 

인증서 만들기
실제 배포용도로 빌드를 하겠다는 의미다. 최종에 최종최종

 

 

녹스에서 실행시켜보니 드디어 된다 하...................................................

 


 

자바가 깔린 곳으로 가서 keytool cmd 입력, keytool이 깔린 곳이다.
cmd 창에서 keytool이 설치된 곳으로 가서 
keystore 의 디렉토리를 가져와
복사해서 가져오기
키스토어가 깔린 디렉토리를 더 괄호 안에 넣으면
이렇게 뜬다.
위는 구글 클라우드 플랫폼이다.
이건 구글 플레이 콘솔창

 


 

구글 로그인 구현

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;

public class App : MonoBehaviour
{
    public Text txtVersion;

    // Start is called before the first frame update
    void Start()
    {
        this.txtVersion.text = Application.version;

        Debug.Log("================================= init GPGS =================================");

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            
            .EnableSavedGames()
            .Build();

        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

        Debug.Log("================================= authenticate =================================");

        // authenticate user:
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) => {
            Debug.Log("================================= result =================================");
        });
    }

}

코드 작성 후 앱 새로 빌드

안드로이드 sdk가 깔린 경로를 가져와

 

adb connect 127.0.0.1:62001로 안드로이드에 접속
다음에 adb logcat을 하면 이렇게 무수한 뭐시기가 뜬다.
녹스에서 새로 빌드한 앱을 실행하면 구글 게임에 연결 중이라는 팝업이 뜨면서
구글 로그인으로 들어간다.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;

public class App : MonoBehaviour
{
    public Text txtVersion;
    public Text txtId;
    public Text txtUsername;
    public Text txtState;
    public Image thumb;

    // Start is called before the first frame update
    void Start()
    {
        this.txtVersion.text = Application.version;
        

        Debug.Log("================================= init GPGS =================================");

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            
            .EnableSavedGames()
            .Build();

        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

        Debug.Log("================================= authenticate =================================");

        // authenticate user:
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) => {
            Debug.Log("================================= result ================================="+result);
            Debug.Log("================================= local User ================================="+ Social.localUser);
            Debug.Log("================================= autenciated =================================" + Social.localUser.authenticated);

            this.txtId.text = Social.localUser.id;
            this.txtUsername.text = Social.localUser.userName;
            this.txtState.text = Social.localUser.state.ToString();

            StartCoroutine(this.WaitforLoadThumb(() =>
            {
                Debug.Log(Social.localUser.image);
                Debug.LogFormat("{0}{1}", Social.localUser.image.width, Social.localUser.image.height);
                this.thumb.sprite = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width,Social.localUser.image.height), Vector2.zero);
                this.thumb.SetNativeSize();
            }));
        });

        
    }
    private IEnumerator WaitforLoadThumb(System.Action callback)
    {
        while (true)
        {
            if (Social.localUser.image != null)
            {
                break;
            }
            yield return null;
        }
        callback();
    }
    

}

'Node.js' 카테고리의 다른 글

Naver login  (0) 2021.06.24
GPGS Achievement  (0) 2021.06.23
0616 Sequelize  (0) 2021.06.16
0615 express서버와 mysql 커넥션  (0) 2021.06.15
0611 express 서버 이어서  (0) 2021.06.11