升级到 XCFramework,添加模拟器支持

- 创建支持真机和模拟器的 XCFramework
- 模拟器版本使用空壳实现,用于开发调试
- 真机版本包含完整 Unity 运行时
- 更新 podspec 版本到 1.0.7
- 移除所有架构排除配置,XCFramework 自动处理
This commit is contained in:
zj
2025-11-25 13:37:00 +08:00
parent e6e3231876
commit 1256b5db50
623 changed files with 5330 additions and 24 deletions

View File

@@ -0,0 +1,29 @@
#pragma once
// important app life-cycle events
@protocol LifeCycleListener<NSObject>
@optional
- (void)didFinishLaunching:(NSNotification*)notification;
- (void)didBecomeActive:(NSNotification*)notification;
- (void)willResignActive:(NSNotification*)notification;
- (void)didEnterBackground:(NSNotification*)notification;
- (void)willEnterForeground:(NSNotification*)notification;
- (void)willTerminate:(NSNotification*)notification;
- (void)unityDidUnload:(NSNotification*)notification;
- (void)unityDidQuit:(NSNotification*)notification;
@end
void UnityRegisterLifeCycleListener(id<LifeCycleListener> obj);
void UnityUnregisterLifeCycleListener(id<LifeCycleListener> obj);
#ifdef __cplusplus
extern "C" {
#endif
extern __attribute__((visibility("default"))) NSString* const kUnityDidUnload;
extern __attribute__((visibility("default"))) NSString* const kUnityDidQuit;
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,186 @@
// DO NOT PUT #pragma once or include guard check here
// This header is designed to be able to be included multiple times
// This header is used to redefine platforms after they were temporary undefined by UndefinePlatforms.h
// Please make sure to always use this paired with the UndefinePlatforms.h header.
//
// ex.
//
// #include "UndefinePlatforms.h"
// #include "Some3rdParty.h"
// #include "RedefinePlatforms.h"
#ifndef DETAIL__PLATFORMS_HAD_BEEN_UNDEFINED_BY_UNDEFINEPLATFORMS_H
#error "RedefinePlatforms.h can only be used after UndefinePlatforms.h got included before."
#endif
#undef DETAIL__PLATFORMS_HAD_BEEN_UNDEFINED_BY_UNDEFINEPLATFORMS_H
// define all other platforms to 0
#undef PLATFORM_WIN
#if defined(DETAIL__TEMP_PLATFORM_WIN_WAS_1)
#undef DETAIL__TEMP_PLATFORM_WIN_WAS_1
#define PLATFORM_WIN 1
#else
#define PLATFORM_WIN 0
#endif
#undef PLATFORM_OSX
#if defined(DETAIL__TEMP_PLATFORM_OSX_WAS_1)
#undef DETAIL__TEMP_PLATFORM_OSX_WAS_1
#define PLATFORM_OSX 1
#else
#define PLATFORM_OSX 0
#endif
#undef PLATFORM_LINUX
#if defined(DETAIL__TEMP_PLATFORM_LINUX_WAS_1)
#undef DETAIL__TEMP_PLATFORM_LINUX_WAS_1
#define PLATFORM_LINUX 1
#else
#define PLATFORM_LINUX 0
#endif
#undef PLATFORM_WINRT
#if defined(DETAIL__TEMP_PLATFORM_WINRT_WAS_1)
#undef DETAIL__TEMP_PLATFORM_WINRT_WAS_1
#define PLATFORM_WINRT 1
#else
#define PLATFORM_WINRT 0
#endif
#undef PLATFORM_FAMILY_WINDOWSGAMES
#if defined(DETAIL__TEMP_PLATFORM_FAMILY_WINDOWSGAMES_WAS_1)
#undef DETAIL__TEMP_PLATFORM_FAMILY_WINDOWSGAMES_WAS_1
#define PLATFORM_FAMILY_WINDOWSGAMES 1
#else
#define PLATFORM_FAMILY_WINDOWSGAMES 0
#endif
#undef PLATFORM_WEBGL
#if defined(DETAIL__TEMP_PLATFORM_WEBGL_WAS_1)
#undef DETAIL__TEMP_PLATFORM_WEBGL_WAS_1
#define PLATFORM_WEBGL 1
#else
#define PLATFORM_WEBGL 0
#endif
#undef PLATFORM_WASI
#if defined(DETAIL__TEMP_PLATFORM_WASI_WAS_1)
#undef DETAIL__TEMP_PLATFORM_WASI_WAS_1
#define PLATFORM_WASI 1
#else
#define PLATFORM_WASI 0
#endif
#undef PLATFORM_ANDROID
#if defined(DETAIL__TEMP_PLATFORM_ANDROID_WAS_1)
#undef DETAIL__TEMP_PLATFORM_ANDROID_WAS_1
#define PLATFORM_ANDROID 1
#else
#define PLATFORM_ANDROID 0
#endif
#undef PLATFORM_PS4
#if defined(DETAIL__TEMP_PLATFORM_PS4_WAS_1)
#undef DETAIL__TEMP_PLATFORM_PS4_WAS_1
#define PLATFORM_PS4 1
#else
#define PLATFORM_PS4 0
#endif
#undef PLATFORM_PS5
#if defined(DETAIL__TEMP_PLATFORM_PS5_WAS_1)
#undef DETAIL__TEMP_PLATFORM_PS5_WAS_1
#define PLATFORM_PS5 1
#else
#define PLATFORM_PS5 0
#endif
#undef PLATFORM_IPHONE
#if defined(DETAIL__TEMP_PLATFORM_IPHONE_WAS_1)
#undef DETAIL__TEMP_PLATFORM_IPHONE_WAS_1
#define PLATFORM_IPHONE 1
#else
#define PLATFORM_IPHONE 0
#endif
#undef PLATFORM_IOS
#if defined(DETAIL__TEMP_PLATFORM_IOS_WAS_1)
#undef DETAIL__TEMP_PLATFORM_IOS_WAS_1
#define PLATFORM_IOS 1
#else
#define PLATFORM_IOS 0
#endif
#undef PLATFORM_TVOS
#if defined(DETAIL__TEMP_PLATFORM_TVOS_WAS_1)
#undef DETAIL__TEMP_PLATFORM_TVOS_WAS_1
#define PLATFORM_TVOS 1
#else
#define PLATFORM_TVOS 0
#endif
#undef PLATFORM_VISIONOS
#if defined(DETAIL__TEMP_PLATFORM_VISIONOS_WAS_1)
#undef DETAIL__TEMP_PLATFORM_VISIONOS_WAS_1
#define PLATFORM_VISIONOS 1
#else
#define PLATFORM_VISIONOS 0
#endif
#undef PLATFORM_XBOXONE
#if defined(DETAIL__TEMP_PLATFORM_XBOXONE_WAS_1)
#undef DETAIL__TEMP_PLATFORM_XBOXONE_WAS_1
#define PLATFORM_XBOXONE 1
#else
#define PLATFORM_XBOXONE 0
#endif
#undef PLATFORM_SWITCH
#if defined(DETAIL__TEMP_PLATFORM_SWITCH_WAS_1)
#undef DETAIL__TEMP_PLATFORM_SWITCH_WAS_1
#define PLATFORM_SWITCH 1
#else
#define PLATFORM_SWITCH 0
#endif
#undef PLATFORM_LUMIN
#if defined(DETAIL__TEMP_PLATFORM_LUMIN_WAS_1)
#undef DETAIL__TEMP_PLATFORM_LUMIN_WAS_1
#define PLATFORM_LUMIN 1
#else
#define PLATFORM_LUMIN 0
#endif
#undef PLATFORM_STADIA
#if defined(DETAIL__TEMP_PLATFORM_STADIA_WAS_1)
#undef DETAIL__TEMP_PLATFORM_STADIA_WAS_1
#define PLATFORM_STADIA 1
#else
#define PLATFORM_STADIA 0
#endif
#undef PLATFORM_NETBSD
#if defined(DETAIL__TEMP_PLATFORM_NETBSD_WAS_1)
#undef DETAIL__TEMP_PLATFORM_NETBSD_WAS_1
#define PLATFORM_NETBSD 1
#else
#define PLATFORM_NETBSD 0
#endif
#undef PLATFORM_EMBEDDED_LINUX
#if defined(DETAIL__TEMP_PLATFORM_EMBEDDED_LINUX_WAS_1)
#undef DETAIL__TEMP_PLATFORM_EMBEDDED_LINUX_WAS_1
#define PLATFORM_EMBEDDED_LINUX 1
#else
#define PLATFORM_EMBEDDED_LINUX 0
#endif
#undef PLATFORM_QNX
#if defined(DETAIL__TEMP_PLATFORM_QNX_WAS_1)
#undef DETAIL__TEMP_PLATFORM_QNX_WAS_1
#define PLATFORM_QNX 1
#else
#define PLATFORM_QNX 0
#endif

View File

@@ -0,0 +1,68 @@
#pragma once
#include "LifeCycleListener.h"
struct UnityDisplaySurfaceBase; // Unity/UnityRendering.h
struct RenderingSurfaceParams; // Unity/DisplayManager.h
// due to delicate nature of render loop we have just one delegate in app
// if you need to use several rendering delegates you need to do one of:
// 1. create custom delegate that will have code to combine effects by itself
// 2. use helper that simply holds array of delegates (which will work only in easiest cases)
@protocol RenderPluginDelegate<LifeCycleListener, NSObject>
@required
// this will be called right after gles intialization.
// surface pointer will never be changed, so you should keep it.
// the only valid fields in there as of now are layer and context
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
@optional
// this will be called before recreating main display surface (from [UnityView recreateRenderingSurface])
// you can tweak params here.
// use it for enabling CVTextureCache support and the likes
- (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
// this will be called right after recreating main display surface (from [UnityView recreateRenderingSurface])
// as [UnityView recreateRenderingSurface] is the only place where unity itself will trigger surface recreate
// you can use this method to update your rendering depending on changes
- (void)onAfterMainDisplaySurfaceRecreate;
// this will be called after frame render and msaa resolve but before blitting to system FB
// you can expect that frame contents are ready (though still in target resolution)
// use it for anylizing/postprocessing rendered frame, taking screenshot and the like
// you should use targetFB if it is not 0
// otherwise use systemFB (covers case of intermediate fb not needed: no msaa, native res, no CVTextureCache involved)
- (void)onFrameResolved;
@end
// simple helper for common plugin stuff
// you can implement protocol directly, but subclassing this will provide some common implementation
@interface RenderPluginDelegate : NSObject<RenderPluginDelegate>
{
struct UnityDisplaySurfaceBase* mainDisplaySurface;
}
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
@end
// simple helper to have an array of render delegates.
// be warned that it works in simplest cases only, when there is no interop between delegates
@interface RenderPluginArrayDelegate : RenderPluginDelegate
{
NSArray* delegateArray;
}
@property(nonatomic, retain) NSArray* delegateArray;
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
- (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
- (void)onAfterMainDisplaySurfaceRecreate;
- (void)onFrameResolved;
- (void)didBecomeActive:(NSNotification*)notification;
- (void)willResignActive:(NSNotification*)notification;
- (void)didEnterBackground:(NSNotification*)notification;
- (void)willEnterForeground:(NSNotification*)notification;
- (void)willTerminate:(NSNotification*)notification;
@end

View File

@@ -0,0 +1,123 @@
// DO NOT PUT #pragma once or include guard check here
// This header is designed to be able to be included multiple times
// This header is used to temporary undefine all platform definitions in case there is a naming conflict with
// 3rd party code. Please make sure to always use this paired with the RedefinePlatforms.h header.
//
// ex.
//
// #include "UndefinePlatforms.h"
// #include "Some3rdParty.h"
// #include "RedefinePlatforms.h"
#ifdef DETAIL__PLATFORMS_HAD_BEEN_UNDEFINED_BY_UNDEFINEPLATFORMS_H
#error "UndefinePlatforms.h has been included more than once or RedefinePlatforms.h is missing."
#endif
// define all other platforms to 0
#if PLATFORM_WIN
#define DETAIL__TEMP_PLATFORM_WIN_WAS_1
#endif
#undef PLATFORM_WIN
#if PLATFORM_OSX
#define DETAIL__TEMP_PLATFORM_OSX_WAS_1
#endif
#undef PLATFORM_OSX
#if PLATFORM_LINUX
#define DETAIL__TEMP_PLATFORM_LINUX_WAS_1
#endif
#undef PLATFORM_LINUX
#if PLATFORM_WINRT
#define DETAIL__TEMP_PLATFORM_WINRT_WAS_1
#endif
#undef PLATFORM_WINRT
#if PLATFORM_FAMILY_WINDOWSGAMES
#define DETAIL__TEMP_PLATFORM_FAMILY_WINDOWSGAMES_WAS_1
#endif
#undef PLATFORM_FAMILY_WINDOWSGAMES
#if PLATFORM_WEBGL
#define DETAIL__TEMP_PLATFORM_WEBGL_WAS_1
#endif
#undef PLATFORM_WEBGL
#if PLATFORM_WASI
#define DETAIL__TEMP_PLATFORM_WASI_WAS_1
#endif
#undef PLATFORM_WASI
#if PLATFORM_ANDROID
#define DETAIL__TEMP_PLATFORM_ANDROID_WAS_1
#endif
#undef PLATFORM_ANDROID
#if PLATFORM_PS4
#define DETAIL__TEMP_PLATFORM_PS4_WAS_1
#endif
#undef PLATFORM_PS4
#if PLATFORM_PS5
#define DETAIL__TEMP_PLATFORM_PS5_WAS_1
#endif
#undef PLATFORM_PS5
#if PLATFORM_IPHONE
#define DETAIL__TEMP_PLATFORM_IPHONE_WAS_1
#endif
#undef PLATFORM_IPHONE
#if PLATFORM_IOS
#define DETAIL__TEMP_PLATFORM_IOS_WAS_1
#endif
#undef PLATFORM_IOS
#if PLATFORM_TVOS
#define DETAIL__TEMP_PLATFORM_TVOS_WAS_1
#endif
#undef PLATFORM_TVOS
#if PLATFORM_VISIONOS
#define DETAIL__TEMP_PLATFORM_VISIONOS_WAS_1
#endif
#undef PLATFORM_VISIONOS
#if PLATFORM_XBOXONE
#define DETAIL__TEMP_PLATFORM_XBOXONE_WAS_1
#endif
#undef PLATFORM_XBOXONE
#if PLATFORM_SWITCH
#define DETAIL__TEMP_PLATFORM_SWITCH_WAS_1
#endif
#undef PLATFORM_SWITCH
#if PLATFORM_LUMIN
#define DETAIL__TEMP_PLATFORM_LUMIN_WAS_1
#endif
#undef PLATFORM_LUMIN
#if PLATFORM_STADIA
#define DETAIL__TEMP_PLATFORM_STADIA_WAS_1
#endif
#undef PLATFORM_STADIA
#if PLATFORM_NETBSD
#define DETAIL__TEMP_PLATFORM_NETBSD_WAS_1
#endif
#undef PLATFORM_NETBSD
#if PLATFORM_EMBEDDED_LINUX
#define DETAIL__TEMP_PLATFORM_EMBEDDED_LINUX_WAS_1
#endif
#undef PLATFORM_EMBEDDED_LINUX
#if PLATFORM_QNX
#define DETAIL__TEMP_PLATFORM_QNX_WAS_1
#endif
#undef PLATFORM_QNX
#define DETAIL__PLATFORMS_HAD_BEEN_UNDEFINED_BY_UNDEFINEPLATFORMS_H

View File

@@ -0,0 +1,140 @@
#pragma once
#import <QuartzCore/CADisplayLink.h>
#include "RenderPluginDelegate.h"
// Edited by https://github.com/juicycleff/flutter-unity-view-widget
// Added by https://github.com/juicycleff/flutter-unity-view-widget
typedef void(^unitySceneLoadedCallbackType)(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid);
typedef void(^unityMessageCallbackType)(const char* message);
// Added by https://github.com/juicycleff/flutter-unity-view-widget
@protocol UnityEventListener <NSObject>
- (void)onSceneLoaded:(NSString *)name buildIndex:(NSInteger *)bIndex loaded:(bool *)isLoaded valid:(bool *)IsValid;
- (void)onMessage:(NSString *)message;
@end
@class UnityView;
@class UnityViewControllerBase;
@class DisplayConnection;
__attribute__ ((visibility("default")))
@interface UnityAppController : NSObject<UIApplicationDelegate>
{
UnityView* _unityView;
CADisplayLink* _displayLink;
UIWindow* _window;
UIView* _rootView;
UIViewController* _rootController;
UIViewController* _snapshotViewController;
DisplayConnection* _mainDisplay;
// CODE ARCHEOLOGY: we were caching view controllers, both autorotation one and per-fixed-orientation ones
// CODE ARCHEOLOGY: we stopped doing this as the performance impact is negligible,
// CODE ARCHEOLOGY: yet it introduces corner cases and in general lots of code
#if UNITY_SUPPORT_ROTATION
UIInterfaceOrientation _curOrientation;
#endif
id<RenderPluginDelegate> _renderDelegate;
}
// override it to add your render plugin delegate
- (void)shouldAttachRenderDelegate;
// this one is called at the very end of didFinishLaunchingWithOptions:
// after views have been created but before initing engine itself
// override it to register plugins, tweak UI etc
- (void)preStartUnity;
// this one is called at at the very end of didFinishLaunchingWithOptions:
// it will start showing unity view and rendering unity content
- (void)startUnity:(UIApplication*)application;
// this is a part of UIApplicationDelegate protocol starting with ios5
// setter will be generated empty
@property (retain, nonatomic) UIWindow* window;
@property (readonly, copy, nonatomic) UnityView* unityView;
@property (readonly, copy, nonatomic) CADisplayLink* unityDisplayLink;
@property (readonly, copy, nonatomic) UIView* rootView;
@property (readonly, copy, nonatomic) UIViewController* rootViewController;
@property (readonly, copy, nonatomic) DisplayConnection* mainDisplay;
#if UNITY_SUPPORT_ROTATION
@property (readonly, nonatomic) UIInterfaceOrientation interfaceOrientation;
#endif
@property (nonatomic, retain) id renderDelegate;
@property (nonatomic, copy) void (^quitHandler)(void);
@property (nonatomic, copy) void(^unitySceneLoadedHandler)(const char* name, const int* buildIndex, const bool* isLoaded, const bool* IsValid);
@property (nonatomic, copy) void(^unityMessageHandler)(const char* message);
@end
// accessing app controller
#ifdef __cplusplus
extern "C" {
#endif
extern UnityAppController* _UnityAppController;
extern UnityAppController* GetAppController(void);
#ifdef __cplusplus
} // extern "C"
#endif
// Put this into mm file with your subclass implementation
// pass subclass name to define
#define IMPL_APP_CONTROLLER_SUBCLASS(ClassName) \
@interface ClassName(OverrideAppDelegate) \
{ \
} \
+(void)load; \
@end \
@implementation ClassName(OverrideAppDelegate) \
+(void)load \
{ \
extern const char* AppControllerClassName; \
AppControllerClassName = #ClassName; \
} \
@end \
// plugins
#define APP_CONTROLLER_RENDER_PLUGIN_METHOD(method) \
do { \
id<RenderPluginDelegate> delegate = GetAppController().renderDelegate; \
if([delegate respondsToSelector:@selector(method)]) \
[delegate method]; \
} while(0)
#define APP_CONTROLLER_RENDER_PLUGIN_METHOD_ARG(method, arg) \
do { \
id<RenderPluginDelegate> delegate = GetAppController().renderDelegate; \
if([delegate respondsToSelector:@selector(method:)]) \
[delegate method:arg]; \
} while(0)
// these are simple wrappers about ios api, added for convenience
void AppController_SendNotification(NSString* name);
void AppController_SendNotificationWithArg(NSString* name, id arg);
void AppController_SendUnityViewControllerNotification(NSString* name);
// in the case when apple adds new api that has easy fallback path for old ios
// we will add new api methods at runtime on older ios, so we can switch to new api universally
// in that case we still need actual declaration: we will do it here as it is the most convenient place
// history:
// [CADisplayLink preferredFramesPerSecond], [UIScreen maximumFramesPerSecond], [UIView safeAreaInsets]
// were removed after we started to enforce xcode9 (sdk 11)

View File

@@ -0,0 +1,67 @@
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <UnityFramework/UnityAppController.h>
// this is coming from mach-o/ldsyms.h
// we were including this header header here directly
// alas we were including <mach-o/ldsyms.h> directly in UnityFramework.h (for mach_header definition)
// instead of doing forward declaration and using, say, void pointers in unity c-interface
// and this resulted in code in the wild that uses _mh_execute_header directly without this include
// now, with C++/ObjC++ modules support we end up in a funny situation,
// where we need to include UndefinePlatforms/RedefinePlatforms quoted which gives a warning
// thankfully, we can easily provide the definition of _mh_execute_header ourselves
typedef struct mach_header_64 MachHeader;
extern const struct mach_header_64 _mh_execute_header;
//! Project version number for UnityFramework.
FOUNDATION_EXPORT double UnityFrameworkVersionNumber;
//! Project version string for UnityFramework.
FOUNDATION_EXPORT const unsigned char UnityFrameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <UnityFramework/PublicHeader.h>
#pragma once
// important app life-cycle events
__attribute__ ((visibility("default")))
@protocol UnityFrameworkListener<NSObject>
@optional
- (void)unityDidUnload:(NSNotification*)notification;
- (void)unityDidQuit:(NSNotification*)notification;
@end
__attribute__ ((visibility("default")))
@interface UnityFramework : NSObject
{
}
- (UnityAppController*)appController;
- (UITextField*)keyboardTextField;
+ (UnityFramework*)getInstance;
- (void)setDataBundleId:(const char*)bundleId;
- (void)runUIApplicationMainWithArgc:(int)argc argv:(char*[])argv;
- (void)runEmbeddedWithArgc:(int)argc argv:(char*[])argv appLaunchOpts:(NSDictionary*)appLaunchOpts;
- (void)unloadApplication;
- (void)quitApplication:(int)exitCode;
- (void)registerFrameworkListener:(id<UnityFrameworkListener>)obj;
- (void)unregisterFrameworkListener:(id<UnityFrameworkListener>)obj;
- (void)showUnityWindow;
- (void)pause:(bool)pause;
- (void)setAbsoluteURL:(const char *)url;
- (void)setExecuteHeader:(const MachHeader*)header;
- (void)sendMessageToGOWithName:(const char*)goName functionName:(const char*)name message:(const char*)msg;
@end

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>UnityFramework</string>
<key>CFBundleIdentifier</key>
<string>com.unity3d.framework</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>UnityFramework</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>13.0</string>
</dict>
</plist>

View File

@@ -0,0 +1,5 @@
framework module UnityFramework {
umbrella header "UnityFramework.h"
export *
module * { export * }
}

Binary file not shown.