نقل البيانات إلى الإصدار التجريبي من حزمة تطوير البرامج (SDK) للإدخال 1.0.0

يوضّح هذا الدليل كيفية نقل بيانات لعبة Unity لاستخدام أحدث إصدار من Input SDK. يتضمّن الإصدار 1.0.0-beta من حزمة SDK تحسينات كبيرة مقارنةً بالنسخة الحصرية السابقة 0.0.4. ننصحك بنقل البيانات من النسخ الحصرية السابقة في أقرب وقت ممكن. سيظلّ الإصدار 0.0.4 من حزمة SDK يعمل حتى مارس 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

يتم الآن إنشاء 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)
);

إعادة تسمية طرق PlayInputMappingClient

بالنسبة إلى PlayInputMappingClient، تم تغيير اسم RegisterInputMappingProvider إلى SetInputMappingProvider.

ابحث عن أي استدعاءات لـ 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();