forked from fuziki/UnityCoreBluetooth
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameViewController.swift
More file actions
72 lines (55 loc) · 1.91 KB
/
GameViewController.swift
File metadata and controls
72 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// GameViewController.swift
// DaydreamExample iOS
//
// Created by fuziki on 2021/06/26.
//
import Foundation
import UIKit
import SceneKit
class GameViewController: UIViewController {
@IBOutlet weak var gameView: SCNView!
@IBOutlet weak var label: UILabel!
var gameController: GameController!
let bluetoothService = BluetoothService.shared
override func viewDidLoad() {
super.viewDidLoad()
self.gameController = GameController(sceneRenderer: gameView)
// Allow the user to manipulate the camera
self.gameView.allowsCameraControl = true
// Show statistics such as fps and timing information
self.gameView.showsStatistics = true
// Configure the view
self.gameView.backgroundColor = UIColor.black
// Add a tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
var gestureRecognizers = gameView.gestureRecognizers ?? []
gestureRecognizers.insert(tapGesture, at: 0)
self.gameView.gestureRecognizers = gestureRecognizers
bluetoothService.onUpdateValue = { [weak self] (value: String) in
DispatchQueue.main.async { [weak self] in
self?.label.text = value
}
}
bluetoothService.start()
}
@objc
func handleTap(_ gestureRecognizer: UIGestureRecognizer) {
// Highlight the tapped nodes
let p = gestureRecognizer.location(in: gameView)
gameController.highlightNodes(atPoint: p)
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
override var prefersStatusBarHidden: Bool {
return true
}
}