מעבר ל-SDK לקליטת נתונים בגרסת 1.0.0 בטא

במדריך הזה מוסבר איך להעביר את המשחק ב-Unity לשימוש בגרסה העדכנית של Input SDK. גרסת 1.0.0-beta של ה-SDK כוללת שיפורים משמעותיים לעומת גרסת הטרום-השקה הקודמת, 0.0.4. מומלץ לבצע מיגרציה מהגרסאות הקודמות של התצוגה המקדימה בהקדם האפשרי. ערכת ה-SDK בגרסה 0.0.4 תמשיך לפעול עד מרץ 2023.

עדכון ההפניות

למחלקות נוספה הקידומת Play כדי למנוע התנגשויות בשמות עם Unity. אם מופיעה הודעת שגיאה דומה לזו:

error CS0246: The type or namespace name 'InputMappingProvider' could not be found (are you missing a using directive or an assembly reference?)

צריך להוסיף את הקידומת Play לשם הכיתה. לדוגמה, InputMappingProvider הופך ל-PlayInputMappingProvider.

עדכון כל פעולת קלט

הפונקציה InputAction בנויה עכשיו עם קריאה ל-PlayInputAction.Create, במקום ליצור struct חדש עם שדות בעלי שמות.

מאתרים קוד שקורא ל-new InputAction:

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

ומחליפים אותו בקריאה ל-PlayInputAction.Create:

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

עדכון כל InputGroup

בדומה ל-InputAction, מעכשיו InputGroup יתקשר אליך PlayInputGroup.Create במקום שתצטרך למלא ידנית את הטופס struct.

כלומר, צריך לאתר את כל השיחות אל new InputGroup:

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

ולהחליף אותה בשיחה אל PlayInputGroup.Create:

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

עדכון של InputMap

InputMap משתמש גם ב-PlayInputMap.Create במקום ליצור מבנה חדש.

מאתרים שיחות למספר new InputMap:

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

ומחליפים אותו בקריאה ל-PlayInputMap.Create:

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

שינוי השם של ה-methods של PlayInputMappingClient

השם של RegisterInputMappingProvider השתנה לSetInputMappingProvider ב-PlayInputMappingClient.

לכן, צריך לאתר את כל השיחות למספר RegisterInputMappingProvider:

Input.GetInputMappingClient().RegisterInputMappingProvider(_inputMappingProvider);

ומחליפים אותם בשיחה אל SetInputMappingProvider:

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

בנוסף, השם של UnregisterInputMappingProvider שונה ל-ClearInputMappingProvider, ולא צריך יותר להשתמש ב-InputMappingProvider שרשמת בעבר כפרמטר.

מאתרים שיחות למספר UnregisterInputMappingProvider:

Input.GetInputMappingClient().UnregisterInputMappingProvider(_inputMapProvider);

ולהחליף אותם ב-ClearInputMappingProvider:

PlayInput.GetInputMappingClient().ClearInputMappingProvider();