C# Class NDream.AirConsole.AirConsole

Inheritance: UnityEngine.MonoBehaviour
显示文件 Open project: AirConsole/airconsole-unity-plugin Class Usage Examples

Public Properties

Property Type Description
androidTvGameVersion string
androidUIResizeMode AndroidUIResizeMode
autoScaleCanvas bool
browserStartMode StartMode
controllerHtml UnityEngine.Object
webViewLoadingSprite UnityEngine.Sprite

Private Properties

Property Type Description
AllocateDeviceSlots void
Awake void
GetDevice JToken
GetGameUrl string
InitWebView void
OnAdComplete void
OnAdShow void
OnApplicationPause void
OnApplicationQuit void
OnClose void
OnConnect void
OnCustomDeviceStateChange void
OnDeviceProfileChange void
OnDeviceStateChange void
OnDisable void
OnDisconnect void
OnGameEnd void
OnHighScoreStored void
OnHighScores void
OnLaunchApp void
OnMessage void
OnPersistentDataLoaded void
OnPersistentDataStored void
OnPremium void
OnReady void
OnSceneLoaded void
OnUnityWebviewPlatformReady void
OnUnityWebviewResize void
Start void
StopWebsocketServer void
Update void

Public Methods

Method Description
Broadcast ( object data ) : void

Sends a message to all devices.

ConvertDeviceIdToPlayerNumber ( int device_id ) : int

Returns the player number for a device_id, if the device_id is part of the active players previously set by the screen by calling setActivePlayers. Player numbers are zero based and are consecutive. If the device_id is not part of the active players, this function returns -1.

ConvertPlayerNumberToDeviceId ( int player_number ) : int

Returns the device_id of a player, if the player is part of the active players previously set by the screen by calling setActivePlayers. If fewer players are in the game than the passed in player_number or the active players have not been set by the screen, this function returns undefined.

GetControllerDeviceIds ( ) : List

Returns all controller device ids that have loaded your game.

GetCustomDeviceState ( int device_id = -1 ) : JToken

Gets the custom DeviceState of a device.

GetDeviceId ( ) : int

Returns the device_id of this device. Every device in a AirConsole session has a device_id. The screen always has device_id 0. You can use the AirConsole.SCREEN constant instead of 0. All controllers also get a device_id. You can NOT assume that the device_ids of controllers are consecutive or that they start at 1. DO NOT HARDCODE CONTROLLER DEVICE IDS! If you want to have a logic with "players numbers" (Player 0, Player 1, Player 2, Player 3) use the setActivePlayers helper function! You can hardcode player numbers, but not device_ids. Within an AirConsole session, devices keep the same device_id when they disconnect and reconnect. Different controllers will never get the same device_id in a session. Every device_id remains reserved for the device that originally got it. For more info read http:// developers.airconsole.com/#/guides/device_ids_and_states

GetMasterControllerDeviceId ( ) : int

Returns the device ID of the master controller.

GetNickname ( int device_id = -1 ) : string

Returns the nickname of a user.

GetPremiumDeviceIds ( ) : List

Returns all device Ids that are premium.

GetProfilePicture ( String uid, int size = 64 ) : string

Returns the url to a profile picture of a user.

GetProfilePicture ( int device_id = -1, int size = 64 ) : string

Returns the url to a profile picture of a user.

GetServerTime ( ) : long

Returns the current time on the game server. This allows you to have a synchronized clock: You can send the servertime in a message to know exactly at what point something happened on a device.

GetUID ( int device_id = -1 ) : string

Returns the globally unique id of a device.

GetUrl ( StartMode mode ) : string
IsAirConsoleUnityPluginReady ( ) : bool

Determines whether the AirConsole Unity Plugin is ready. Use onReady event instead if possible.

IsPremium ( int device_id = -1 ) : bool

Returns true if the device is premium

IsUserLoggedIn ( int device_id = -1 ) : bool

Returns true if a user is logged in.

Message ( int to, object data ) : void

