Sign in

The best practice is to start the sign-in flow right after the application start.

All you need to do is to call the Connect function:

UM_GameServiceManager.instance.Connect();

 

The following code snippet shows how you can subscribe for the connect / disconnect actions:

UM_GameServiceManager.OnPlayerConnected += OnPlayerConnected;
UM_GameServiceManager.OnPlayerDisconnected += OnPlayerDisconnected;

private void OnPlayerConnected() {
	Debug.Log("Player Connected");
}
	

private void OnPlayerDisconnected() {
	Debug.Log("Player Disconnected");
}

 

 

You can always find out the current connection state with the ConnectionSate property.

UM_GameServiceManager.instance.ConnectionSate

 

You may also use Disconnect method if you want to disconnect from the Game Service.

UM_GameServiceManager.instance.Disconnect();

 

Note: The Method does nothing on the IOS platform due to the Game Center API guidelines.

 

The code snippet below shows how to check if a player is currently connected to the game service.

if(UM_GameServiceManager.instance.ConnectionSate == UM_ConnectionState.CONNECTED) 

 

Available connection states:

public enum UM_ConnectionState  {
	UNDEFINED,
	CONNECTING,
	CONNECTED,
	DISCONNECTED
}

 

After a player is successfully connected, you may use player's properties to retrieve information about a current player. The code snippet below shows how to display player's name, id and avatar with Unity GUI:

if(UM_GameServiceManager.instance.player != null) {
	GUI.Label(new Rect(100, 10, Screen.width, 40), "ID: " + UM_GameServiceManager.instance.player.PlayerId);
	GUI.Label(new Rect(100, 20, Screen.width, 40), "Name: " +  UM_GameServiceManager.instance.player.Name);
	if(UM_GameServiceManager.instance.player.Avatar != null) {
		GUI.DrawTexture(new Rect(10, 10, 75, 75), UM_GameServiceManager.instance.player.Avatar);
	}
}

 

The player property is represented as GameServicePlayerTemplate object. 

public class GameServicePlayerTemplate  {
    public string PlayerId {get;}
    public string Name {get;}
    public Texture2D Avatar {get;}
    public GameCenterPlayerTemplate GameCenterPlayer {get;}
    public GooglePlayerTemplate GooglePlayPlayer {get;}
}

public class GameCenterPlayerTemplate {
    public string playerId {get;}
	public string alias {get;}
	public string displayName {get;} 
	public Texture2D avatar {get;}
}

public class GooglePlayerTemplate {
    public string playerId {get;}
	public string name {get;}
	public bool hasIconImage {get;}
	public bool hasHiResImage {get;}
	public string iconImageUrl {get;}
	public string hiResImageUrl {get;}
	public Texture2D icon {get;}
	public Texture2D image {get;}
}

 

 

The full API use example can be found under the UM_GameServiceBasics example scene.