Skip to content

vietplayfuri/Goplay_SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goplay-unity3d-sdk

Version 1.0

(Really) Quick-start Guide

This tutorial will go through the step-by-step instructions to integrate the Login feature to a Unity3d game project.

Requirements

Unity3D version 4.6 or later

Step 1: Import plugin

Open Unity Editor and double click package GoPlaySDK_v1.XX.unitypackage to import all necessary environment. Or you can choose Assets > Import Package > Custom Package… and choose GoPlaySDK _v1.XX.unitypackage location.

Step 2: Determine to connect to which server

GoPlay provides dev server and production server. To setup the Live server build or Test server build, configure the Boolean variable UseLiveServer in GoPlaySDK.cs. Set it to True to use production server, False for dev server.

public bool UseLiveServer {get; set;}

Step 3: Set up GAME_ID

To start using the SDK, we need to set up the GAME_ID of the current project. The value helps GoPlay server identify which game connecting to it. Choose from Unity3D menu, GoPlaySDK > Setting to open Setting Dialog.

Unity3D Setting

Step 4: Call Login API and get a response

GoPlaySDK uses an Event subscription mechanism. Each API call is a HTTP asynchronous web request. When a response callback is available, an Event will be triggered. Client application can easily subscribe to these events.

GoPlaySdk.Instance.OnLogin += OnLogin;

void OnLogin(IResult callback)
{
  var result = callback as LoginResult;
  if (result != null)
  {
    // Yipee…
  }
}

For a full listing of the source code sample, please refer to the sample Unity project in the SDK package.

API References

Table of contents

  1. API Calls
  2. Login
  3. Register
  4. Logout
  5. Get Profile
  6. Edit Profile
  7. Get Progress
  8. Save Progress
  9. Save Progress File
  10. Read Progress
  11. Update Game Stats
  12. Get Unfulfilled Exchanges
  13. Fulfill Exchange
  14. Reject Exchange
  15. Supporting Classes
  16. Session
  17. UserProfile
  18. Exchange
  19. GameStat

API Calls

Login

public void Login(string userName, string password)
public void Login(SocialPlatforms platform, string token)

This method perform a log-in to GoPlaySDK using a username and password. A user account must be available before calling this method. An event will be triggered when server callbacks. This event must be hooked up before calling this method.

If user login via facebook account, the server will bind the user with the facebook account for future auto-login.

Example:

GoPlaySdk.Instance.OnLogin+= HandleOnLogin;

GoPlaySdk.Instance.Login(Username.text, Password.text);

#####Input

