Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Add unity integration
Browse files Browse the repository at this point in the history
  • Loading branch information
hqy2000 committed Dec 18, 2017
1 parent a37887a commit c5e9bfc
Show file tree
Hide file tree
Showing 26 changed files with 1,187 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Unity
Unity/
## Build generated
build/
DerivedData/
Expand Down
32 changes: 29 additions & 3 deletions General/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var time = Date().timeIntervalSince1970
var theme = ThemeManager()
var url:String? = nil

@objc var currentUnityController: UnityAppController?
var isUnityRunning = false
var application: UIApplication?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.application = application
unity_init(CommandLine.argc, CommandLine.unsafeArgv)
currentUnityController = UnityAppController()
currentUnityController!.application(application, didFinishLaunchingWithOptions: launchOptions)
// first call to startUnity will do some init stuff, so just call it here and directly stop it again
startUnity()
stopUnity()

IQKeyboardManager.sharedManager().enable = true
NetworkActivityIndicatorManager.shared.isEnabled = true
NetworkActivityIndicatorManager.shared.completionDelay = 0.5
/*
UMAnalyticsConfig.sharedInstance().appKey = "59c733a1c895764c1100001c"
UMAnalyticsConfig.sharedInstance().channelId = "App Store"
MAnalyticsConfig.sharedInstance().channelId = "App Store"
MobClick.start(withConfigure: UMAnalyticsConfig.sharedInstance())
let version = Bundle.main.infoDictionary!["CFBundleShortVersionString"]
MobClick.setAppVersion(version as! String)
MobClick.setEncryptEnabled(true)
//MobClick.setLogEnabled(true)
MobClick.setLogEnabled(true)
*/
if let options = launchOptions{
dump(options[UIApplicationLaunchOptionsKey.remoteNotification])
}
Expand Down Expand Up @@ -145,6 +157,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
return true
}

func startUnity() {
if !isUnityRunning {
isUnityRunning = true
currentUnityController!.applicationDidBecomeActive(application!)
}
}

func stopUnity() {
if isUnityRunning {
currentUnityController!.applicationWillResignActive(application!)
isUnityRunning = false
}
}
}


Expand Down
207 changes: 113 additions & 94 deletions General/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions General/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ class GameViewController:UIViewController,WKNavigationDelegate,WKUIDelegate,SKPr

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
MobClick.beginLogPageView("Gaming")
//MobClick.beginLogPageView("Gaming")
}

override func viewWillDisappear(_ animated: Bool) {
MobClick.endLogPageView("Gaming")
//MobClick.endLogPageView("Gaming")

super.viewWillDisappear(animated)
}
Expand Down
1 change: 1 addition & 0 deletions General/NFLSers-iOS-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "UMMobClick/MobClick.h"
8 changes: 5 additions & 3 deletions General/NewsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NewsViewController:UITableViewController,FrostedSidebarDelegate{
Alamofire.request("https://api.nfls.io/weather/ping")
checkStatus()
self.removeFile(filename: "", path: "temp")
let rightButton = UIBarButtonItem(title: nil, style: .plain, target: self, action: #selector(self.settings))
let rightButton = UIBarButtonItem(title: nil, style: .plain, target: self, action: #selector(self.showUnity))
rightButton.icon(from: .FontAwesome, code: "cog", ofSize: 20)
self.navigationItem.rightBarButtonItem = rightButton
let leftButton = UIBarButtonItem(title: nil, style: .plain, target: self, action: #selector(self.menu))
Expand All @@ -122,7 +122,9 @@ class NewsViewController:UITableViewController,FrostedSidebarDelegate{
view.addGestureRecognizer(swipeBack)

}

@objc func showUnity() {
self.performSegue(withIdentifier: "showUnity", sender: self)
}
@objc func refresh() {
loadNews()
debugPrint("refresh")
Expand Down Expand Up @@ -326,7 +328,7 @@ class NewsViewController:UITableViewController,FrostedSidebarDelegate{
}
self.showLogin()
} else {
MobClick.profileSignIn(withPUID: (String(describing: (json as! [String:Int])["id"]!)))
//MobClick.profileSignIn(withPUID: (String(describing: (json as! [String:Int])["id"]!)))
self.getAuthStatus()
self.getBadge()
self.requestMessage()
Expand Down
4 changes: 2 additions & 2 deletions General/ResourcesFiltringView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ class ResourcesFiltringViewController:UIViewController, UITableViewDataSource, U
listRequest()
}
override func viewWillAppear(_ animated: Bool) {
MobClick.beginLogPageView("Resources")
//MobClick.beginLogPageView("Resources")
UIApplication.shared.isIdleTimerDisabled = false
}
override func viewWillDisappear(_ animated: Bool) {
MobClick.endLogPageView("Resources")
//MobClick.endLogPageView("Resources")
}
@objc func setting() {
var mutipleSelectAction = UIAlertAction()
Expand Down
29 changes: 29 additions & 0 deletions General/UnityView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UnityView.swift
// NFLSers-iOS
//
// Created by hqy on 2017/12/18.
// Copyright © 2017年 胡清阳. All rights reserved.
//

import Foundation
import UIKit

class UnityViewController:UIViewController {
var unityView: UIView?
override func viewDidLoad() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.startUnity()

unityView = UnityGetGLView()!

self.view!.addSubview(unityView!)
unityView!.translatesAutoresizingMaskIntoConstraints = false

// look, non-full screen unity content!
let views = ["view": unityView]
let w = NSLayoutConstraint.constraints(withVisualFormat: "|-20-[view]-20-|", options: [], metrics: nil, views: views)
let h = NSLayoutConstraint.constraints(withVisualFormat: "V:|-75-[view]-50-|", options: [], metrics: nil, views: views)
view.addConstraints(w + h)
}
}
Loading

0 comments on commit c5e9bfc

Please sign in to comment.