Oyun Geliştirme
Gamepad desteği
Gamepad ile çalışacak bağlamaları öğrenirsin.
Gamepad bağlamaları
Yeni Input System'de her cihaz aynı yol biçimini kullanır: <Gamepad>/leftStick, <Gamepad>/buttonSouth. Bir eyleme hem klavye hem gamepad bağlaması ekleyebilirsin; eylem hangi cihaz kullanılırsa kullanılsın aynı şekilde tetiklenir. Düğme adları Xbox düzenine göredir: buttonSouth A/Cross, buttonWest X/Square düğmesidir.
moveAction.AddBinding("<Gamepad>/leftStick");
moveAction.AddBinding("<Keyboard>/arrowKeys");
Debug.Log("Iki cihaz baglandi");
Kontrol düzeni
Bir Input Action asset'inde her cihaz seti için bir kontrol düzeni tanımlanır; örneğin Keyboard&Mouse ve Gamepad. Her bağlama bir ya da birden çok gruba atanır. PlayerInput bileşeni SwitchCurrentControlScheme ile etkin düzeni değiştirebilir.
playerInput.SwitchCurrentControlScheme("Gamepad", Gamepad.current);
Debug.Log("Duzen degisti");
Böylece oyun hangi tuş göstergelerini basacağını bilir.
Uygulama Move eylemini iki cihaza bağla
GamepadDestek adında bir MonoBehaviour yaz. Start içinde adı Move, türü InputActionType.Value olan bir InputAction oluştur. AddCompositeBinding("2DVector") ile başlayan zincirde With çağrılarıyla tuşları bağla: Up için <Keyboard>/w, Down için <Keyboard>/s, Left için <Keyboard>/a, Right için <Keyboard>/d. Sonra move.AddBinding("<Gamepad>/leftStick") ile sol çubuğu ekle, move.Enable() çağır ve Debug.Log("Move hazir") yazdır.
Örnek çözümü göster
using UnityEngine;
using UnityEngine.InputSystem;
public class GamepadDestek : MonoBehaviour
{
void Start()
{
InputAction move = new InputAction(name: "Move", type: InputActionType.Value);
move.AddCompositeBinding("2DVector")
.With("Up", "<Keyboard>/w")
.With("Down", "<Keyboard>/s")
.With("Left", "<Keyboard>/a")
.With("Right", "<Keyboard>/d");
move.AddBinding("<Gamepad>/leftStick");
move.Enable();
Debug.Log("Move hazir");
}
}
Kendini test et
-
Gamepad'de sol analog çubuğun yolu nedir?
- <Gamepad>/buttonEast
- <Gamepad>/dpad
- <Gamepad>/leftTrigger
- <Gamepad>/leftStick
Cevabı göster
<Gamepad>/leftStick — Sol analog çubuk leftStick'tir; leftTrigger sol tetik, buttonEast B/Circle düğmesi, dpad ise yön tuşlarıdır.
-
A düğmesini bağla
jumpAction.AddBinding("<Gamepad>/button____");
Cevabı göster
jumpAction.AddBinding("<Gamepad>/buttonSouth");
-
Gamepad terimleri
- buttonWest
- X/Square düğmesi
- leftTrigger
- Sol tetik düğmesi
- Control Scheme
- Cihaz setine göre tuş düzeni
- SwitchCurrentControlScheme
- Etkin düzeni değiştirme
Sıradaki ders: Özet - İleri giriş