คู่มือนี้อธิบายวิธีย้ายข้อมูลเกมเพื่อใช้ Input SDK เวอร์ชันล่าสุด SDK 1.0.0-beta มีการปรับปรุงที่สำคัญกว่าเวอร์ชันตัวอย่าง 0.0.4 ก่อนหน้า คุณควรย้ายข้อมูลจากเวอร์ชันตัวอย่างก่อนหน้าโดยเร็วที่สุด SDK 0.0.4 จะยังคงทำงานต่อไปจนถึงเดือนมีนาคม 2023
อัปเดตทรัพยากร Dependency
ลบคลัง 0.0.4 ออกจากไดเรกทอรี libs เนื่องจากตอนนี้คลังพร้อมใช้งานใน Maven แล้ว
จากนั้นค้นหาบรรทัดนี้ในไฟล์ build.grade
ระดับโมดูล
implementation files('libs/inputmapping-0.0.4.aar')
แทนที่ด้วยโค้ดต่อไปนี้
implementation 'com.google.android.libraries.play.games:inputmapping:1.0.0-beta'
ติดตั้งใช้งานอินเทอร์เฟซ InputMappingProvider ใหม่
คลาสแอบสแทรกต์เดิม InputMappingProvider เปลี่ยนเป็นอินเทอร์เฟซใน
เวอร์ชัน 1.0.0-beta เมธอด onProvideInputMap() ยังคงเป็นส่วนหนึ่งของอินเทอร์เฟซ
Kotlin
นำ () ออกจากคำจำกัดความของคลาสเนื่องจากไม่มีตัวสร้างที่จะเรียกใช้ใน
InputMappingProvider
ค้นหาการติดตั้งใช้งาน InputMappingProvider ดังนี้
class MyInputMapProvider : InputMappingProvider() {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
และอัปเดตเป็น
class MyInputMapProvider : InputMappingProvider {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
Java
แทนที่ extends ด้วย implements เพื่อระบุว่าคุณกำลังใช้
อินเทอร์เฟซแทนการขยายคลาส
ค้นหาตำแหน่งที่คุณขยาย InputMappingProvider ดังนี้
public class MyInputMapProvider extends InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
และเปลี่ยนเพื่อใช้ InputMappingProvider ดังนี้
public class MyInputMapProvider implements InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
ใช้ InputClient ใหม่
registerInputMappingProvider และ unregisterInputMappingProvider ถูกแทนที่ด้วย setInputMappingProvider และ clearInputMappingProvider
นอกจากนี้ clearInputMappingProvider ยังไม่รับอาร์กิวเมนต์อีกต่อไป คุณจึงไม่จำเป็นต้องเก็บข้อมูลอ้างอิงถึงผู้ให้บริการเพื่อยกเลิกการลงทะเบียนในภายหลัง
Kotlin
หากต้องการลงทะเบียนผู้ให้บริการแผนที่อินพุต ให้ค้นหาการเรียกไปยังregisterInputMappingProvider
private val myInputMapProvider by lazy {
MyInputMapProvider()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.registerInputMappingProvider(myInputMapProvider)
}
แล้วแทนที่ด้วย setInputMappingProvider
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.setInputMappingProvider(MyInputMapProvider())
}
หากต้องการล้างแผนที่อินพุต ให้ค้นหาการเรียกใช้ unregisterInputMappingProvider ดังนี้
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider)
super.onDestroy()
}
แล้วแทนที่ด้วย clearInputMappingprovider
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.clearInputMappingProvider()
super.onDestroy()
}
Java
หากต้องการลงทะเบียนผู้ให้บริการแผนที่อินพุต ให้ค้นหาการเรียกไปยัง
registerInputMappingProvider
private final MyInputMapProvider myInputMapProvider = new MyInputMapProvider();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.registerInputMappingProvider(myInputMapProvider);
}
แล้วแทนที่ด้วย setInputMappingProvider
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.setInputMappingProvider(new MyInputMapProvider());
}
หากต้องการล้างผู้ให้บริการการแมปอินพุต ให้ค้นหาการเรียกไปยัง
unregisterInputMappingProvider
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider);
super.onDestroy();
}
แล้วแทนที่ด้วย clearInputMappingProvider
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.clearInputMappingProvider();
super.onDestroy();
}