你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 【Unity】 ios游戲開發中登陸 GameCenter的問題和腳本

【Unity】 ios游戲開發中登陸 GameCenter的問題和腳本

編輯:IOS開發綜合

想經過Unity 登錄IOS GameCenter,需求借助unity自帶的Social.localUser辦法調用來完成,鑒於有些開發者沒有過這方面的經歷,上面就給大家引見下成功登陸進IOS GameCenter的辦法,想看的可以學習一下。

  

  上面是代碼完成:

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

112

113

114

using UnityEngine;

using UnityEngine.SocialPlatforms;

using UnityEngine.SocialPlatforms.GameCenter;

public class GameCenterManager : System.Object

{

private static GameCenterManager instance;

private static object _lock=new object();

private GameCenterManager(){}

public static GameCenterManager GetInstance()

{

if(instance==null)

{

lock(_lock)

{

if(instance==null)

{

instance=new GameCenterManager();

}

}

}

return instance;

}

public void Start()

{

Social.localUser.Authenticate(HandleAuthenticated);

}

private void HandleAuthenticated(bool success)

{

Debug.Log("*** HandleAuthenticated: success = " + success);

if(success)

{

string userInfo = "UserName:" + Social.localUser.userName +"\nUser ID:"+

Social.localUser.id + " \nIsUnderage: "+ Social.localUser.underage;

Debug.Log(userInfo);

//上面三行看團體需求,需求什麼信息就取什麼信息,這裡正文掉是由於擔憂有的冤家沒有在iTunesConnect裡設置排行、成就之類的東西,運轉起來能夠會報錯

// Social.localUser.LoadFriends(HandleFriendsLoaded);

// Social.LoadAchievements(HandleAchievementsLoaded);

// Social.LoadAchievementDescriptions(HandleAchievementDescriptionsLoaded);

}

}

private void HandleFriendsLoaded(bool success)

{

Debug.Log("*** HandleFriendsLoaded: success = " + success);

foreach(IUserProfile friend in Social.localUser.friends)

{

Debug.Log("* friend = " + friend.ToString());

}

}

private void HandleAchievementsLoaded(IAchievement[] achievements)

{

Debug.Log("* HandleAchievementsLoaded");

foreach(IAchievement achievement in achievements)

{

Debug.Log("* achievement = " + achievement.ToString());

}

}

private void HandleAchievementDescriptionsLoaded(IAchievementDescription[] achievementDescriptions)

{

Debug.Log("*** HandleAchievementDescriptionsLoaded");

foreach(IAchievementDescription achievementDescription in achievementDescriptions)

{

Debug.Log("* achievementDescription = " + achievementDescription.ToString());

}

}

// achievements

public void ReportProgress(string achievementId, double progress)

{

if (Social.localUser.authenticated) {

Social.ReportProgress(achievementId, progress, HandleProgressReported);

}

}

private void HandleProgressReported(bool success)

{

Debug.Log("*** HandleProgressReported: success = " + success);

}

public void ShowAchievements()

{

if (Social.localUser.authenticated) {

Social.ShowAchievementsUI();

}

}

// leaderboard

public void ReportScore(string leaderboardId, long score)

{

if (Social.localUser.authenticated) {

Social.ReportScore(score, leaderboardId, HandleScoreReported);

}

}

public void HandleScoreReported(bool success)

{

Debug.Log("*** HandleScoreReported: success = " + success);

}

public void ShowLeaderboard()

{

if (Social.localUser.authenticated) {

Social.ShowLeaderboardUI();

}

}

  

  當然在登陸進程中也呈現過一些列問題,例如說在IOS設備上沒有反映,剛開端覺得這個腳本出問題。然後運用第三方插件,也是不能登錄, 檢查源碼,打印錯誤日志。

  

  最後才發現必需開啟gameCenter的沙盒形式 Sandbox in Settings--> Game Center --> Sandbox. 錯誤提示為:Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognized by Game Center." UserInfo=0x17d08ee0 {NSLocalizedDescription=The requested operation could not be completed because this application is not recognized by Game Center.

  

  置信有了這前車之鑒,大家的開發進程會變的順暢很多。

【【Unity】 ios游戲開發中登陸 GameCenter的問題和腳本】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved