main
gem 2 months ago
parent d7699c93cd
commit 40409fd882
  1. 49
      example/ios/Runner.xcodeproj/project.pbxproj
  2. 21
      example/ios/Runner/AppDelegate.swift
  3. 1
      example/lib/screens/simple_screen.dart
  4. 55
      example/pubspec.lock
  5. 2
      example/pubspec.yaml
  6. 113
      ios/Classes/CocosPlayerUtils.swift
  7. 3
      ios/Classes/FLTCocosView.swift
  8. 36
      ios/Classes/FLTCocosWidgetController.swift
  9. 7
      ios/Classes/FlutterCocosViewPlugin.swift
  10. 10
      ios/Classes/FlutterCocosWidgetPlugin.m
  11. 10
      ios/flutter_cocos_view.podspec
  12. 4
      lib/src/io/device_method.dart
  13. 14
      pubspec.yaml

@ -106,7 +106,6 @@
181E7CAB9BFA90CDBBC625FE /* Pods-RunnerTests.release.xcconfig */, 181E7CAB9BFA90CDBBC625FE /* Pods-RunnerTests.release.xcconfig */,
26E556676FA54FF74E61CC9C /* Pods-RunnerTests.profile.xcconfig */, 26E556676FA54FF74E61CC9C /* Pods-RunnerTests.profile.xcconfig */,
); );
name = Pods;
path = Pods; path = Pods;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
@ -198,7 +197,7 @@
97C146EC1CF9000F007C117D /* Resources */, 97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */, 9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */,
C22789791D91DA87B0800321 /* [CP] Embed Pods Frameworks */, 129AC22480F1A498B12D0823 /* [CP] Copy Pods Resources */,
); );
buildRules = ( buildRules = (
); );
@ -270,6 +269,23 @@
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
129AC22480F1A498B12D0823 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1; alwaysOutOfDate = 1;
@ -345,23 +361,6 @@
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
}; };
C22789791D91DA87B0800321 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
@ -457,6 +456,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0; IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LIBTOOLFLAGS = "$(inherited)";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos; SUPPORTED_PLATFORMS = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
@ -471,12 +471,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = U4K6R29373;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
OTHER_LIBTOOLFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample; PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@ -587,6 +589,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0; IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_LIBTOOLFLAGS = "$(inherited)";
SDKROOT = iphoneos; SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
@ -637,6 +640,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0; IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LIBTOOLFLAGS = "$(inherited)";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos; SUPPORTED_PLATFORMS = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule; SWIFT_COMPILATION_MODE = wholemodule;
@ -653,12 +657,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = U4K6R29373;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
OTHER_LIBTOOLFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample; PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@ -675,12 +682,16 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = U4K6R29373;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
ONLY_ACTIVE_ARCH = YES;
OTHER_LIBTOOLFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample; PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCocosViewExample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

@ -7,7 +7,28 @@ import UIKit
_ application: UIApplication, _ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool { ) -> Bool {
///InitCocosIntegrationWithOptions(argc: CommandLine.argc, argv: CommandLine.unsafeArgv, launchOptions)
let flutterEngine = FlutterEngine(name: "io.flutter", project: nil)
flutterEngine.run()
let controller = FlutterViewControllerWithTransition(engine: flutterEngine, nibName: nil, bundle: nil)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
GeneratedPluginRegistrant.register(with: self) GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions) return super.application(application, didFinishLaunchingWithOptions: launchOptions)
} }
}
class FlutterViewControllerWithTransition: FlutterViewController {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
NotificationCenter.default.post(name: NSNotification.Name("ViewWillTransition"), object: nil, userInfo: ["size": size, "coordinator": coordinator])
}
} }

