Created
July 31, 2018 17:09
-
-
Save KIKS007/3d52f43b6ba76b60dfeba1b6edfa0e93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController | |
{ | |
@IBOutlet var rotateSwitch: UISwitch! | |
override func viewDidLoad() | |
{ | |
super.viewDidLoad() | |
/* if let appDelegate = UIApplication.shared.delegate as? AppDelegate | |
{ | |
appDelegate.startUnity() | |
NotificationCenter.default.addObserver(self, selector: #selector(handleUnityReady), name: NSNotification.Name("UnityReady"), object: nil) | |
}*/ | |
} | |
@objc func handleUnityReady() { | |
showUnitySubView() | |
} | |
func showUnitySubView() { | |
if let unityView = UnityGetGLView() { | |
// insert subview at index 0 ensures unity view is behind current UI view | |
view?.insertSubview(unityView, at: 0) | |
/* unityView.translatesAutoresizingMaskIntoConstraints = false | |
let views = ["view": unityView] | |
let w = NSLayoutConstraint.constraints(withVisualFormat: "|-0-[view]-0-|", options: [], metrics: nil, views: views) | |
let h = NSLayoutConstraint.constraints(withVisualFormat: "V:|-75-[view]-0-|", options: [], metrics: nil, views: views) | |
view.addConstraints(w + h)*/ | |
} | |
} | |
@IBAction func startUnity(_ sender: UIButton) | |
{ | |
if let unityView = UnityGetGLView() | |
{ | |
unityView.isHidden = false; | |
} | |
if let appDelegate = UIApplication.shared.delegate as? AppDelegate | |
{ | |
appDelegate.startUnity() | |
NotificationCenter.default.addObserver(self, selector: #selector(handleUnityReady), name: NSNotification.Name("UnityReady"), object: nil) | |
} | |
} | |
@IBAction func stopUnity(_ sender: UIButton) | |
{ | |
if let appDelegate = UIApplication.shared.delegate as? AppDelegate | |
{ | |
appDelegate.stopUnity() | |
if let unityView = UnityGetGLView() | |
{ | |
unityView.isHidden = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment