void Start() { if (Instance == null) { Instance = this; } displayMainMenu = false; displayGameOver = false; displayMainMenuPaused = false; sW = Screen.width; sH = Screen.height; buttonWidth = sW * 0.6f; buttonHeight = sH / 20.0f; storeKitController = GetComponent <StoreKitController>(); // always authenticate at every launch GameCenterBinding.authenticateLocalPlayer(); GameCenterBinding.loadLeaderboardTitles(); //Get in-app purchase product data storeKitController.RequestProductData(); showAds = true; int Ads = EncryptedPlayerPrefs.GetInt("removeadverts"); if (Ads == 1) { if (EncryptedPlayerPrefs.CheckEncryption("removeadverts", "int", "1")) { showAds = false; } } else { //start loading ad AdBinding.initializeInterstitial(); //start iAd AdBinding.createAdBanner(true); } // hack to detect iPad 3 until Unity adds official support this.isPad = (Screen.width >= 1536 || Screen.height >= 1536); if (isPad) { customButtonStyle.fontSize = 64; customHighlightStyle.fontSize = 64; customPaddedStyle.fontSize = 64; } //keep this object in memory DontDestroyOnLoad(transform.gameObject); }
void leaderboardsGUI() { if (GUILayout.Button("Load Leaderboard Data")) { GameCenterBinding.loadLeaderboardTitles(); } if (GUILayout.Button("Show Leaderboards")) { GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime); } if (!_hasLeaderboardData) { GUILayout.Label("Load leaderboard data to see more options"); return; } if (GUILayout.Button("Post Score")) { Debug.Log("about to report a random score for leaderboard: " + _leaderboards[0].leaderboardId); GameCenterBinding.reportScore(Random.Range(1, 99999), _leaderboards[0].leaderboardId); } if (GUILayout.Button("Issue Score Challenge")) { var playerIds = new string[] { "player1", "player2" }; var score = Random.Range(1, 9999); GameCenterBinding.issueScoreChallenge(score, 0, _leaderboards[0].leaderboardId, playerIds, "Beat this score!"); } if (GUILayout.Button("Get Raw Score Data")) { GameCenterBinding.retrieveScores(false, GameCenterLeaderboardTimeScope.AllTime, 1, 25, _leaderboards[0].leaderboardId); } if (GUILayout.Button("Get Scores for Me")) { GameCenterBinding.retrieveScoresForPlayerId(GameCenterBinding.playerIdentifier(), _leaderboards[0].leaderboardId); } }
//public AudioClip bgmusic; // Use this for initialization void Start() { GameCenterManager.categoriesLoaded += delegate(List <GameCenterLeaderboard> leaderboards) { this.leaderboards = leaderboards; }; GameCenterManager.achievementMetadataLoaded += delegate(List <GameCenterAchievementMetadata> achievementMetadata) { this.achievementMetadata = achievementMetadata; }; GameCenterBinding.authenticateLocalPlayer(); GameCenterBinding.loadLeaderboardTitles(); string alias = GameCenterBinding.playerAlias(); }
void OnGUI() { float yPos = 5.0f; float xPos = 5.0f; float width = (Screen.width >= 960 || Screen.height >= 960) ? 320 : 160; float height = (Screen.width >= 960 || Screen.height >= 960) ? 80 : 40; float heightPlus = height + 5.0f; if (GUI.Button(new Rect(xPos, yPos, width, height), "Authenticate")) { GameCenterBinding.authenticateLocalPlayer(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Load Achievement Metadata")) { GameCenterBinding.retrieveAchievementMetadata(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Raw Achievements")) { GameCenterBinding.getAchievements(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Post Achievement")) { if (achievementMetadata != null && achievementMetadata.Count > 0) { int percentComplete = (int)Random.Range(2, 60); Debug.Log("sending percentComplete: " + percentComplete); GameCenterBinding.reportAchievement(achievementMetadata[0].identifier, percentComplete); } else { Debug.Log("you must load achievement metadata before you can post an achievement"); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Issue Achievement Challenge")) { if (achievementMetadata != null && achievementMetadata.Count > 0) { var playerIds = new string[] { "player1", "player2" }; GameCenterBinding.issueAchievementChallenge(achievementMetadata[0].identifier, playerIds, "I challenge you"); } else { Debug.Log("you must load achievement metadata before you can issue an achievement challenge"); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Show Achievements")) { GameCenterBinding.showAchievements(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Reset Achievements")) { GameCenterBinding.resetAchievements(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Multiplayer Scene")) { Application.LoadLevel("GameCenterMultiplayerTestScene"); } // Second Column xPos = Screen.width - width - 5.0f; yPos = 5.0f; if (GUI.Button(new Rect(xPos, yPos, width, height), "Get Player Alias")) { string alias = GameCenterBinding.playerAlias(); Debug.Log("Player alias: " + alias); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Load Leaderboard Data")) { GameCenterBinding.loadLeaderboardTitles(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Post Score")) { // We must have a leaderboard to post the score to if (leaderboards != null && leaderboards.Count > 0) { Debug.Log("about to report a random score for leaderboard: " + leaderboards[0].leaderboardId); GameCenterBinding.reportScore(Random.Range(1, 99999), leaderboards[0].leaderboardId); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Issue Score Challenge")) { // We must have a leaderboard to post the score to if (leaderboards != null && leaderboards.Count > 0) { var playerIds = new string[] { "player1", "player2" }; var score = Random.Range(1, 9999); GameCenterBinding.issueScoreChallenge(score, 0, leaderboards[0].leaderboardId, playerIds, "Beat this score!"); } else { Debug.Log("you must load your leaderboards before you can issue a score challenge"); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Show Leaderboards")) { GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Raw Score Data")) { // We must have a leaderboard to retrieve scores from if (leaderboards != null && leaderboards.Count > 0) { GameCenterBinding.retrieveScores(false, GameCenterLeaderboardTimeScope.AllTime, 1, 25, leaderboards[0].leaderboardId); } else { Debug.Log("Load leaderboard data before attempting to retrieve scores"); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Scores for Me")) { // We must have a leaderboard to retrieve scores from if (leaderboards != null && leaderboards.Count > 0) { GameCenterBinding.retrieveScoresForPlayerId(GameCenterBinding.playerIdentifier(), leaderboards[0].leaderboardId); } else { Debug.Log("Load leaderboard data before attempting to retrieve scores"); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Retrieve Friends")) { GameCenterBinding.retrieveFriends(true); } }
void OnGUI() { //PAUSE MENU if (displayMainMenu) { gameOver = false; GUI.DrawTextureWithTexCoords(new Rect(0f, 0f, sW, sH), mainMenuBackground, new Rect(0f, 0f, 5f, 5f)); GUI.DrawTexture(new Rect(sW * 0.2f, sH * 0.1f, sW * 0.6f, sH * 0.1f), gamelogo); if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.3f, buttonWidth, buttonHeight), "RESUME GAME", customHighlightStyle)) { displayMainMenu = false; displayMainMenuPaused = false; Camera.main.GetComponent <beeGUI>().dispMenu = true; Time.timeScale = 1; } if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.4f, buttonWidth, buttonHeight), "LEADERBOARD", customButtonStyle)) { if (GameCenterBinding.isPlayerAuthenticated()) { if (_hasLeaderboardData) { GameCenterBinding.showGameCenterViewController(GameCenterViewControllerState.Leaderboards); } } else { GameCenterBinding.authenticateLocalPlayer(); GameCenterBinding.loadLeaderboardTitles(); } } if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.5f, buttonWidth, buttonHeight), "RATE", customHighlightStyle)) { Application.OpenURL("itms-apps://itunes.apple.com/app/id875911453"); } if (EncryptedPlayerPrefs.GetInt("10xtralives") != 1) { if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.6f, buttonWidth, buttonHeight), "EXTRA LIVES", customButtonStyle)) { displayExtraLives = true; displayMainMenu = false; } } if (EncryptedPlayerPrefs.GetInt("removeadverts") != 1) { if (EncryptedPlayerPrefs.GetInt("10xtralives") != 1) { if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.7f, buttonWidth, buttonHeight), "REMOVE ADS", customHighlightStyle)) { displayRemoveAds = true; displayMainMenu = false; } } else { if (GUI.Button(new Rect((sW - buttonWidth) / 2, sH * 0.6f, buttonWidth, buttonHeight), "REMOVE ADS", customButtonStyle)) { displayRemoveAds = true; displayMainMenu = false; } } } } //EXTRA LIVES if (displayExtraLives) { GUI.DrawTextureWithTexCoords(rRect(0f, 0f, 1f, 1f), mainMenuBackground, new Rect(0f, 0f, 5f, 5f)); GUI.DrawTexture(rRect(0.2f, 0.1f, 0.6f, 0.1f), gamelogo); if (EncryptedPlayerPrefs.GetInt("10xtralives") != 1) { GUI.Label(rRect(0.25f, 0.3f, 0.5f, 0.05f), "BUY EXTRA LIVES", customHighlightStyle); GUI.Label(rRect(0.125f, 0.35f, 0.75f, 0.25f), "Survive longer each game by buying extra life options. You can buy an extra 3 or a whopping 10 extra lives!", customPaddedStyle); if (GUI.Button(rRect(0.125f, 0.6f, 0.375f, 0.05f), "3 EXTRA LIVES", customHighlightStyle)) { BuyExtraLives(); } if (GUI.Button(rRect(0.5f, 0.6f, 0.375f, 0.05f), "RESTORE", customHighlightStyle)) { RestoreButtonPressed(); } if (GUI.Button(rRect(0.125f, 0.65f, 0.375f, 0.05f), "10 EXTRA LIVES", customHighlightStyle)) { Buy10ExtraLives(); } if (GUI.Button(rRect(0.5f, 0.65f, 0.375f, 0.05f), "CANCEL", customHighlightStyle)) { CancelButtonPressed(); } } } //GAME OVER if (displayGameOver) { gameOver = true; if (showAds && AdBinding.isInterstitalLoaded()) { AdBinding.destroyAdBanner(); AdBinding.showInterstitial(); } GUI.DrawTextureWithTexCoords(rRect(0f, 0f, 1f, 1f), mainMenuBackground, new Rect(0f, 0f, 5f, 5f)); GUI.DrawTexture(rRect(0.2f, 0.1f, 0.6f, 0.1f), gamelogo); GUI.Label(rRect(0.3f, 0.25f, 0.4f, 0.05f), "GAME OVER", customHighlightStyle); GUI.Label(rRect(0.3f, 0.3f, 0.4f, 0.05f), "SCORE", customButtonStyle); GUI.Label(rRect(0.3f, 0.35f, 0.4f, 0.05f), ((int)Camera.main.GetComponent <beeGUI>().score).ToString(), customButtonStyle); GUI.Label(rRect(0.3f, 0.4f, 0.4f, 0.05f), "HIGH", customButtonStyle); GUI.Label(rRect(0.3f, 0.45f, 0.4f, 0.05f), EncryptedPlayerPrefs.GetInt("highScoore").ToString(), customButtonStyle); if (GUI.Button(rRect(0.3f, 0.52f, 0.4f, 0.05f), "RATE", customHighlightStyle)) { Application.OpenURL("itms-apps://itunes.apple.com/app/id875911453"); } if (GUI.Button(rRect(0.3f, 0.59f, 0.4f, 0.05f), "LEADERBOARD", customHighlightStyle)) { if (GameCenterBinding.isPlayerAuthenticated()) { if (_hasLeaderboardData) { GameCenterBinding.showGameCenterViewController(GameCenterViewControllerState.Leaderboards); } } else { GameCenterBinding.authenticateLocalPlayer(); GameCenterBinding.loadLeaderboardTitles(); } } float yoffset = 0f; if (EncryptedPlayerPrefs.GetInt("10xtralives") != 1) { if (GUI.Button(rRect(0.3f, 0.66f, 0.4f, 0.05f), "EXTRA LIVES", customHighlightStyle)) { displayExtraLives = true; displayGameOver = false; } } else { yoffset -= 0.07f; } if (showAds == true) { if (GUI.Button(rRect(0.3f, 0.73f + yoffset, 0.4f, 0.05f), "REMOVE ADS", customHighlightStyle)) { displayRemoveAds = true; displayGameOver = false; } } else { yoffset -= 0.07f; } if (GUI.Button(rRect(0.3f, 0.80f + yoffset, 0.4f, 0.05f), "TRY AGAIN", customHighlightStyle)) { displayMainMenu = false; displayGameOver = false; Camera.main.GetComponent <beeGUI>().dispMenu = true; Time.timeScale = 1; if (showAds) { AdBinding.createAdBanner(true); AdBinding.initializeInterstitial(); } Application.LoadLevel("game"); } } //REMOVE ADS PURCHASE if (displayRemoveAds) { GUI.DrawTextureWithTexCoords(new Rect(0f, 0f, sW, sH), mainMenuBackground, new Rect(0f, 0f, 5f, 5f)); GUI.DrawTexture(new Rect(sW * 0.2f, sH * 0.1f, sW * 0.6f, sH * 0.1f), gamelogo); if (EncryptedPlayerPrefs.GetInt("removeadverts") != 1) { GUI.Label(rRect(0.25f, 0.3f, 0.5f, 0.05f), "REMOVE ADVERTS", customHighlightStyle); GUI.Label(rRect(0.125f, 0.35f, 0.75f, 0.25f), "Have and advert-free experience by purchasing the option below. Then experience uninterrupted gameplay!", customPaddedStyle); if (GUI.Button(rRect(0.125f, 0.6f, 0.25f, 0.05f), "NO ADS!", customHighlightStyle)) { BuyRemoveAds(); } if (GUI.Button(rRect(0.375f, 0.6f, 0.25f, 0.05f), "RESTORE", customHighlightStyle)) { RestoreButtonPressed(); } if (GUI.Button(rRect(0.625f, 0.6f, 0.25f, 0.05f), "CANCEL", customHighlightStyle)) { CancelButtonPressed(); } } } //PROBLEM WITH IN-APP PURCHASE if (displayProblem) { GUI.DrawTextureWithTexCoords(new Rect(0f, 0f, sW, sH), mainMenuBackground, new Rect(0f, 0f, 5f, 5f)); GUI.DrawTexture(new Rect(sW * 0.2f, sH * 0.1f, sW * 0.6f, sH * 0.1f), gamelogo); GUI.Label(rRect(0.25f, 0.3f, 0.5f, 0.05f), "PROBLEM", customHighlightStyle); GUI.Label(rRect(0.125f, 0.35f, 0.75f, 0.25f), "There appears to be a problem in doing that action. Please can you try again later?", customPaddedStyle); if (GUI.Button(rRect(0.375f, 0.6f, 0.25f, 0.05f), "HOME", customHighlightStyle)) { if (gameOver) { displayGameOver = true; } else { displayMainMenu = true; } displayProblem = false; } } }
// Sends off a request to get all the currently live leaderboards including leaderboardId and title. public void LoadLeaderboardTitles() { GameCenterBinding.loadLeaderboardTitles(); }