يوضِّح هذا الدليل كيفية نقل ألعابك في Unity لاستخدام أحدث حزمة تطوير برامج (SDK) للإدخال. تتضمّن حزمة تطوير البرامج (SDK) الإصدار 1.0.0-الإصدار التجريبي تحسينات مهمة مقارنةً بالإصدار السابق من الإصدار 0.0.4. يجب نقل البيانات من المعاينات السابقة في أقرب وقت ممكن. سيستمر عمل حزمة تطوير البرامج (SDK) 0.0.4 حتى آذار (مارس) 2023.
تعديل المراجع
تلقت الصفوف البادئة Play
لتجنُّب تسمية التضاربات باستخدام Unity.
كلما ظهرت رسالة خطأ تشبه:
الخطأ CS0246: تعذر العثور على النوع أو اسم مساحة الاسم "InputMappingProvider" (هل ينقصك استخدام توجيه أو مرجع تجميع؟)
يجب إضافة البادئة 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
)
);
تعديل كل مجموعة إدخال
مثل 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
السمة 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();