Sends a message to another device.

NavigateHome ( ) : void

Request that all devices return to the AirConsole store.

NavigateTo ( string url ) : void

Request that all devices load a game by url. Note that the custom DeviceStates are preserved. If you don't want that, override SetCustomDeviceState(null) on every device before calling this function.

ProcessJS ( string data ) : void
RequestHighScores ( string level_name, string level_version, List uids = null, List ranks = null, int total = -1, int top = -1 ) : void

Requests high score data of players (including global high scores and friends). Will call onHighScores when data was received.

RequestPersistentData ( List uids = null ) : void

Requests persistent data from the servers. Will call onPersistentDataLoaded when data was received.

SetActivePlayers ( int max_players = -1 ) : void

Takes all currently connected controllers and assigns them a player number. Can only be called by the screen. You don't have to use this helper function, but this mechanism is very convenient if you want to know which device is the first player, the second player, the third player ... The assigned player numbers always start with 0 and are consecutive. You can hardcode player numbers, but not device_ids. Once the screen has called setActivePlayers you can get the device_id of the first player by calling convertPlayerNumberToDeviceId(0), the device_id of the second player by calling convertPlayerNumberToDeviceId(1), ... You can also convert device_ids to player numbers by calling convertDeviceIdToPlayerNumber(device_id). You can get all device_ids that are active players by calling getActivePlayerDeviceIds(). The screen can call this function every time a game round starts.

SetCustomDeviceState ( object data ) : void

Sets the custom DeviceState of this device.

SetCustomDeviceStateProperty ( string key, object value ) : void

Sets a property in the custom DeviceState of this device.

ShowAd ( ) : void

Requests that AirConsole shows a multiscreen advertisment. onAdShow is called on all connected devices if an advertisement is shown (in this event please mute all sounds). onAdComplete is called on all connected devices when the advertisement is complete or no advertisement was shown.

ShowDefaultUI ( bool visible ) : void

Shows or hides the default UI.

StoreHighScore ( string level_name, string level_version, float score, List uids, Newtonsoft.Json.Linq.JObject data = null, string score_string = null ) : void

Stores a high score of the current user on the AirConsole servers. High scores may be returned to anyone. Do not include sensitive data. Only updates the high score if it was a higher or same score. Calls onHighScoreStored when the request is done. The name of the level the user was playing. This should be a human readable string because it appears in the high score sharing image. You can also just pass an empty string. The version of the level the user was playing. This is for your internal use. The score the user has achieved The UIDs of the users that achieved the high score. Custom high score data (e.g. can be used to implement Ghost modes or include data to verify that it is not a fake high score). A short human readable representation of the score. (e.g. "4 points in 3s"). Defaults to "X points" where x is the score converted to an integer.

StoreHighScore ( string level_name, string level_version, float score, string uid, Newtonsoft.Json.Linq.JObject data = null, string score_string = null ) : void

Stores a high score of the current user on the AirConsole servers. High scores may be returned to anyone. Do not include sensitive data. Only updates the high score if it was a higher or same score. Calls onHighScoreStored when the request is done. The name of the level the user was playing. This should be a human readable string because it appears in the high score sharing image. You can also just pass an empty string. The version of the level the user was playing. This is for your internal use. The score the user has achieved The UID of the user that achieved the high score. Custom high score data (e.g. can be used to implement Ghost modes or include data to verify that it is not a fake high score). A short human readable representation of the score. (e.g. "4 points in 3s"). Defaults to "X points" where x is the score converted to an integer.

StorePersistentData ( string key, JToken value, string uid = null ) : void

Stores a key-value pair persistently on the AirConsole servers. Storage is per game. Total storage can not exceed 1 MB per game and uid. Will call onPersistentDataStored when the request is done.

Private Methods

