using UnityEngine;
public class IdnetAPI : MonoBehaviour
{
//my correction
public Texture aTexture;
public GUISkin guiSkin;
private const int BORDER = 10;
private const int BORDER_X2 = BORDER * 2;
private const int BOX_WIDTH = 350;
private const int BOX_WIDTH_SMALL = 400;
private const int BOX_HEIGHT_SMALL = 90;
private const float BUTTON_HEIGHT = 35;
private bool _allowErroneousApiCalls;
private bool _minimized;
private void Awake()
{
Idnet.I.Initialize("5a1ec9c7e694aa9df335bb7e", false);
// Mandatory for all IDnet games.
AutoLoginGUIWindowCode();
}
//****************************************************AUTOLOGIN***************************************************//
private static void AutoLoginGUIWindowCode()
{
Idnet.I.AutoLogin((user, autoLoginException) =>
{
if (autoLoginException != null)
{
#if UNITY_EDITOR
Debug.LogError("Autologin does not work in the Unity Editor,try it browser!");
#else // Callback: Autologin failed,show the OnlineSave-LocalSave setup screen http://dev.id.net/docs/unity/saving/
Debug.Log("Autologin failed,probably user not logged-in to https://www.id.net");
#endif
}
else
{
if (Idnet.User.LoggedIn())
{
// Callback: Autologin Success,you will get user's nickname in callback.
// Show the OnlineSave-LocalSave setup screen http://dev.id.net/docs/unity/saving/ with user's name.
Debug.Log("Auto login success. " + "Nickname " + Idnet.User.Current.Nickname);
//my correction
NameFromAPI.mefirstname = Idnet.User.Current.Nickname;
}
}
});
}
//*************************************************Login GUI window***********************************************//
private static void LoginGUIWindowCode()
{
Idnet.I.Login(loginRegisterException =>
{
if (Idnet.User.LoggedIn())
{
// Callback: Login Success,you will get user's nickname in callback.
Debug.Log("User logged in: " + "Nickname " + Idnet.User.Current.Nickname);
//my correction
NameFromAPI.mefirstname = Idnet.User.Current.Nickname;
}
});
}
//*************************************************Register GUI window********************************************//
private static void RegisterGUIWindowCode()
{
Idnet.I.Register(loginRegisterException =>
{
if (Idnet.User.LoggedIn())
{
// Callback: Register & hence Login Success,you will get user's nickname in callback.
Debug.Log("User logged in: " + "Nickname " + Idnet.User.Current.Nickname);
//my correction
NameFromAPI.mefirstname = Idnet.User.Current.Nickname;
}
});
}
//*************************************************User's NickName************************************************//
private static void ShowNickname()
{
// Call it in Update() or OnGUI or api callbacks.
if (Idnet.User.LoggedIn())
{
Debug.Log("Welcome: " + Idnet.User.Current.Nickname);
}
else
{
Debug.Log("Not logged-in to idnet");
}
}
//**********************************************Profile GUI window************************************************//
private static void ProfileExampleCode()
{
if (!Idnet.User.LoggedIn()) return;
Idnet.I.Profile();
}
//**************************************************Direct Logout*************************************************//
/// <summary>
/// Logout user from IDnet.
/// </summary>
private static void LogoutExampleCode()
{
if (!Idnet.User.LoggedIn()) return;
Idnet.I.Logout();
//my correction
NameFromAPI.mefirstname = "Free Racer";
}
//****************************************PostScore to idnet leaderboard******************************************//
private static void PostScoreExampleCode()
{
//Score posted must be an integer.
var exampleScore = 1000 + Random.Range(0, 1000);
// "LEADERBOARD" is the Table name you created http://dev.id.net/docs/unity/table-setup
Idnet.I.PostHighscore(exampleScore, "LEADERBOARD");
}
//********************************PostScore with callback(use if you need callback)*******************************//
private static void PostScoreWithCallbackExampleCode()
{
//Score posted must be an integer.
var exampleScore = 1000 + Random.Range(0, 1000);
// "LEADERBOARD" is the Table name you created http://dev.id.net/docs/unity/table-setup
Idnet.I.PostHighscore(exampleScore, "LEADERBOARD", (score, postHighscoreException) =>
{
if (postHighscoreException == null)
{
// Callback: Post Score succesfull here,you can show leaderboard here.
Debug.Log("Score posted succesfully");
}
else
{
Debug.LogError("Posting Score failed " + postHighscoreException);
}
});
}
//***************************************************Leaderboard**************************************************//
private static void LeaderboardExampleCode()
{
// "LEADERBOARD" is the Table name you created http://dev.id.net/docs/unity/table-setup
Idnet.I.Leaderboard("LEADERBOARD");
}
//*************************Submit Score and hence open leaderboard window(on callback)****************************//
private static void SubmitScoreExampleCode()
{
//exampleScore,Score posted must be an integer.
var exampleScore = 1001 + Random.Range(0, 1000);
// "LEADERBOARD" is the Table name you created http://dev.id.net/docs/unity/table-setup
Idnet.I.SubmitHighScore(exampleScore, "LEADERBOARD");
}
//**************************************Get User's BestScore from leaderboard*************************************//
/// <summary>
/// Get BestScore of current logged-in user from IDnet leaderboard.
/// Dont use this API in Update() or OnGUI() obviously.
/// </summary>
private static void GetBestScoreFromLeaderboard()
{
// "LEADERBOARD" is the Table name you created http://dev.id.net/docs/unity/table-setup
Idnet.I.GetBestScore("LEADERBOARD", bestScoreException =>
{
if (bestScoreException == null)
{
// Callback: Successfully retrieved BestScore of user.
Debug.Log("Idnet Best Score " + Idnet.User.Current.BestScore);
}
});
}
//***********************************SAVE Progress-Data of user to idnet server***********************************//
private static void SaveUserDataExampleCode()
{
if (!Idnet.User.LoggedIn()) return;
//Example 1: Posting a String.
Idnet.I.Post("MessageOfTheDay", "Hello World");
//Example 2: Posting Vectors
Idnet.I.Post("VectorPos", new Vector3(1.2f, 1.2f, 1.2f));
//Example 2: Posting Arrays
Idnet.I.Post("ExampleArray", new string[] {"Idnet", "Unity", "Games"});
// Posting a Class
// Mostly used type is "Class",as normally,there's a lot of user data to be posted with a 'single key and single api call'.
//Example 3: Posting Custom class1 "UserProgressExampleData",Create your own class as per your usage,mostly used type for posting user's progress.
Idnet.I.Post("UserProgress", new UserProgressExampleData(5, 545, 3, 20.5f, "Big Character", true));
}
/// <summary>
/// Post data and recieve its callback,once the operiation is finished.
/// </summary>
private static void SaveUserDataWithCallBackExampleCode()
{
// Using Callbacks.
// Example 1: Post a String.
Idnet.I.Post<string>("MessageOfTheDay", "Hello World", (data, postDataException) =>
{
if (postDataException == null)
{
Debug.Log("Data posted succesfully ");
}
else
{
Debug.LogError("Posting Data failed " + postDataException);
// "not_saved" as postDataException means you are saving the same "key" twice within a second.
}
});
// Example 2: Posting Arrays
Idnet.I.Post<int[]>("ExampleArray", new int[] {1, 2, 3}, (data, postDataException) =>
{
if (postDataException == null)
{
Debug.Log("Data posted succesfully");
}
else
{
Debug.LogError("Posting Data failed " + postDataException);
// "not_saved" as postDataException means you are saving the same "key" twice within a second.
}
});
// Example 3: Posting Custom class1 "UserProgressExampleData"
Idnet.I.Post<UserProgressExampleData>("UserProgress",
new UserProgressExampleData(5, 545, 3, 20.5f, "Big Character", true), (data, postDataException) =>
{
if (postDataException == null)
{
Debug.Log("Data posted succesfully");
}
else
{
Debug.LogError("Posting Data failed " + postDataException);
// "not_saved" as postDataException means you are saving the same "key" twice within a second.
}
});
}
//*************************************************GET Saved Progress-Data****************************************//
private static void GetUserDataExampleCode()
{
if (!Idnet.User.LoggedIn()) return;
//Example 1: Get a "String"
Idnet.I.Get<string>("MessageOfTheDay", (keyValuePair, getException) =>
{
if (getException != null)
{
Debug.Log("No Data returned for the key '" + keyValuePair.Key + "'");
// Callback: Get Data failed,probably no data available with this key on server,debug "getException" for the more details.
// "Key not found" as a "getException" means server do not contains any data corresponding to this key.
}
else
{
Debug.Log("Retrieved '" + keyValuePair.Key + "' with value '" + keyValuePair.Value);
// Callback: Data retrieved sucessfully,write your code here like saving to Playerprefs/variables,hence load game level.
/* Example Usage:
PlayerPrefs.SetString("Message",keyValuePair.Value);
Application.LoadLevel("Idnet Sample Scene"); */
}
});
//Example 2: Get a "Vector"
Idnet.I.Get<Vector3>("VectorPos", (keyValuePair, getException) =>
{
if (getException != null)
{
Debug.Log("No Data returned for the key '" + keyValuePair.Key + "'");
// Callback: Get Data failed,probably no data available with this key on server.
}
else
{
Debug.Log("Retrieved '" + keyValuePair.Key + "' with value '" + keyValuePair.Value + "'.");
// Callback: Data retrieved sucessfully,write your code here like saving to Playerprefs/variables,hence load game level.
}
});
//Example 2: Get an "Array"
Idnet.I.Get<string[]>("ExampleArray", (keyValuePair, getException) =>
{
if (getException != null)
{
Debug.Log("No Data returned for the key '" + keyValuePair.Key + "'");
// Callback: Get Data failed,probably no data available with this key on server.
}
else
{
string ArrayValues = string.Empty;
//keyValuePair.Value is an array you posted(string[] in this case)
foreach (var value in keyValuePair.Value)
{
//Debug.Log("Array values "+value);
ArrayValues += " | " + value;
}
Debug.Log("Retrieved '" + keyValuePair.Key + " with values " + ArrayValues);
}
});
// Example 3: Get a "Class"(Mostly used type)
// "UserProgressExampleData" created below,create your own class.
Idnet.I.Get<UserProgressExampleData>("UserProgress", (keyValuePair, getException) =>
{
if (getException != null)
{
Debug.Log("No Data returned for the key '" + keyValuePair.Key + "'");
// Callback: Get Data failed,probably no data available with this key on server.
}
else
{
Debug.Log("Retrieved '" + keyValuePair.Key + "' with value '" + keyValuePair.Value);
// Callback: Data retrieved sucessfully,write your code here,like saving to Playerprefs/variables & hence load game level.
/* Example:
PlayerPrefs.SetInt("Life",keyValuePair.Value.Lives);
PlayerPrefs.SetInt("TotalCoins",keyValuePair.Value.TotalCoins);
Application.LoadLevel("Idnet Sample Scene"); */
#if UNITY_EDITOR
Debug.Log("Example UserProgress: "
+ "\t" + keyValuePair.Value.NumOfLevelsUnlocked
+ "\t" + keyValuePair.Value.TotalCoins
+ "\t" + keyValuePair.Value.Lives
+ "\t" + keyValuePair.Value.MaxDistanceTravelled
+ "\t" + keyValuePair.Value.UnlockedCharacterName
+ "\t" + keyValuePair.Value.IsTutorialCompleted
);
#endif
}
});
}
//**************************************Example "Class" used for Post/Get API*************************************//
/// <summary>
/// Example "Class" for Post/Get data.
/// Post/Get,a lot of user's data with a single key using a Class.
/// Create your own custom class,as per your own usage.
/// Just change/delete variables in class below and in constructor,as per your own user data to be posted.
/// </summary>
internal class UserProgressExampleData
{
public bool IsTutorialCompleted;
public int Lives;
public float MaxDistanceTravelled;
public int NumOfLevelsUnlocked;
public int TotalCoins;
public string UnlockedCharacterName;
public UserProgressExampleData(int numlevels, int totalcoins, int lives, float maxdistance,
string charactername,
bool istutorialcompleted)
{
NumOfLevelsUnlocked = numlevels;
TotalCoins = totalcoins;
Lives = lives;
MaxDistanceTravelled = maxdistance;
UnlockedCharacterName = charactername;
IsTutorialCompleted = istutorialcompleted;
}
}
//**************************************Example2 "Class" used for Post/Get API*************************************//
/// <summary>
/// Example2 "Class" for Post/Get data.
/// </summary>
internal class UserProgressExample2
{
public int Coins;
public string Name;
public bool Showtutorial;
public UserProgressExample2(int coins, bool showtutorial, string name)
{
Coins = coins;
Showtutorial = showtutorial;
Name = name;
}
}
//**********************************************Show Achievements window******************************************//
/// <summary>
/// This Api opens IDnet Achievement GUI window(List all achievements in the game,both locked and unlocked ones)
/// Creating achievements on IDnet dashboard: http://dev.id.net/docs/unity/achievements/
/// For creating Custom Achievements(Achievements with your own UI),please have a look to
/// "CustomAchievementExample.cs".
/// </summary>
/// <remarks>
/// Pass your {app-id} here 'https://www.id.net/applications/{app-id}/achievements' ,to directly go to achievement
/// page.
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// Achievements Gui Api.
/// </remarks>
private void ListAchievementsExampleCode()
{
Idnet.I.ListAchievements();
}
//************************************************Unlock Achievements*********************************************//
/// <summary>
/// This Api unlock achievements,using Achievement "Name" and "Unlock Key".
/// Achievements "Name" and "Unlock Key" are obtained when you create achievements on IDnet dashboard.
/// </summary>
/// <remarks>
/// Online Docs: http://dev.id.net/docs/unity/achievements-unlock/
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before Unlock
/// Achievements Api.
/// </remarks>
private void UnlockAchievementExampleCode()
{
Idnet.AchievementUnlocker au;
//achievement to be unlocked.
au = new Idnet.AchievementUnlocker("Unity Test Achievement 1", "150e06bccaaa9d8422d9");
// "Unity Test Achievement 1" is the "Name" of achievement that you create at "https://www.id.net/applications/{app-id}/achievements" (Pass your app-id here.)
// "4b51803aac54decb4d7b" is the "Unlock Key" you get here "https://www.id.net/applications/{app-id}/achievements" (Pass your app-id here)
Idnet.I.UnlockAchievement(au);
}
//*******************************************Unlock Achievements with callbacks*****************************************//
/// <summary>
/// This Api unlock achievements,and you will get a callback after achievement is successfully unlocked.
/// Achievements "Name" and "Unlock Key" are obtained when you create achievements on IDnet dashboard.
/// </summary>
private void UnlockAchievementCallbackExampleCode()
{
Idnet.AchievementUnlocker au;
//achievement to be unlocked.
au = new Idnet.AchievementUnlocker("Unity Test Achievement 1", "150e06bccaaa9d8422d9");
// "Unity Test Achievement 1" is the "Name" of achievement that you create at "https://www.id.net/applications/{app-id}/achievements" (Pass your app-id here.)
// "4b51803aac54decb4d7b" is the "Unlock Key" you get here "https://www.id.net/applications/{app-id}/achievements" (Pass your app-id here)
Idnet.I.UnlockAchievement(au, unlockAchievementsException =>
{
if (unlockAchievementsException == null)
{
// Callback: Achievement Unlocked sucessfully.
Debug.Log("Achievement unlocked sucessfully: " + "\n" + au.Name + "\n" + au.Key);
}
else
{
// Callback: Achievement unlocking failed.
Debug.LogError("Unlock Achievements Failed: " + unlockAchievementsException);
}
});
}
//*******************************************Delete/Reset user's progress*****************************************//
/// <summary>
/// Used to Reset progress of user.
/// </summary>
private static void DeleteUserDataExampleCode()
{
if (!Idnet.User.LoggedIn()) return;
Idnet.I.DeleteKey("MessageOfTheDay");
}
//****************************************"Online Save" Button Click Code*****************************************//
/// <summary>
/// Live Game Visualisation: http://www.y8.com/games/bike_riders
/// Games should have 2 modes: "Online Save" and "Local Save",these buttons should be on the first screen of the game.
/// **Online-Save Concept**
/// ==> If user is Not logged-in to IDnet(i.e Idnet.User.LoggedIn()==false),and clicks on Online Save button,open IDnet
/// Login Gui window and after login is successfull "Get" all data from server using Get api(Login API callback) and
/// save to unity variables/playerprefs.
/// ==> If user already logged in to idnet using autologin or whatever means(i.e Idnet.User.LoggedIn()==true),just
/// "Get" all saved data using "Get" api.
/// **Local Save Concept**
/// Just load the game level normally,no need to Use "Get" api.
/// </summary>
private void OnlineSaveExampleCode()
{
// Let IDnet know your current game mode.
Idnet.I.CurrentMode = Idnet.GameMode.OnlineSave;
if (!Idnet.User.LoggedIn())
{
//If user not logged-in,open Login window and hence retrieve all saved data using Get API,if login is successfull.
Idnet.I.LoginRegister(loginRegisterException =>
{
if (Idnet.User.LoggedIn())
{
// User succesfully logged-in here.
Debug.Log("User logged in: " + "Nickname " + Idnet.User.Current.Nickname);
//Get all saved from server and hence load the level,as done in OnlineSaveGetDataExample();
OnlineSaveGetDataExample();
}
});
}
else
{
// User already logged-in,using cached-login(PlayerPrefs) or autologin,so Get all saved from server and hence load the level,as done in OnlineSaveGetDataExample().
OnlineSaveGetDataExample();
}
}
//****************************************"Local Save" button Example Code****************************************//
/// <summary>
/// **Local Save Concept**
/// Just load the game level normally,no need to Use "Get" api.
/// </summary>
private void LocalSaveExampleCode()
{
//Set Current Selected Mode of user.
Idnet.I.CurrentMode = Idnet.GameMode.LocalSave;
// Play the game normally,just load the gameplay level here.
}
//*************************************"Online Save" Get-Data Example Code****************************************//
/// <summary>
/// Online Save Get-Data Example Code.
/// </summary>
private void OnlineSaveGetDataExample()
{
Idnet.I.Get<UserProgressExampleData>("UserProgress", (keyValuePair, getException) =>
{
if (getException != null)
{
Debug.Log("Get failed for '" + keyValuePair.Key + "'" +
"probably no data available on server with this key");
// Callback: Get Data Failed(probably no data available on server with this key),load the next gameplay level here(No values to be saved in playerprefs).
// Examples Usage:
// Application.LoadLevel("Idnet Sample Scene"); //Load your game level here
}
else
{
Debug.Log("Retrieved '" + keyValuePair.Key + "' with value '" + keyValuePair.Value);
// Callback: Data retrieved sucessfully,write your code here like saving to unity variables/playerprefs,hence load game level too.
//Examples Usage below: Store "retrieved values" to unity variables/playerprefs,and use it in game.
PlayerPrefs.SetInt("Current_Level", keyValuePair.Value.NumOfLevelsUnlocked);
PlayerPrefs.SetInt("TotalCoins", keyValuePair.Value.TotalCoins);
PlayerPrefs.SetInt("Life", keyValuePair.Value.Lives);
PlayerPrefs.SetFloat("MaxDistanceTravelled", keyValuePair.Value.MaxDistanceTravelled);
PlayerPrefs.SetString("UnlockedCharacterName", keyValuePair.Value.UnlockedCharacterName);
PlayerPrefs.SetString("IsTutorialCompleted", keyValuePair.Value.IsTutorialCompleted.ToString());
// Application.LoadLevel("Idnet Sample Scene"); //Load your game level here
#if UNITY_EDITOR
Debug.Log("Example UserProgress: "
+ "\n" + keyValuePair.Value.NumOfLevelsUnlocked
+ "\n" + keyValuePair.Value.TotalCoins
+ "\n" + keyValuePair.Value.Lives
+ "\n" + keyValuePair.Value.MaxDistanceTravelled
+ "\n" + keyValuePair.Value.UnlockedCharacterName
+ "\n" + keyValuePair.Value.IsTutorialCompleted
);
#endif
}
});
}
//************************************"Multiple Leaderboards" per game Info***********************************//
/// <remarks>
/// If your game have more than 1 leaderboards(games with more than 1 levels,and each level has its own
/// leaderboard),follow steps below.
/// Firstly you need to create "leaderboard names" called tables,for each leaderboard of your game on "Applications
/// page" of id.net.
/// To directly go to "Create tables/leaderboard names" page,pass your {app-id} here:
/// https://www.id.net/applications/{app-id}/playtomic_tables# and create leaderboard/table names there.
/// Example of passing {app-id}: https://www.id.net/applications/55961a8 ... ic_tables#
/// Example of "Leaderboard/table names": "Level1 Leaderboard","Level2 Leaderboard","Highway Leaderboard","Mountain
/// Level","Level 1" etc.
/// You will need these "table/leaderboard names",to PostScore to a particular level leaderboard and hence opening
/// corresponding leaderboard window.
/// Online Docs: Create "Table" name (eg. Leaderboard) as explained here http://dev.id.net/docs/unity/table-setup
/// </remarks>
/// <summary>
/// Post Score to "Level 1" Leaderboard.
/// Make sure you have created table/leaderboard name "Level 1" on applications page
/// https://www.id.net/applications/{app-id}/playtomic_tables#
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// posting scores.
/// </summary>
private void PostScoreLevel1ExampleCode()
{
//Score posted must be an integer.
var exampleScore = 1000 + Random.Range(0, 1000);
//Make sure you have created table/leaderboard name "Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.PostHighscore(exampleScore, "Level 1");
}
//***************************************Post Score to "Level 2" leaderboard**************************************//
/// <summary>
/// Post Score to "Level 2" Leaderboard.
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// posting scores.
/// </summary>
private void PostScoreLevel2ExampleCode()
{
//Score posted must be an integer.
var exampleScore = 1000 + Random.Range(0, 1000);
//Make sure you have created table/leaderboard name "Level 2" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.PostHighscore(exampleScore, "Level 2");
}
//************************SubmitScore to "Level 1" and hence open "Level 1" leaderboard***************************//
/// <summary>
/// "Submit Score" Button code,this API post scores to "Level 1" Leaderboard and hence open corresponding leaderboard
/// window after post score is succesfull(Callback).
/// For Guest users(user not logged in to IDnet),it will automatically open Login GUI window.
/// </summary>
/// <remarks>
/// This "Submit Score" button should be present/used on gameover screen(if you are not automatically posting scores on
/// gameover using PostScore API).
/// For Alterations to this api,create your own Submit score api using PostScore callback
/// "PostScoreWithCallbackExampleCode()" or just open Idnet.cs and find SubmitHighScore() method and alter it.
/// Make sure you have created table/leaderboard name "Level 1" on applications page
/// https://www.id.net/applications/{app-id}/playtomic_tables# before using it.
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before submit
/// score api.
/// </remarks>
private static void SubmitScoreLevel1ExampleCode()
{
//exampleScore,Score posted must be an integer.
var exampleScore = 1001 + Random.Range(0, 1000);
//Make sure you have created table/leaderboard name "Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.SubmitHighScore(exampleScore, "Level 1");
}
//************************SubmitScore to "Level 2" and hence open "Level 2" leaderboard***************************//
/// <summary>
/// "Submit Score" Button code,this API post scores to "Level 2" Leaderboard and hence open corresponding leaderboard
/// window after post score is succesfull(Callback).
/// For Guest users(user not logged in to IDnet),it will automatically open Login GUI window.
/// </summary>
private static void SubmitScoreLevel2ExampleCode()
{
//exampleScore,Score posted must be an integer.
var exampleScore = 1001 + Random.Range(0, 1000);
//Make sure you have created table/leaderboard name "Level 2" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.SubmitHighScore(exampleScore, "Level 2");
}
//********************************************"Level 1" Leaderboard window****************************************//
/// <summary>
/// Open table "Level 1" 'Leaderboard' window.
/// Make sure you have created table/leaderboard name "Level 1" on applications page
/// https://www.id.net/applications/{app-id}/playtomic_tables#
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// Leaderboard GUI api.
/// </summary>
private static void LeaderboardLevel1ExampleCode()
{
//Make sure you have created table/leaderboard name "Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.Leaderboard("Level 1");
}
//********************************************"Level 2" Leaderboard window****************************************//
/// <summary>
/// Open table "Level 2" 'Leaderboard' window.
/// Make sure you have created table/leaderboard name "Level 2" on applications page
/// https://www.id.net/applications/{app-id}/playtomic_tables#
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// Leaderboard GUI api.
/// </summary>
private static void LeaderboardLevel2ExampleCode()
{
//Make sure you have created table/leaderboard name "Level 2" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.Leaderboard("Level 2");
}
//**********************************Get User's BestScore from "Level 1" leaderboard*******************************//
/// <summary>
/// Get BestScore of current logged-in user from "Level 1" leaderboard.
/// Dont use this API in Update() or OnGUI() obviously.
/// </summary>
private static void GetBestScoreFromLevel1Leaderboard()
{
//Make sure you have created table/leaderboard name "Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.GetBestScore("Level 1", bestScoreException =>
{
if (bestScoreException == null)
{
// Callback: Successfully retrieved BestScore of user.
Debug.Log("Idnet Best Score " + Idnet.User.Current.BestScore);
}
});
}
//*************************************"TIMER Leaderboards(mm:ss:ms)"*********************************************//
/// <remarks>
/// In case of Timer games like racing games,we must have Timer leaderboards in format min:sec:millisec (lower the
/// time,better it is).
/// API for posting "time" to IDnet leaderboard is same as normal score-posting API,but just write
/// "Idnet.I.TimerLeaderboard=true;" before using it.
/// Idnet.I.TimerLeaderboard=true; will make sure that Leaderboards will accept time(milliseconds) in leaderboard and
/// Leaderboard window will show "time" automatically in format mm:ss:ms.
/// Make sure you send "Milliseconds" while posting time to leaderboard.
/// Idnet.I.TimerLeaderboard=true; means "timer" leaderboards and "Idnet.I.TimerLeaderboard=false"(Default) means
/// normal "score" leaderboards.
/// </remarks>
/// <summary>
/// Post Time(it must be in milliseconds) to "Race Level 1" Leaderboard.
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before Post
/// Score api.
/// </summary>
private void PostTimeLevel1ExampleCode()
{
//Let idnet know that its a timer leaderboard.
Idnet.I.TimerLeaderboard = true;
//Time posted must be an "Milliseconds",here "127676698" is a milliseconds time.
var exampleTime = 127676698;
//Make sure you have created table/leaderboard name "Race Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.PostHighscore(exampleTime, "Race Level 1");
}
//********************************************Leaderboard "Timer" window******************************************//
/// <summary>
/// Open "Race Level 1" Timer Leaderboard.
/// NOTE: NO NEED for Logged-In user check here, i.e if (!Idnet.User.LoggedIn ()) return; is not needed before
/// Leaderboard GUI api.
/// </summary>
private void TimerLeaderboardLevel1ExampleCode()
{
//Let idnet know that its a timer leaderboard.
Idnet.I.TimerLeaderboard = true;
//Make sure you have created table/leaderboard name "Race Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.Leaderboard("Race Level 1");
}
//**********************Submit Time(ms) to "Race Level 1" and hence open Level 1 Leaderboard window*******************//
/// <summary>
/// Submit Time to "Race Level 1" Leaderbard window and hence open Leaderboard window after post score is successfull.
/// </summary>
private void SubmitTimeLevel1ExampleCode()
{
//Let idnet know that its a timer leaderboard.
Idnet.I.TimerLeaderboard = true;
var exampleTime = 127676698;
//Make sure you have created table/leaderboard name "Race Level 1" on applications page https://www.id.net/applications/{app-id}/playtomic_tables#
Idnet.I.SubmitHighScore(exampleTime, "Race Level 1");
}
//**************************************************Protection Api************************************************//
private static void BlacklistedWebsitesExampleCode()
{
Idnet.I.Protection(protectionException =>
{
if (protectionException == null)
{
if (Idnet.I.IsBlacklisted)
{
// Callback: Blacklisted website, open blacklisted game scene here.
Debug.Log("Website is blacklisted,disable the game here");
}
}
});
}
//*************************************************Sponser API****************************************************//
private static void SponserWebsitesExampleCode()
{
Idnet.I.Protection(protectionException =>
{
if (protectionException == null)
{
if (Idnet.I.IsSponsor)
{
// Callback: Game is Running on Y8's network,this api can also be used for sitelock/branding.
Debug.Log("Game is Running on Y8's network.");
}
}
});
}
//********************************************END OF CODE EXAMPLES:***********************************************//
private bool load;
//GUI for Sample scene
private void OnGUI()
{
GUI.skin = guiSkin;
//my correction
if (aTexture)
GUI.DrawTexture(new Rect(10, Screen.height- 160, 230, 150), aTexture, ScaleMode.StretchToFill, true, 10.0F);
var dynamicRect = new Rect(BORDER, BORDER, BOX_WIDTH, Screen.height - BORDER_X2);
// Minimize IdnetSample.
if (Idnet.I.IsShowingGui() || _minimized )
{
dynamicRect.height = BOX_HEIGHT_SMALL;
dynamicRect.width = BOX_WIDTH_SMALL;
}
// Title.
// GUI.Box(dynamicRect, "IDNET");
// Area.
GUILayout.BeginArea(new Rect((Screen.width)/2 - 45, Screen.height/2, dynamicRect.width - BORDER_X2,
dynamicRect.height - BORDER_X2));
// Minimize?
if (Idnet.I.IsShowingGui ()) {
// Do nothing.
} else {
// Content.
GUILayout.BeginHorizontal ();
GUILayout.BeginVertical ();
GUILayout.FlexibleSpace();
//GUI.color = Color.cyan;
//GUI.enabled = _allowErroneousApiCalls;
#if !UNITY_EDITOR
GUI.enabled = true;
#endif
// GUILayout.Label ("Users (Authentication)");
// if (GUILayout.Button ("AutoLogin", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
// AutoLoginGUIWindowCode ();
// }
GUI.enabled = !Idnet.User.LoggedIn ();
if (GUILayout.Button ("Login", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
LoginGUIWindowCode ();
}
GUI.enabled = !Idnet.User.LoggedIn ();
if (GUILayout.Button ("Register", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
RegisterGUIWindowCode ();
}
GUI.enabled = !Idnet.User.LoggedIn ();
if (GUILayout.Button ("Play as Guest", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
load = true;
NameFromAPI.mefirstname = "Player " + Random.Range(1, 1000) ;
Application.LoadLevel("MainMenu");
}
GUI.enabled = !GUI.enabled;
if (GUILayout.Button ("Logout", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
LogoutExampleCode ();
}
if (GUILayout.Button ("User Profile", GUILayout.MaxHeight (BUTTON_HEIGHT))) {
ProfileExampleCode ();
}
GUILayout.FlexibleSpace ();
}
GUILayout.EndArea();
GUI.enabled = Idnet.User.LoggedIn ();
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 200, 150, 50), "PLAY")) {
load = true;
//my correction
NameFromAPI.mefirstname = Idnet.User.Current.Nickname;
Application.LoadLevel ("MainMenu");
}
if(load)
GUI.Label (new Rect (Screen.width / 2 - 35, Screen.height / 2 + 270, 70, 50), "LOADING...");
}
}