PrestoPad API Reference

Complete API documentation

API Reference

Core Classes

PrestoPadServerManager

Manages HTTP and WebSocket servers for controller communication.

Properties

Property Type Description
Instance PrestoPadServerManager Singleton instance
HttpPort int HTTP server port (default: 8080)
WebSocketPort int WebSocket server port (default: 8081)
IsHttpServerRunning bool Current server status
LocalIPAddress string Local device IP address
ControllerURL string Full controller URL for connection

Events

Event Description
OnHttpServerReady Fired when the HTTP server starts successfully

PrestoPadControllerDevice

Custom Input Device representing a connected smartphone controller.

Controls

Control Type Description
ButtonA ButtonControl A button (bottom action button)
ButtonB ButtonControl B button (right action button)
ButtonX ButtonControl X button (left action button)
ButtonY ButtonControl Y button (top action button)
StartButton ButtonControl Start button
SelectButton ButtonControl Select button
DPad DpadControl Directional pad (up, down, left, right)
LeftStick StickControl Analog joystick (Vector2)

Properties

Property Type Description
ControllerId int Unique controller identifier (1-12)
deviceId int Unity Input System device ID

Example Usage

void Update()
{
    if (controller == null) return;

    // Button press detection
    if (controller.ButtonA.wasPressedThisFrame)
        Jump();

    if (controller.ButtonA.isPressed)
        ChargeJump();

    if (controller.ButtonA.wasReleasedThisFrame)
        ReleaseJump();

    // Joystick input
    Vector2 movement = controller.LeftStick.ReadValue();
    Move(movement);

    // D-Pad discrete input
    if (controller.DPad.up.isPressed)
        MoveUp();
    if (controller.DPad.down.isPressed)
        MoveDown();
    if (controller.DPad.left.isPressed)
        MoveLeft();
    if (controller.DPad.right.isPressed)
        MoveRight();
}

InputSystemBridge

Bridges network messages to Unity's Input System.

Methods

Method Parameters Description
RegisterController int id Register a new controller by ID
UnregisterController int id Remove a controller by ID
UpdateControllerState int id, byte[] data Update controller input state from binary data

Configuration

PrestoPadServerConfig (ScriptableObject)

Configure server behavior through the Unity Inspector.

Network Settings

Setting Type Default Description
autoStartServers bool true Automatically start servers when enabled
httpPort int 8080 HTTP server port for serving web controller
webSocketPort int 8081 WebSocket port for real-time input
maxConnections int 6 Maximum simultaneous controllers (1-12)

Debug Settings

Setting Type Default Description
enableDebugLogging bool false Enable detailed console logging

Advanced Usage

Detecting Controller Connection/Disconnection

using UnityEngine;
using UnityEngine.InputSystem;
using PrestoPad.Input;

public class ControllerManager : MonoBehaviour
{
    private void OnEnable()
    {
        InputSystem.onDeviceChange += OnDeviceChange;
    }

    private void OnDisable()
    {
        InputSystem.onDeviceChange -= OnDeviceChange;
    }

    private void OnDeviceChange(InputDevice device, InputDeviceChange change)
    {
        if (device is PrestoPadControllerDevice controller)
        {
            switch (change)
            {
                case InputDeviceChange.Added:
                    HandleControllerConnected(controller);
                    break;
                case InputDeviceChange.Removed:
                    HandleControllerDisconnected(controller);
                    break;
            }
        }
    }

    void HandleControllerConnected(PrestoPadControllerDevice controller)
    {
        Debug.Log($"Controller {controller.ControllerId} connected!");
        // Assign to player, spawn character, etc.
    }

    void HandleControllerDisconnected(PrestoPadControllerDevice controller)
    {
        Debug.Log($"Controller {controller.ControllerId} disconnected!");
        // Handle cleanup, pause game, etc.
    }
}

Assigning Controllers to Specific Players

using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
using PrestoPad.Input;

public class PlayerSpawner : MonoBehaviour
{
    [SerializeField] private GameObject playerPrefab;
    [SerializeField] private Transform[] spawnPoints;

    private void OnEnable()
    {
        InputSystem.onDeviceChange += OnDeviceChange;
    }

    private void OnDeviceChange(InputDevice device, InputDeviceChange change)
    {
        if (device is PrestoPadControllerDevice controller)
        {
            if (change == InputDeviceChange.Added)
            {
                SpawnPlayerForController(controller);
            }
        }
    }

    void SpawnPlayerForController(PrestoPadControllerDevice controller)
    {
        int playerIndex = controller.ControllerId - 1; // 0-based index

        if (playerIndex >= 0 && playerIndex < spawnPoints.Length)
        {
            GameObject player = Instantiate(playerPrefab, spawnPoints[playerIndex]);

            // Assign controller to player
            var playerController = player.GetComponent();
            playerController.SetController(controller);
        }
    }
}

Theme Customization

The web controller interface can be customized using CSS themes:

Customizing Controller HTML

For advanced customization, you can modify the controller web interface directly:

Note: Changes to these files will affect all controllers. Make backups before modifying.