Method Description
AllocateDeviceSlots ( int i ) : void
Awake ( ) : void
GetDevice ( int deviceId ) : JToken
GetGameUrl ( string url ) : string
InitWebView ( ) : void
OnAdComplete ( Newtonsoft.Json.Linq.JObject msg ) : void
OnAdShow ( Newtonsoft.Json.Linq.JObject msg ) : void
OnApplicationPause ( bool pauseStatus ) : void
OnApplicationQuit ( ) : void
OnClose ( ) : void
OnConnect ( Newtonsoft.Json.Linq.JObject msg ) : void
OnCustomDeviceStateChange ( Newtonsoft.Json.Linq.JObject msg ) : void
OnDeviceProfileChange ( Newtonsoft.Json.Linq.JObject msg ) : void
OnDeviceStateChange ( Newtonsoft.Json.Linq.JObject msg ) : void
OnDisable ( ) : void
OnDisconnect ( Newtonsoft.Json.Linq.JObject msg ) : void
OnGameEnd ( Newtonsoft.Json.Linq.JObject msg ) : void
OnHighScoreStored ( Newtonsoft.Json.Linq.JObject msg ) : void
OnHighScores ( Newtonsoft.Json.Linq.JObject msg ) : void
OnLaunchApp ( Newtonsoft.Json.Linq.JObject msg ) : void
OnMessage ( Newtonsoft.Json.Linq.JObject msg ) : void
OnPersistentDataLoaded ( Newtonsoft.Json.Linq.JObject msg ) : void
OnPersistentDataStored ( Newtonsoft.Json.Linq.JObject msg ) : void
OnPremium ( Newtonsoft.Json.Linq.JObject msg ) : void
OnReady ( Newtonsoft.Json.Linq.JObject msg ) : void
OnSceneLoaded ( Scene scene, LoadSceneMode sceneMode ) : void
OnUnityWebviewPlatformReady ( Newtonsoft.Json.Linq.JObject msg ) : void
OnUnityWebviewResize ( Newtonsoft.Json.Linq.JObject msg ) : void
Start ( ) : void
StopWebsocketServer ( ) : void
Update ( ) : void

Method Details

Broadcast() public method

Sends a message to all devices.
public Broadcast ( object data ) : void
data object The message to send.
return void

ConvertDeviceIdToPlayerNumber() public method

Returns the player number for a device_id, if the device_id is part of the active players previously set by the screen by calling setActivePlayers. Player numbers are zero based and are consecutive. If the device_id is not part of the active players, this function returns -1.
public ConvertDeviceIdToPlayerNumber ( int device_id ) : int
device_id int Device id.
return int

ConvertPlayerNumberToDeviceId() public method

Returns the device_id of a player, if the player is part of the active players previously set by the screen by calling setActivePlayers. If fewer players are in the game than the passed in player_number or the active players have not been set by the screen, this function returns undefined.
public ConvertPlayerNumberToDeviceId ( int player_number ) : int
player_number int Player Number.
return int

GetControllerDeviceIds() public method

Returns all controller device ids that have loaded your game.
public GetControllerDeviceIds ( ) : List
return List

GetCustomDeviceState() public method

Gets the custom DeviceState of a device.
public GetCustomDeviceState ( int device_id = -1 ) : JToken
device_id int The device ID of which you want the custom state. Default is this device.
return JToken

GetDeviceId() public method

Returns the device_id of this device. Every device in a AirConsole session has a device_id. The screen always has device_id 0. You can use the AirConsole.SCREEN constant instead of 0. All controllers also get a device_id. You can NOT assume that the device_ids of controllers are consecutive or that they start at 1. DO NOT HARDCODE CONTROLLER DEVICE IDS! If you want to have a logic with "players numbers" (Player 0, Player 1, Player 2, Player 3) use the setActivePlayers helper function! You can hardcode player numbers, but not device_ids. Within an AirConsole session, devices keep the same device_id when they disconnect and reconnect. Different controllers will never get the same device_id in a session. Every device_id remains reserved for the device that originally got it. For more info read http:// developers.airconsole.com/#/guides/device_ids_and_states
public GetDeviceId ( ) : int
return int

GetMasterControllerDeviceId() public method