@ -106,6 +106,7 @@ class _SimpleScreenState extends State<SimpleScreen> {
// Callback that connects the created controller to the cocos controller // Callback that connects the created controller to the cocos controller
void _onCocosCreated(controller) { void _onCocosCreated(controller) {
print('Received _onCocosCreated: null');
controller.resume(); controller.resume();
_cocosWidgetController = controller; _cocosWidgetController = controller;
} }

@ -57,14 +57,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -77,11 +69,6 @@ packages:
relative: true relative: true
source: path source: path
version: "0.0.1" version: "0.0.1"
flutter_driver:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -95,16 +82,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
leak_tracker: leak_tracker:
dependency: transitive dependency: transitive
description: description:
@ -169,14 +146,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.0" version: "1.9.0"
platform:
dependency: transitive
description:
name: platform
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
plugin_platform_interface: plugin_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -193,14 +162,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.9.3+7" version: "0.9.3+7"
process:
dependency: transitive
description:
name: process
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -246,14 +207,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
sync_http:
dependency: transitive
description:
name: sync_http
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -286,14 +239,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.2.5" version: "14.2.5"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
sdks: sdks:
dart: ">=3.4.4 <4.0.0" dart: ">=3.4.4 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54" flutter: ">=3.18.0-18.0.pre.54"

@ -30,8 +30,6 @@ dependencies:
cupertino_icons: ^1.0.8 cupertino_icons: ^1.0.8
pointer_interceptor: ^0.9.3+2 pointer_interceptor: ^0.9.3+2
dev_dependencies: dev_dependencies:
integration_test:
sdk: flutter
flutter_test: flutter_test:
sdk: flutter sdk: flutter

@ -6,7 +6,6 @@
// //
import Foundation import Foundation
import cocos_view_pod
private var cocos_warmed_up = false private var cocos_warmed_up = false
@ -37,7 +36,7 @@ public func InitCocosIntegrationWithOptions(
/***********************************PLUGIN_ENTRY END**************************************/ /***********************************PLUGIN_ENTRY END**************************************/
// Load cocos framework for fisrt run // Load cocos framework for fisrt run
func CocosFrameworkLoad() -> CocosFramework? { func CocosFrameworkLoad() -> dcocos_bridge? {
return dcocos_bridge.instance() return dcocos_bridge.instance()
@ -58,7 +57,7 @@ func GetCocosPlayerUtils() -> CocosPlayerUtils {
/*********************************** GLOBAL FUNCS & VARS END****************************************/ /*********************************** GLOBAL FUNCS & VARS END****************************************/
var controller: CocosAppController? //var controller: CocosAppController?
var sharedApplication: UIApplication? var sharedApplication: UIApplication?
@objc protocol CocosEventListener: AnyObject { @objc protocol CocosEventListener: AnyObject {
@ -67,31 +66,74 @@ var sharedApplication: UIApplication?
} }
@objc public class CocosPlayerUtils: UIResponder, UIApplicationDelegate, CocosFrameworkListener { @objc public class CocosPlayerUtils: UIResponder, UIApplicationDelegate {
var ufw: CocosFramework! var ufw: dcocos_bridge!
private var _isCocosPaused = false private var _isCocosPaused = false
private var _isCocosReady = false private var _isCocosReady = false
private var _isCocosLoaded = false private var _isCocosLoaded = false
override init() {
super.init()
//
NotificationCenter.default.addObserver(self, selector: #selector(handleViewWillTransition), name: NSNotification.Name("ViewWillTransition"), object: nil)
}
deinit {
//
NotificationCenter.default.removeObserver(self)
}
@objc func handleViewWillTransition(notification: Notification) {
guard let size = notification.userInfo?["size"] as? CGSize,
let coordinator = notification.userInfo?["coordinator"] as? UIViewControllerTransitionCoordinator else {
return
}
//
print("CocosPlayerUtils will transition to size: \(size)")
//
let selector = NSSelectorFromString("viewWillTransitionToSize:withTransitionCoordinator:")
if self.ufw.responds(to: selector) {
self.ufw.perform(selector, with: size, with: coordinator)
}
}
func initCocos() { func initCocos() {
if (self.cocosIsInitiallized()) { if (self.cocosIsInitiallized()) {
self.ufw?.showCocosWindow() //todo
//self.ufw?.showCocosWindow()
return return
} }
//
//UIDevice.current.beginGeneratingDeviceOrientationNotifications()
self.ufw = CocosFrameworkLoad() self.ufw = CocosFrameworkLoad()
// PodBundle
let bundle = Bundle(for: dcocos_bridge.self)
// `YourPodResources.bundle`
if let bundleURL = bundle.url(forResource: "cocos_main_bundle", withExtension: "bundle") {
let bundlePath = bundleURL.path
print("Bundle absolute path: \(bundlePath)")
self.ufw.configureCocos2dSearchPaths(bundlePath)
} else {
print("Could not find the bundle.")
}
//self.ufw?.setDataBundleId("com.cocos3d.framework") //self.ufw?.setDataBundleId("com.cocos3d.framework")
self.ufw.initPlatform()
let application = UIApplication.shared
self.ufw.application(application, didFinishLaunchingWithOptions: appLaunchOpts )
registerCocosListener() registerCocosListener()
// self.ufw?.runEmbedded(withArgc: gArgc, argv: gArgv, appLaunchOpts: appLaunchOpts) // self.ufw?.runEmbedded(withArgc: gArgc, argv: gArgv, appLaunchOpts: appLaunchOpts)
if self.ufw?.appController() != nil { // if self.ufw?.appController() != nil {
controller = self.ufw?.appController() // controller = self.ufw?.appController()
controller?.cocosMessageHandler = self.cocosMessageHandlers // controller?.cocosMessageHandler = self.cocosMessageHandlers
controller?.cocosSceneLoadedHandler = self.cocosSceneLoadedHandlers // controller?.cocosSceneLoadedHandler = self.cocosSceneLoadedHandlers
self.ufw?.appController()?.window?.windowLevel = UIWindow.Level(UIWindow.Level.normal.rawValue - 1) // self.ufw?.appController()?.window?.windowLevel = UIWindow.Level(UIWindow.Level.normal.rawValue - 1)
} // }
_isCocosLoaded = true _isCocosLoaded = true
} }
@ -107,13 +149,18 @@ var sharedApplication: UIApplication?
// Create new cocos player // Create new cocos player
func createPlayer(completed: @escaping (_ view: UIView?) -> Void) { func createPlayer(completed: @escaping (_ view: UIView?) -> Void) {
if self.cocosIsInitiallized() && self._isCocosReady { if self.cocosIsInitiallized() && self._isCocosReady {
completed(controller?.rootView) //todo
//completed(controller?.rootView)
completed(nil)
return return
} }
NotificationCenter.default.addObserver(forName: NSNotification.Name("CocosReady"), object: nil, queue: OperationQueue.main, using: { note in NotificationCenter.default.addObserver(forName: NSNotification.Name("CocosReady"), object: nil, queue: OperationQueue.main, using: { note in
self._isCocosReady = true self._isCocosReady = true
completed(controller?.rootView) //todo
//completed(controller?.rootView)
completed(nil)
}) })
DispatchQueue.main.async { DispatchQueue.main.async {
@ -134,7 +181,9 @@ var sharedApplication: UIApplication?
self.listenAppState() self.listenAppState()
completed(controller?.rootView) //todo
//completed(controller?.rootView)
completed(nil)
} }
} }
@ -163,22 +212,22 @@ var sharedApplication: UIApplication?
if !self._isCocosReady { if !self._isCocosReady {
return return
} }
//todo
let cocosAppController = self.ufw?.appController() as? CocosAppController //let cocosAppController = self.ufw?.appController() as? CocosAppController
// let cocosAppController = nil
let application = UIApplication.shared let application = UIApplication.shared
if notification?.name == UIApplication.willResignActiveNotification { if notification?.name == UIApplication.willResignActiveNotification {
cocosAppController?.applicationWillResignActive(application) self.ufw?.applicationWillResignActive(application)
} else if notification?.name == UIApplication.didEnterBackgroundNotification { } else if notification?.name == UIApplication.didEnterBackgroundNotification {
cocosAppController?.applicationDidEnterBackground(application) // self.ufw?.applicationDidEnterBackground(application)
} else if notification?.name == UIApplication.willEnterForegroundNotification { } else if notification?.name == UIApplication.willEnterForegroundNotification {
cocosAppController?.applicationWillEnterForeground(application) // self.ufw?.applicationWillEnterForeground(application)
} else if notification?.name == UIApplication.didBecomeActiveNotification { } else if notification?.name == UIApplication.didBecomeActiveNotification {
cocosAppController?.applicationDidBecomeActive(application) self.ufw?.applicationDidBecomeActive(application)
} else if notification?.name == UIApplication.willTerminateNotification { } else if notification?.name == UIApplication.willTerminateNotification {
cocosAppController?.applicationWillTerminate(application) self.ufw?.applicationWillTerminate(application)
} else if notification?.name == UIApplication.didReceiveMemoryWarningNotification { } else if notification?.name == UIApplication.didReceiveMemoryWarningNotification {
cocosAppController?.applicationDidReceiveMemoryWarning(application) // self.ufw?.applicationDidReceiveMemoryWarning(application)
} }
} }
@ -186,6 +235,7 @@ var sharedApplication: UIApplication?
// Listener for app lifecycle eventa // Listener for app lifecycle eventa
func listenAppState() { func listenAppState() {
for name in [ for name in [
UIApplication.didBecomeActiveNotification, UIApplication.didBecomeActiveNotification,
UIApplication.didEnterBackgroundNotification, UIApplication.didEnterBackgroundNotification,
UIApplication.willTerminateNotification, UIApplication.willTerminateNotification,
@ -202,19 +252,22 @@ var sharedApplication: UIApplication?
} }
// Pause cocos player // Pause cocos player
func pause() { func pause() {
self.ufw?.pause(true) //todo
// self.ufw?.pause(true)
self._isCocosPaused = true self._isCocosPaused = true
} }
// Resume cocos player // Resume cocos player
func resume() { func resume() {
self.ufw?.pause(false) //todo
//self.ufw?.pause(false)
self._isCocosPaused = false self._isCocosPaused = false
} }
// Unoad cocos player // Unoad cocos player
func unload() { func unload() {
self.ufw?.unloadApplication() //todo
//self.ufw?.unloadApplication()
} }
func isCocosLoaded() -> Bool { func isCocosLoaded() -> Bool {
@ -227,14 +280,16 @@ var sharedApplication: UIApplication?
// Quit cocos player application // Quit cocos player application
func quit() { func quit() {
self.ufw?.quitApplication(0) //todo
//self.ufw?.quitApplication(0)
self._isCocosLoaded = false self._isCocosLoaded = false
} }
// Post message to cocos // Post message to cocos
func postMessageToCocos(gameObject: String?, cocosMethodName: String?, cocosMessage: String?) { func postMessageToCocos(gameObject: String?, cocosMethodName: String?, cocosMessage: String?) {
if self.cocosIsInitiallized() { if self.cocosIsInitiallized() {
self.ufw?.sendMessageToGO(withName: gameObject, functionName: cocosMethodName, message: cocosMessage) //todo
//self.ufw?.sendMessageToGO(withName: gameObject, functionName: cocosMethodName, message: cocosMessage)
} }
} }

@ -13,7 +13,8 @@ class FLTCocosView: UIView {
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if (!self.bounds.isEmpty) { if (!self.bounds.isEmpty) {
GetCocosPlayerUtils().ufw?.appController()?.rootView.frame = self.bounds //todo
GetCocosPlayerUtils().ufw?.getCocosView()?.frame = self.bounds
} }
} }
} }

@ -23,6 +23,8 @@ public class FLTCocosWidgetController: NSObject, FLTCocosOptionsSink, FlutterPla
arguments args: Any?, arguments args: Any?,
registrar: NSObjectProtocol & FlutterPluginRegistrar registrar: NSObjectProtocol & FlutterPluginRegistrar
) { ) {
//CGRect(x: 0, y: 0, width: 700, height: 700)
self._rootView = FLTCocosView(frame: frame) self._rootView = FLTCocosView(frame: frame)
super.init() super.init()
@ -38,6 +40,8 @@ public class FLTCocosWidgetController: NSObject, FLTCocosOptionsSink, FlutterPla
} }
func methodHandler(_ call: FlutterMethodCall, result: FlutterResult) { func methodHandler(_ call: FlutterMethodCall, result: FlutterResult) {
NSLog("call : \(call.method)")
if call.method == "cocos#dispose" { if call.method == "cocos#dispose" {
self.dispose() self.dispose()
result(nil) result(nil)
@ -93,27 +97,29 @@ public class FLTCocosWidgetController: NSObject, FLTCocosOptionsSink, FlutterPla
func attachView() { func attachView() {
startCocosIfNeeded() startCocosIfNeeded()
//GetCocosPlayerUtils().ufw?.setCocosView(_rootView)
let cocosView = GetCocosPlayerUtils().ufw?.appController()?.rootView // self.channel?.invokeMethod("events#onViewReattached", arguments: "")
if let superview = cocosView?.superview { let cocosView = GetCocosPlayerUtils().ufw?.getCocosView()
cocosView?.removeFromSuperview() if let superview = cocosView?.superview {
superview.layoutIfNeeded() cocosView?.removeFromSuperview()
} superview.layoutIfNeeded()
}
if let cocosView = cocosView {
_rootView.addSubview(cocosView) if let cocosView = cocosView {
_rootView.layoutIfNeeded() _rootView.addSubview(cocosView)
self.channel?.invokeMethod("events#onViewReattached", arguments: "") _rootView.layoutIfNeeded()
} self.channel?.invokeMethod("events#onViewReattached", arguments: "")
}
GetCocosPlayerUtils().resume() GetCocosPlayerUtils().resume()
} }
func reattachView() { func reattachView() {
let cocosView = GetCocosPlayerUtils().ufw?.appController()?.rootView //todo
let cocosView = GetCocosPlayerUtils().ufw?.getCocosView()
let superview = cocosView?.superview let superview = cocosView?.superview
if superview != _rootView { if superview != _rootView {
attachView() attachView()
} }
GetCocosPlayerUtils().resume() GetCocosPlayerUtils().resume()
} }
@ -123,7 +129,7 @@ public class FLTCocosWidgetController: NSObject, FLTCocosOptionsSink, FlutterPla
return return
} }
let cocosView = GetCocosPlayerUtils().ufw?.appController()?.rootView let cocosView = GetCocosPlayerUtils().ufw?.getCocosView()
if _rootView == cocosView?.superview { if _rootView == cocosView?.superview {
if globalControllers.isEmpty { if globalControllers.isEmpty {
cocosView?.removeFromSuperview() cocosView?.removeFromSuperview()

@ -1,11 +1,10 @@
import Flutter import Flutter
import UIKit import UIKit
public class FlutterCocosViewPlugin: NSObject, FlutterPlugin { public class SwiftFlutterCocosViewPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) { public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_cocos_view", binaryMessenger: registrar.messenger()) print("FlutterCocosViewPlugin registered~~~~~~~~~~~~~~") //
let instance = FlutterCocosViewPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
let fuwFactory = FLTCocosWidgetFactory(registrar: registrar) let fuwFactory = FLTCocosWidgetFactory(registrar: registrar)
registrar.register(fuwFactory, withId: "plugin.gem.com/cocos_view", gestureRecognizersBlockingPolicy: FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded) registrar.register(fuwFactory, withId: "plugin.gem.com/cocos_view", gestureRecognizersBlockingPolicy: FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded)

@ -1,12 +1,12 @@
#import FlutterCocosWidgetPlugin.h #import "FlutterCocosWidgetPlugin.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#if __has_include(<flutter_cocos_widget/flutter_cocos_widget-Swift.h>) #if __has_include(<flutter_cocos_view/flutter_cocos_-Swift.h>)
#import <flutter_cocos_widget/flutter_cocos_widget-Swift.h> #import <flutter_cocos_view/flutter_cocos_view-Swift.h>
#else #else
// Support project import fallback if the generated compatibility header // Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library. // is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 // https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "flutter_cocos_widget-Swift.h" #import <flutter_cocos_view/flutter_cocos_view-Swift.h>
#endif #endif
@implementation FlutterCocosWidgetPlugin { @implementation FlutterCocosWidgetPlugin {
@ -16,7 +16,7 @@
} }
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftFlutterCocosWidgetPlugin registerWithRegistrar:registrar]; [SwiftFlutterCocosViewPlugin registerWithRegistrar:registrar];
} }
@end @end

@ -15,11 +15,17 @@ A new Flutter plugin project.
s.source = { :path => '.' } s.source = { :path => '.' }
s.source_files = 'Classes/**/*' s.source_files = 'Classes/**/*'
s.dependency 'Flutter' s.dependency 'Flutter'
s.dependency 'cocos_view_pod','0.1.23'
s.platform = :ios, '14.5' s.platform = :ios, '14.5'
s.dependency 'cocos_view_pod','0.1.7' #s.public_header_files = 'Classes/**/*.h'
#s.vendored_libraries = 'Libs/**/*.a'
#s.libraries = 'dcocos'
#s.private_header_files = 'Classes/flutter_cocos_view-Bridging-Header.h'
s.static_framework = true
# Flutter.framework does not contain a i386 slice. # Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES'}
s.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
s.swift_version = '5.0' s.swift_version = '5.0'
# If your plugin requires a privacy manifest, for example if it uses any # If your plugin requires a privacy manifest, for example if it uses any

@ -40,7 +40,7 @@ class MethodChannelCocosWidget extends CocosWidgetPlatform {
MethodChannel ensureChannelInitialized(int cocosId) { MethodChannel ensureChannelInitialized(int cocosId) {
MethodChannel? channel = _channels[cocosId]; MethodChannel? channel = _channels[cocosId];
if (channel == null) { if (channel == null) {
channel = MethodChannel('plugin.xraph.com/cocos_view_$cocosId'); channel = MethodChannel('plugin.gem.com/cocos_view_$cocosId');
channel.setMethodCallHandler( channel.setMethodCallHandler(
(MethodCall call) => _handleMethodCall(call, cocosId)); (MethodCall call) => _handleMethodCall(call, cocosId));
@ -158,7 +158,7 @@ class MethodChannelCocosWidget extends CocosWidgetPlatform {
bool? cocosWebSource, bool? cocosWebSource,
String? cocosSrcUrl, String? cocosSrcUrl,
}) { }) {
final String _viewType = 'plugin.xraph.com/cocos_view'; final String _viewType = 'plugin.gem.com/cocos_view';
if (useAndroidViewSurf != null) useAndroidViewSurface = useAndroidViewSurf; if (useAndroidViewSurf != null) useAndroidViewSurface = useAndroidViewSurf;

@ -1,11 +1,12 @@
name: flutter_cocos_view name: flutter_cocos_view
description: "A new Flutter plugin project." description: "A new Flutter plugin project."
version: 0.0.1 version: 0.0.1
homepage: homepage: https://www.openim.io
environment: environment:
sdk: ^3.4.4 sdk: ">=3.0.0 <4.0.0"
flutter: '>=3.3.0' flutter: ">=1.20.0"
dependencies: dependencies:
flutter: flutter:
@ -34,14 +35,15 @@ flutter:
# All these are used by the tooling to maintain consistency when # All these are used by the tooling to maintain consistency when
# adding or updating assets for this project. # adding or updating assets for this project.
plugin: plugin:
platforms:
# This plugin project was generated without specifying any # This plugin project was generated without specifying any
# platforms with the `--platform` argument. If you see the `some_platform` map below, remove it and # platforms with the `--platform` argument. If you see the `some_platform` map below, remove it and
# then add platforms following the instruction here: # then add platforms following the instruction here:
# https://flutter.dev/to/pubspec-plugin-platforms # https://flutter.dev/to/pubspec-plugin-platforms
# ------------------- # -------------------
some_platform: platforms:
pluginClass: somePluginClass ios:
pluginClass: FlutterCocosWidgetPlugin
# ------------------- # -------------------
# To add assets to your plugin package, add an assets section, like this: # To add assets to your plugin package, add an assets section, like this:

Loading…
Cancel
Save