Paramter Type Notes
username string Required parameter
password string Required parameter
Output (LoginResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Session string Access token for late requests
Profile UserProfile See UserProfile definition in Supporting Classes section
Error Messages
  • INVALID_USN_PWD - 'Username or Password is incorrect'
  • MISSING_FIELDS - 'Required field(s) is blank'
  • INVALID_GAME_ID - 'Invalid Game ID'

Register

public void Register(string userName, string password, string email = null, string nickName = null, Gender gender = Gender.Other, string referal = null)

This method is used to explicitly register a new customer account. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

If user registers by using a facebook account, the server will bind the user with the facebook account for future auto-login.

Example:

GoPlaySdk.Instance.OnRegister += OnRegister;

GoPlaySdk.Instance.Register(Username.text,Password.text,Email.text);

#####Input

Paramter Type Notes
username string Required Parameter. Must be unique.
password string Required parameter
email string
nickName string
gender string male, female, or other
referral string
Output (RegisterResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Session string Access token for late requests
Profile UserProfile See UserProfile definition in Supporting Classes section
Error Messages
  • EXISTING_USERNAME_EMAIL- 'Account with such username/email already exists'
  • MISSING_FIELDS - 'Required field(s) is blank'
  • INVALID_GAME_ID - 'Invalid Game ID'
  • USERNAME_LENGTH - 'Username is between 3-20 characters'
  • INVALID_USERNAME - 'Username does not accept special characters'
  • PASSWORD_LENGTH - 'Password must be more than 3 characters'

Logout

This method logs out a player from GoPlay server.

Example:

GoPlaySdk.Instance.LogOut();

Get Profile

public void GetProfile()

Call this method to retrieve the profile of a user. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnGetProfile += HandleOnGetProfile

GoPlaySdk.Instance.GetProfile();

#####Input

Paramter Type Notes
Output (profileResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Profile UserProfile See UserProfile definition in Supporting Classes section
Error Messages
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’

Edit Profile

public void EditProfile(string email=null, string nickName=null, Gender?  gender=null )

Call this method to updates the profile of a user. Parameters may be omitted, and those fields will be unchanged. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnEditProfile += HandleOnEditProfile;
GoPlaySdk.Instance.EditProfile(Email.text,NickName.text);

#####Input

Paramter Type Notes
email string
nickName string
gender string male, female, or other
Output (ProfileResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Profile UserProfile See UserProfile definition in Supporting Classes section
Error Messages
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’

Get Progress

public void GetProgress(bool sendData)

Call this method to retrieve game progress directly from GoPlay server. The progress is saved in a string field, either as xml or json. The progress is saved together with a meta field. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnGetProgress += HandleOnGetProgress;
GoPlaySdk.Instance.GetProgress (true);

#####Input

Paramter Type Notes
sendData bool True or False. Optional, default True. Choose if the response should include the game save data, decrease traffic on server and client when only meta data and save_at timestamp are needed.
Output (GetProgressResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Data string
Meta string
Error Messages
  • MISSING_FIELDS - ‘Required field(s) is blank’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’

Save Progress

public void SaveProgress(string data, string meta=null)

Call this method to save game progress to GoPlay server.

Example:

GoPlaySdk.Instance.OnSaveProgress += HandleOnSaveProgress;
GoPlaySdk.Instance.SaveProgess(data);

#####Input

Paramter Type Notes
data string Data to be sent to server
meta string Optional parameter
Output (SaveProgressResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Error Messages
  • MISSING_FIELDS - ‘Required field(s) is blank’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’

Save Progress File

public void SaveProgressFile(string fullPath, string meta=null)

Call this method to save game progress file of any extension to GoPlay server.

Example:

GoPlaySdk.Instance.OnSaveProgress += HandleOnSaveProgress;
GoPlaySdk.Instance.SaveProgessFile(Application.dataPath + "/Sample/Sample1/data.json");

#####Input

Paramter Type Notes
fullPath string Full path to the game progress storage file
meta string Optional parameter
Output (SaveProgressResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Error Messages
  • MISSING_FIELDS - ‘Required field(s) is blank’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’

Read Progress

public void ReadProgress(string fullPath)

Because the game progress storage file is protected, call this method to download game progress file from GoPlay server.

Example:

GoPlaySdk.Instance.OnReadProgress += HandleOnReadProgress;
GoPlaySdk.Instance.ReadProgress(Application.dataPath + "/Sample/Sample1/downloaded.json");

#####Input

Paramter Type Notes
fullPath string Full path where the game progress storage file should be saved
Output (ReadProgressResult)
Paramter Type Notes
Succeeded bool
FullPath string Full path where the game progress storage file was saved
Message string Human-readable error message
ErrorCode string Er'Filename does not exist'ror Code
Error Messages
  • MISSING_FIELDS - ‘Required field(s) is blank’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’
  • NON_EXISTING_FILENAME - 'Filename does not exist'
  • ERROR_READING_FILE

Update Game Stats

public void UpdateGameStats(string gameId, GameStats stats

Call this method in game client to save game stats directly to GoPlay server. The stat is saved as a string. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnUpdateGameStats += HandleOnUpdateGameStats;
GoPlaySdk.Instance.UpdateGameStats(GameId,gameStats);

#####Input

Paramter Type Notes
gameId guid Required Parameter.
stats array Required Parameter. Array of Game Stat. See Game Stat definition in Supporting Classes section
Output (UpdateGameStatsResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Error Messages
  • MISSING_FIELDS - ‘Required field(s) is blank’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_GAME_ID - ‘Invalid Game ID’
  • INVALID_GAME_STAT - ‘Invalid stat format. A stat JSON must include 3 keys title, value and public with their values.’

Get Unfulfilled Exchanges

public void GetUnFullFilledExchanges(string gameId)

Returns a list of unfulfilled exchanges made on GoPlay website An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnGetUnFullFilledExchanges+= HandleOnGetUnFullFilledExchanges;
GoPlaySdk.Instance.GetUnFullFilledExchanges() ;

#####Input

Paramter Type Notes
gameId guid Required Parameter.
Output (FullFillExchangeResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
Exchanges array Array of Exchange. See Exchange definition in Supporting Classes section
Error Messages
  • INVALID_GAME_ID - ‘Invalid Game ID’
  • INVALID_SESSION - ‘Invalid Session’

Fulfill Exchange

public void FullFillExchange(string gameId, string transactionId)

Call this method to fulfill an exchange made on GoPlay website. An event will be triggered when server callbacks. This event must be hooked up before calling the API.

Example:

GoPlaySdk.Instance.OnFullFillExchange+= HandleOnFullFillExchange;
GoPlaySdk.Instance.FulfillExchange(GameId,transId);

#####Input

Paramter Type Notes
gameId guid Required Parameter
transactionId uuid Required parameter
Output (FullFillExchangeResult)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Exchange Exchange The detail of the fulfilled exchange, for double checking. See Exchange definition in Supporting Classes section
Error Messages
  • INVALID_GAME_ID - ‘Invalid Game ID’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_TRANSACTION_ID - ‘Invalid Transaction ID’
  • TRANSACTION_ALREADY_PROCESSED - ‘Transaction has already been processed’

Reject Exchange

public void RejectExchange(string transactionId)

Reject an exchange made on GoPlay website. The rejected exchange’s status will be changed to failure and the user’s balance is redeemed.

Example:

GoPlaySdk.Instance.OnRejectExchange += HandleOnRejectExchange;
GoPlaySdk.Instance.RejectExchange(transactionId) ;

#####Input

Paramter Type Notes
transactionId uuid Required Parameter
Output (JSON)
Paramter Type Notes
Succeeded bool
Message string Human-readable error message
ErrorCode string Error Code
Exchange Exchange The detail of the rejected exchange, for double checking. See Exchange definition in Supporting Classes section
Error Messages
  • INVALID_GAME_ID - ‘Invalid Game ID’
  • INVALID_SESSION - ‘Invalid Session’
  • INVALID_TRANSACTION_ID - ‘Invalid Transaction ID’
  • TRANSACTION_ALREADY_PROCESSED - ‘Transaction has already been processed’

Supporting Classes

Session

Contains all information regarding the player’s session, such as session ID, game ID and current user.

Variable Type Notes
gameId GTGameID Hold GameID class
GameId string GameID guid type
HasLoggedIn boolean Whether the user has login before
CurrentUser UserProfile The current user
SessionId string Id of current session
GOPLAY_Session string store cache key for session

UserProfile

All the information about user such as username, password, Gender, etc.

Variable Type Notes
Id int
UserName string
NickName string
Email string
Gender Gender
VipStatus Vip
CountryCode string
GoPlayToken decimal
FreeGoPlayToken decimal

Exchange

This class holds information about user’s transactions.

Variable Type Notes
TransactionId Guid
ExchangeType ExchangeOptionTypes
ExchangeOptionIdentifier ExchangeOptionIdentifier
GoPlayTokenValue decimal
Quantity int
IsFree bool

GameStat

A JSON object representing a game stat, with the following keys:

Variable Type Notes
Title string
Value string
Public boolean