Returns the device ID of the master controller.
public GetMasterControllerDeviceId ( ) : int
return int

GetNickname() public method

Returns the nickname of a user.
public GetNickname ( int device_id = -1 ) : string
device_id int The device id for which you want the nickname. Default is this device. Screens don't have nicknames.
return string

GetPremiumDeviceIds() public method

Returns all device Ids that are premium.
public GetPremiumDeviceIds ( ) : List
return List

GetProfilePicture() public method

Returns the url to a profile picture of a user.
public GetProfilePicture ( String uid, int size = 64 ) : string
uid String The uid for which you want a profile picture. Screens don't have profile pictures.
size int The size of in pixels of the picture. Default is 64.
return string

GetProfilePicture() public method

Returns the url to a profile picture of a user.
public GetProfilePicture ( int device_id = -1, int size = 64 ) : string
device_id int The device id for which you want a profile picture. Defaults to this device. Screens don't have profile pictures.
size int The size of in pixels of the picture. Default is 64.
return string

GetServerTime() public method

Returns the current time on the game server. This allows you to have a synchronized clock: You can send the servertime in a message to know exactly at what point something happened on a device.
public GetServerTime ( ) : long
return long

GetUID() public method

Returns the globally unique id of a device.
public GetUID ( int device_id = -1 ) : string
device_id int The device id for which you want the uid. Default is this device.
return string

GetUrl() public static method

public static GetUrl ( StartMode mode ) : string
mode StartMode
return string

IsAirConsoleUnityPluginReady() public method

Determines whether the AirConsole Unity Plugin is ready. Use onReady event instead if possible.
public IsAirConsoleUnityPluginReady ( ) : bool
return bool

IsPremium() public method

Returns true if the device is premium
public IsPremium ( int device_id = -1 ) : bool
device_id int The device_id that should be checked. Only controllers can be premium. Default is this device.
return bool

IsUserLoggedIn() public method

Returns true if a user is logged in.
public IsUserLoggedIn ( int device_id = -1 ) : bool
device_id int
return bool

Message() public method

Sends a message to another device.
public Message ( int to, object data ) : void
to int The device ID to send the message to.
data object The data to send.
return void

NavigateHome() public method

Request that all devices return to the AirConsole store.
public NavigateHome ( ) : void
return void

NavigateTo() public method

Request that all devices load a game by url. Note that the custom DeviceStates are preserved. If you don't want that, override SetCustomDeviceState(null) on every device before calling this function.
public NavigateTo ( string url ) : void
url string
return void

ProcessJS() public method

public ProcessJS ( string data ) : void
data string
return void

RequestHighScores() public method

Requests high score data of players (including global high scores and friends). Will call onHighScores when data was received.
public RequestHighScores ( string level_name, string level_version, List uids = null, List ranks = null, int total = -1, int top = -1 ) : void
level_name string The name of the level.
level_version string The version of the level.
uids List An array of UIDs of the users should be included in the result. Default is all connected controllers.
ranks List An array of high score rank types. High score rank types can include data from across the world, only a specific area or a users friends. Valid array entries are "world", "country", "region", "city", "friends". Default is ["world"].
total int Amount of high scores to return per rank type. Default is 8.
top int Amount of top high scores to return per rank type. top is part of total. Default is 5.
return void

RequestPersistentData() public method

Requests persistent data from the servers. Will call onPersistentDataLoaded when data was received.
public RequestPersistentData ( List uids = null ) : void
uids List The uids for which you would like to request the persistent data. Default is this device.
return void

SetActivePlayers() public method

Takes all currently connected controllers and assigns them a player number. Can only be called by the screen. You don't have to use this helper function, but this mechanism is very convenient if you want to know which device is the first player, the second player, the third player ... The assigned player numbers always start with 0 and are consecutive. You can hardcode player numbers, but not device_ids. Once the screen has called setActivePlayers you can get the device_id of the first player by calling convertPlayerNumberToDeviceId(0), the device_id of the second player by calling convertPlayerNumberToDeviceId(1), ... You can also convert device_ids to player numbers by calling convertDeviceIdToPlayerNumber(device_id). You can get all device_ids that are active players by calling getActivePlayerDeviceIds(). The screen can call this function every time a game round starts.
public SetActivePlayers ( int max_players = -1 ) : void
max_players int
return void

