실행 영상
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Achievements : MonoBehaviour
{
void Start()
{
GetComponent<Button>().onClick.AddListener(() =>
{
GPGSManager.Instance.ReportAchievementProgress(100.0f, GPGSIds.achievement_first_step); // 업적 전행사항
Social.ShowAchievementsUI(); //업적 리스트 출력.
});
}
}
Achievements.cs
(업적 진행 사항 제출 및 업적 창 띄우기)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LeaderBoard : MonoBehaviour
{
void Start()
{
GetComponent<Button>().onClick.AddListener(() =>
{
//점수 보고 함수.
//1번 인자 : 보고할 점수
//2번 인자 : 보고할 대상 리더보드 ID값
//3번 인자 : callback 함수
GPGSManager.Instance.ReportScore(5, GPGSIds.leaderboard_high_score); // 리더보드에 점수 제출
Social.ShowLeaderboardUI(); // 리더보드 리스트 출력
});
}
}
LeaderBoard.cs
(리더보드-high score 점수 제출 및 리더보드 띄우기)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
public class GPGSManager : MonoBehaviour
{
private static GPGSManager instance;
public void ShowLeaderboardUI_Ranking()
=> ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI(GPGSIds.leaderboard_high_score);
public void ShowLeaderboardUI() => Social.ShowLeaderboardUI();
public static GPGSManager Instance
{
get
{
if (instance == null)
{
instance = FindObjectOfType<GPGSManager>();
if (instance == null)
{
GameObject gpgsManagerGo = new GameObject();
instance = gpgsManagerGo.AddComponent<GPGSManager>();
gpgsManagerGo.name = "GPGSManager";
DontDestroyOnLoad(gpgsManagerGo);
}
}
return instance;
}
}
private void Awake()
{
if (instance == null)
{
instance = this as GPGSManager;
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(this.gameObject);
}
}
public void Start()
{
// Google Play Games 초기화 및 활성화
PlayGamesPlatform.Activate();
Social.localUser.Authenticate(ProcessAuthentication);
}
public void ProcessAuthentication(bool success)
{
if (success)
{
Debug.Log("인증 성공");
}
else
{
Debug.Log("인증 실패");
}
}
public void ReportScore(long score, string leaderboardID) // 리더보드
{
Social.ReportScore(score, leaderboardID, (bool success) => {
if (success)
{
Debug.Log("리더보드 점수 제출 성공");
}
else
{
Debug.Log("리더보드 점수 제출 실패");
}
});
}
public void ReportAchievementProgress(float progress, string leaderboardID) // 리더보드
{
Social.ReportProgress(leaderboardID, progress, (bool isSuccess) => {
if (isSuccess)
{
Debug.Log("업적 진행 사항 제출 성공");
}
else
{
Debug.Log("업적 진행 사항 제출 실패");
}
});
}
}
GPGSManager.cs
반응형
'산대특 > 인디게임 출시 및 홍보마케팅' 카테고리의 다른 글
[Google AdMob] 유니티에 구글 애드몹 광고 연동하기 (0) | 2024.06.28 |
---|---|
구글 플레이 게임 서비스(GPGS) 인증 예제 (0) | 2024.06.21 |
구글 플레이 게임즈(GPGS) 유니티 연동 오류 해결 (0) | 2024.06.20 |