ย้ายข้อมูลไปยัง SDK อินพุต 1.0.0 รุ่นเบต้า

คู่มือนี้อธิบายวิธีย้ายข้อมูลเกม Unity เพื่อใช้ Input SDK เวอร์ชันล่าสุด SDK 1.0.0-beta มีการปรับปรุงที่สำคัญเมื่อเทียบกับเวอร์ชันตัวอย่าง 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 แต่ละรายการ

ตอนนี้ระบบจะสร้าง 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 ด้วยเช่นกันแทนการสร้าง struct ใหม่

ค้นหาการเรียก 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();