Skip to content

unity aircontroller

Peter Klooster edited this page Mar 13, 2019 · 1 revision

AirController (Unity)

The AirController is the base class that handles everything, even though AirController works out of the box it is advised that the AirController, Device and Player classes get extended for custom behavior.

AirController editor window

Minimal implementation

using SwordGC.AirController;

public class ExampleAirController : AirController {

    public override Player GetNewPlayer(int playerId)
    {
        return new ExamplePlayer(playerId);
    }

    protected override Device GetNewDevice (int deviceId)
    {
        return new ExampleDevice(deviceId);
    }
}

Variables

// TOGETHER: All devices get marked hero.
// SEPERATE: Only the hero device will be marked hero.
public enum HEROMODE { TOGETHER, SEPERATE }
public HEROMODE heroMode = HEROMODE.TOGETHER;

// AUTO: A device will automatically try to claim a player
// CUSTOM: A device won't claim a player (for a join now screen?). 
// 
// Note: When set to custom you can easily claim a player by sending a button called "claim" from the device
public enum JOINMODE { AUTO, CUSTOM }
public JOINMODE joinMode = JOINMODE.AUTO;

// AUTO: The system will create a player for each device.
// LIMITED: The system will create the specified amount of players and will only allow that many
public enum MAXPLAYERSMODE { AUTO, LIMITED }
public MAXPLAYERSMODE maxPlayersMode = MAXPLAYERSMODE.AUTO;

// Becomes true when the AirConsole plugin is ready
public bool IsReady { get; private set; }

// Becomes true when OnPremium is called
public bool HasHero { get; private set; }

// The maximum amount of players when maxPlayersMode is set to LIMITED
public int maxPlayers = 4;

// Turns all debugs on and off
public bool debug = true;

// Set to true if the savedata needs to be loaded when a device connects
public bool autoLoadSavedata = false;

// Contains all players
public Dictionary<int, Player> Players { get; protected set; }

// The amount of players that are created but not claimed
public int PlayersAvailable;

// Contains all devices
public Dictionary<int, Device> Devices { get; protected set; }

// The code in string form which controllers can use to connect to the game.
// Defaults as "" but is updated in the onReady call.
public string Code { get; private set; }

Callbacks

// Is called when a player is claimed
public virtual void OnPlayerClaimed (Player player){}

// Is called when a player is unclaimed
public virtual void OnPlayerUnclaimed (Player player){}

// Is called when a player is disconnected
public virtual void OnPlayerDisconnected (Player player){}

// Is called when a device is connected
public virtual void OnDeviceConnected (Device device){}

// Is called when a device is disconnected
public virtual void OnDeviceDisconnected (Device device){}

// Is called when a device is reconnected
public virtual void OnDeviceReconnected (Device device){}

Methods

Note: The AirController already includes all AirConsole functions as virtual voids, which can all be overriden.

// Called when a new player is needed, override this function to insert your own Player extended class
public virtual Player GetNewPlayer (int playerId) {}

// Returns the matching player, returns null when none is found
public Player GetPlayer(int playerId) {}

// Call this to reset all players to it's default state. (Which is none, or maxPlayers when maxPlayerMode == LIMITED
public void ResetPlayers() {}

// Claims a player for a device
public void ClaimPlayer(int deviceId) {}

// Unclaim a player from a device
public void UnclaimPlayer(int deviceId) {}

// Tries to reconnect a device to a previously claimed player
public bool ReconnectWithPlayer (int deviceId) {}

// Returns the matching Device, returns null when none is found
public Device GetDevice (int deviceId) {}

// Called when a new device is needed, override this function to insert your own Device extended class
protected virtual Device GetNewDevice (int deviceId) {}

// Checks if a device has a player object
public bool DeviceHasPlayer(int deviceId) {}

// Return the player based on a deviceId
public Player GetPlayerFromDevice(int deviceId) {}

// Sends the current device states to the devices
public void UpdateDeviceStates() {}

// Resets the input, is called on LateUpdate
public void ResetInput() {}

// Saves the savedata of all devices
public void SaveData (){}

// Saves the savedata of a device
public void SaveData (Device device){}

Clone this wiki locally