Migrieren Sie zum 1.0.0-beta Input SDK

In dieser Anleitung wird beschrieben, wie Sie Ihr Unity-Spiel zur Verwendung des neuesten Input SDK migrieren. Das 1.0.0-beta SDK bietet erhebliche Verbesserungen im Vergleich zur vorherigen 0.0.4-Vorschau. Sie sollten so schnell wie möglich von den vorherigen Vorschauen migrieren. Das SDK 0.0.4 funktioniert noch bis März 2023.

Verweise aktualisieren

Klassen haben das Präfix Play erhalten, um Namenskonflikte mit Unity zu vermeiden. Wenn eine Fehlermeldung wie die folgende angezeigt wird:

Fehler CS0246: Der Typ- oder Namespace-Name "InputMappingProvider" konnte nicht gefunden werden (fehlen Sie eine using-Anweisung oder eine Assembly-Referenz?)

müssen Sie dem Klassennamen das Präfix Play hinzufügen. Aus InputMappingProvider wird beispielsweise PlayInputMappingProvider.

Jede InputAction aktualisieren

InputAction wird jetzt mit einem Aufruf von PlayInputAction.Create erstellt, anstatt eine neue struct mit benannten Feldern zu erstellen.

Suchen Sie nach jedem Code, der new InputAction aufruft:

var driveAction = new InputAction
{
    ActionLabel = "Drive",
    UniqueId = (int)InputEventIds.DRIVE,
    InputControls = new InputControls
    {
        AndroidKeycodes = new[] { AndroidKeyCode.KEYCODE_SPACE }
    }
};

Ersetzen Sie ihn durch einen Aufruf von PlayInputAction.Create:

var driveAction = PlayInputAction.Create(
    "Drive",
    (int)InputEventIds.DRIVE,
    PlayInputControls.Create(
        new[] { AndroidKeyCode.KEYCODE_SPACE },
        null
    )
);

Jede InputGroup aktualisieren

Wie InputAction hat auch InputGroup jetzt einen PlayInputGroup.Create-Aufruf, anstatt ein struct manuell ausfüllen zu müssen.

Das bedeutet, dass Sie alle Aufrufe von new InputGroup ermitteln sollten:

var gameInputGroup = new InputGroup
{
    GroupLabel = "Game controls",
    InputActions = new List<InputAction>
    {
        driveAction,
        turboAction,
        openGarageAction,
        openStoreAction
    }
};

Ersetzen Sie es durch einen Aufruf von PlayInputGroup.Create:

var gameInputGroup = PlayInputGroup.Create(
    "Game controls",
    new List<PlayInputAction>
    {
        driveAction,
        turboAction,
        openGarageAction,
        openStoreAction
    }
);

InputMap aktualisieren

Für InputMap wird auch PlayInputMap.Create verwendet, anstatt eine neue Struktur zu erstellen.

Suchen Sie alle Aufrufe von new InputMap:

return new InputMap
{
    InputGroups = new List<InputGroup>
    {
        gameInputGroup,
        menuInputGroup
    },
    MouseSettings = new MouseSettings
    {
        AllowMouseSensitivityAdjustment = false,
        InvertMouseMovement = false
    }
};

Ersetzen Sie ihn durch einen Aufruf von PlayInputMap.Create:

return PlayInputMap.Create(
    new List<PlayInputGroup>
    {
        gameInputGroup,
        menuInputGroup
    },
    PlayMouseSettings.Create(false, false)
);

PlayInputMappingClient-Methoden umbenennen

Für PlayInputMappingClient wurde RegisterInputMappingProvider in SetInputMappingProvider umbenannt.

Suchen Sie also alle Aufrufe von RegisterInputMappingProvider:

Input.GetInputMappingClient().RegisterInputMappingProvider(_inputMappingProvider);

Ersetzen Sie sie durch einen Aufruf von SetInputMappingProvider:

PlayInputMappingClient inputMappingClient =
    Google.Play.InputMapping.PlayInput.GetInputMappingClient();
inputMappingClient.SetInputMappingProvider(_inputMapProvider);

UnregisterInputMappingProvider wurde ebenfalls in ClearInputMappingProvider umbenannt und benötigt die zuvor registrierte InputMappingProvider nicht mehr als Parameter.

Suchen Sie alle Aufrufe von UnregisterInputMappingProvider:

Input.GetInputMappingClient().UnregisterInputMappingProvider(_inputMapProvider);

Ersetzen Sie sie durch ClearInputMappingProvider:

PlayInput.GetInputMappingClient().ClearInputMappingProvider();