일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 유니티
- Data structure
- Android
- 안드로이드 mvp
- flutter
- 우분투 파이썬
- 자바기초
- Nexus GraphQL
- 자바
- Apollo GraphQL
- mvvm
- graphQL
- 안드로이드 테스트
- unit test
- PYTHON
- Apollo Server
- dagger-hilt
- 안드로이드 디자인패턴
- prisma
- ubuntu python
- MVVM pattern
- Android test
- Design Pattern
- LinkedList
- 안드로이드
- 파이썬 크롤링
- 웹크롤링
- java
- Dependency Injection
- Kotlin
- Today
- Total
Hun's Blog
[Unity] GPGS(Google Play Games Services) 2. 로그인 본문
간단하게 예제화면을 만들어서 로그인 / 로그아웃 / 프로필 사진 / 유저 네임을 가져와보자.
필요한 것
1. 사진을 띄울 창
2. 이름을 띄울 text
3. 현재 상태 log를 띄울 text
4. 로그인을 구현할 script와 오브젝트
캡쳐 화면으로 순서대로 정리해 보았다.
이미지 1 UI Setting 1
// Hierarchy 창에서 오른쪽 마우스 클릭 -> UI -> Canvas
// Canvas 오른쪽 마우스 클릭 -> UI -> Image
// Canvas 오른쪽 마우스 클릭 -> UI -> RawImage
// Canvas 오른쪽 마우스 클릭 -> UI -> Text
// Canvas 오른쪽 마우스 클릭 -> UI -> Text
생성
이미지2 UI Setting 2
// image -> background
// raw image -> user_image
// text -> user_name, user_log
test용도이니 각각의 배치는 자유롭게
이미지3 UI Setting 3
// Canvas 오른쪽 마우스 클릭 -> UI -> Button -> Login 오브젝트 명 변경 -> text 변경
// Canvas 오른쪽 마우스 클릭 -> UI -> Button -> Logout 오브젝트 명 변경 -> text 변경
이미지4 UI Setting 4
Hierarchy 창에서 오른쪽 마우스 클릭 -> Create Empty -> GooglePlayManager 오브젝트 명 변경
이미지5 c# script 생성
빨간색 체크 포인트 오른쪽 마우스 클릭 -> Create -> C# Script
스크립트 명 GooglePlayManager로 저장
이미지 6 script 추가
생성한 스크립트를 Hierarchy의 GooglePlayManager로 드래그하여 추가 -> 스크립트 열기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
public class GooglePlayTest : MonoBehaviour
{
public Text scoreText;
public Text myLog;
public RawImage myImage;
private bool bWaitingForAuth = false;
private void Awake()
{
// 구글 게임서비스 활성화 (초기화)
PlayGamesPlatform.InitializeInstance(new PlayGamesClientConfiguration.Builder().Build());
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
}
private void Start()
{
//게임시작시 자동로그인
doAutoLogin();
}
// 자동로그인
public void doAutoLogin()
{
if (bWaitingForAuth)
return;
//구글 로그인이 되어있지 않다면
if (!Social.localUser.authenticated)
{
bWaitingForAuth = true;
//로그인 인증 처리과정 (콜백함수)
Social.localUser.Authenticate(AuthenticateCallback);
}
else
{
}
}
// 수동로그인
public void OnBtnLoginClicked()
{
//이미 인증된 사용자는 바로 로그인 성공된다.
if (Social.localUser.authenticated)
{
}
else
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
}
else
{
Debug.Log("Login Fail");
}
});
}
// 수동 로그아웃
public void OnBtnLogoutClicked()
{
((PlayGamesPlatform)Social.Active).SignOut();
}
// 인증 callback
void AuthenticateCallback(bool success)
{
if (success)
{
// 사용자 이름을 띄어줌
StartCoroutine(UserPictureLoad());
}
else
{
}
}
// 유저 이미지 받아오기
IEnumerator UserPictureLoad()
{
// 최초 유저 이미지 가져오기
Texture2D pic = Social.localUser.image;
// 구글 아바타 이미지 여부를 확인 후 이미지 생성
while (pic == null)
{
pic = Social.localUser.image;
yield return null;
}
myImage.texture = pic;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
이미지7 script setting
이미지7과 같이 각각의 위치에 맞게 드래그해서 추가
이미지 8 login button
1번 클릭 -> 2번 플러스 클릭 -> 3번 GooglePlayManager 드래그해서 넣기 -> 4번 OnClickLogin() 메소드 셋팅
이미지 9 logout button
로그인과 동일한 방법으로 진행 -> OnClickLogout() 메소드 셋팅
이미지10 android build -> apk파일 생성
유니티 에디터 -> File -> Build Settings -> Build
이전에 저장했던 이름 그대로 저장
스마트폰에 받아 설치하고 실행
이미지 11 로그인
이미지 12 로그아웃
자동로그인 / 로그인버튼 / 로그아웃 버튼 모두 잘 동작한다.
'Others' 카테고리의 다른 글
Android Emulator on Apple M1 (4) | 2020.12.27 |
---|---|
Setup Android Development Envrionment on Mac OS (0) | 2020.12.16 |
[Unity] GPGS(Google Play Games Services) 1.연동 (0) | 2020.03.22 |