目录
目录README.md

swift-version swift-package-manager platform ci-status license

GCOverseer

Combine wrapper around Apple’s Game Controller Framework.

Tested Platforms

  • iOS 14+
  • macOS 11+ (BigSur+)
  • Mac Catalyst 14+
  • tvOS 14+
  • Xcode 12+
  • Swift 5.3+

Usage Examples

Handle Connected / Disconnected Events

import SpriteKit
import Combine
import GCOverseer

class GameScene: SKScene {

    let gcOverseer = GCOverseer()

    var cancellables = Set<AnyCancellable>()

    override init(size: CGSize) {
        super.init(size: size)

        // 🎮
        gcOverseer.$isGameControllerConnected
            .sink { isConnected in
                // Do something
            }
            .store(in: &cancellables)
    }
}

Available Properties

Property Description
@Published var isGameControllerConnected: Bool Subscribe to this variable to keep track of connect / disconnect events of game controllers.

Available APIs

API Description
controllers() Returns all controllers that are connected to the device. E.g. Dualshock, Xbox, Siri Remote controllers, etc.
extendedGamepadControllers() Returns all controllers supporting the extendedGamepad profile that are connected to the device. E.g. Dualshock, Xbox controllers, etc.
dualshockControllers() Returns all DualShock controllers that are connected to the device.
xboxControllers() Returns all Xbox controllers that are connected to the device.
microGamepadControllers() Returns all controllers supporting the microGamepad profile that are connected to the device. E.g. Apple’s Siri Remote.
motionControllers() Returns all controllers supporting the motion profile that are connected to the device.
controllerFor(playerIndex:) Returns the controller for the player 1, player 2, etc.
enableLogging() / disableLogging() Enables / disables logging output.

Integration

Xcode

Use Xcode’s built-in support for SPM.

or…

Package.swift

In your Package.swift, add GCOverseer as a dependency:

dependencies: [
  .package(url: "https://github.com/backslash-f/gcoverseer", from: "0.1.0")
],

Associate the dependency with your target:

targets: [
  .target(name: "App", dependencies: ["GCOverseer"])
]

Run: swift build

关于
66.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号