daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NotificationCenter.default.addObserver(forName: .GCControllerDidConnect, object: nil, queue: .main) { (note) in
  2.         if let controller = note.object as? GCController {
  3.             if controller.playerIndex != .indexUnset {
  4.                 print("setting up controller (controller.playerIndex.rawValue)")
  5.                 self.setupController(controller)
  6.                 return
  7.             }
  8.  
  9.             var availableIndexes = [0, 1, 2, 3]
  10.             for connectedController in GCController.controllers() {
  11.                 if let occupiedIndex = availableIndexes.index(of: connectedController.playerIndex.rawValue) {
  12.                     availableIndexes.remove(at: occupiedIndex)
  13.                 }
  14.             }
  15.             if !availableIndexes.isEmpty {
  16.                 controller.playerIndex = GCControllerPlayerIndex(rawValue: availableIndexes.first!)!
  17.                 print("setting up controller (controller.playerIndex.rawValue)")
  18.                 self.setupController(controller)
  19.             }
  20.  
  21.         }
  22.     }
  23.    
  24. setting up controller 0
  25. setting up controller 1
RAW Paste Data
Top