Migrieren Sie zum 1.0.0-beta Input SDK

In diesem Leitfaden wird beschrieben, wie Sie Ihr Unity-Spiel migrieren, um die neueste Eingabe-SDK. Das SDK 1.0.0-beta bietet erhebliche Verbesserungen gegenüber dem vorherige 0.0.4-Vorschau. Sie sollten so bald wie möglich aus den früheren Vorschauen migrieren wie möglich. Das SDK 0.0.4 funktioniert noch bis März 2023.

Referenzen aktualisieren

Klassen erhalten das Präfix Play, um Namenskonflikte mit Unity zu vermeiden. Wenn Sie eine Fehlermeldung wie diese erhalten:

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

müssen Sie dem Klassennamen das Präfix Play hinzufügen. Beispiel: InputMappingProvider wird zu PlayInputMappingProvider.

Jede InputAction aktualisieren

InputAction wird jetzt mit einem Aufruf von PlayInputAction.Create erstellt, im Gegensatz zu zum Erstellen einer neuen struct mit benannten Feldern.

Suchen Sie den 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 es 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 bei InputAction hat auch InputGroup jetzt einen PlayInputGroup.Create-Anruf, als das manuelle Ausfüllen eines struct.

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

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

Ersetzen Sie ihn durch einen Aufruf von PlayInputGroup.Create:

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

InputMap aktualisieren

InputMap verwendet ebenfalls PlayInputMap.Create, anstatt ein neues Struktur.

Suchen Sie alle new InputMap-Aufrufe:

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

Ersetzen Sie es 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 umbenannt in SetInputMappingProvider

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 umbenannt in ClearInputMappingProvider und Ihre zuvor registrierte InputMappingProvider als Parameter verwenden.

Suchen Sie alle UnregisterInputMappingProvider-Aufrufe:

Input.GetInputMappingClient().UnregisterInputMappingProvider(_inputMapProvider);

Ersetzen Sie sie durch ClearInputMappingProvider:

PlayInput.GetInputMappingClient().ClearInputMappingProvider();