SetCustomDeviceState() public method

Sets the custom DeviceState of this device.
public SetCustomDeviceState ( object data ) : void
data object The custom data to set.
return void

SetCustomDeviceStateProperty() public method

Sets a property in the custom DeviceState of this device.
public SetCustomDeviceStateProperty ( string key, object value ) : void
key string
value object
return void

ShowAd() public method

Requests that AirConsole shows a multiscreen advertisment. onAdShow is called on all connected devices if an advertisement is shown (in this event please mute all sounds). onAdComplete is called on all connected devices when the advertisement is complete or no advertisement was shown.
public ShowAd ( ) : void
return void

ShowDefaultUI() public method

Shows or hides the default UI.
public ShowDefaultUI ( bool visible ) : void
visible bool Whether to show or hide the default UI.
return void

StoreHighScore() public method

Stores a high score of the current user on the AirConsole servers. High scores may be returned to anyone. Do not include sensitive data. Only updates the high score if it was a higher or same score. Calls onHighScoreStored when the request is done. The name of the level the user was playing. This should be a human readable string because it appears in the high score sharing image. You can also just pass an empty string. The version of the level the user was playing. This is for your internal use. The score the user has achieved The UIDs of the users that achieved the high score. Custom high score data (e.g. can be used to implement Ghost modes or include data to verify that it is not a fake high score). A short human readable representation of the score. (e.g. "4 points in 3s"). Defaults to "X points" where x is the score converted to an integer.
public StoreHighScore ( string level_name, string level_version, float score, List uids, Newtonsoft.Json.Linq.JObject data = null, string score_string = null ) : void
level_name string
level_version string
score float
uids List
data Newtonsoft.Json.Linq.JObject
score_string string
return void

StoreHighScore() public method

Stores a high score of the current user on the AirConsole servers. High scores may be returned to anyone. Do not include sensitive data. Only updates the high score if it was a higher or same score. Calls onHighScoreStored when the request is done. The name of the level the user was playing. This should be a human readable string because it appears in the high score sharing image. You can also just pass an empty string. The version of the level the user was playing. This is for your internal use. The score the user has achieved The UID of the user that achieved the high score. Custom high score data (e.g. can be used to implement Ghost modes or include data to verify that it is not a fake high score). A short human readable representation of the score. (e.g. "4 points in 3s"). Defaults to "X points" where x is the score converted to an integer.
public StoreHighScore ( string level_name, string level_version, float score, string uid, Newtonsoft.Json.Linq.JObject data = null, string score_string = null ) : void
level_name string
level_version string
score float
uid string
data Newtonsoft.Json.Linq.JObject
score_string string
return void

StorePersistentData() public method

Stores a key-value pair persistently on the AirConsole servers. Storage is per game. Total storage can not exceed 1 MB per game and uid. Will call onPersistentDataStored when the request is done.
public StorePersistentData ( string key, JToken value, string uid = null ) : void
key string The key of the data entry.
value JToken The value of the data entry.
uid string The uid for which the data should be stored. Default is this device.
return void

Property Details

androidTvGameVersion public_oe property

public string androidTvGameVersion
return string

androidUIResizeMode public_oe property

public AndroidUIResizeMode androidUIResizeMode
return AndroidUIResizeMode

autoScaleCanvas public_oe property

public bool autoScaleCanvas
return bool

browserStartMode public_oe property

public StartMode browserStartMode
return StartMode

controllerHtml public_oe property

public Object,UnityEngine controllerHtml
return UnityEngine.Object

webViewLoadingSprite public_oe property

public Sprite,UnityEngine webViewLoadingSprite
return UnityEngine.Sprite