diff --git a/Example/Assets/Example.mm b/Example/Assets/Example.mm index be52bec..9877889 100644 --- a/Example/Assets/Example.mm +++ b/Example/Assets/Example.mm @@ -7,7 +7,7 @@ // #import -#import "unityswift-Swift.h" +#import extern "C" { void _ex_callSwiftMethod(const char *message) { diff --git a/Example/Assets/Example.swift b/Example/Assets/Example.swift index b7a7780..0bdfb6f 100644 --- a/Example/Assets/Example.swift +++ b/Example/Assets/Example.swift @@ -8,13 +8,17 @@ import Foundation -class Example : NSObject { +public class Example : NSObject { static func callUnityMethod(_ message: String) { + let uf = UnityFramework.getInstance() // Call a method on a specified GameObject. - UnitySendMessage("CallbackTarget", "OnCallFromSwift", message) + uf?.sendMessageToGO( + withName: "CallbackTarget", + functionName: "OnCallFromSwift", + message: message) } - @objc static func swiftMethod(_ message: String) { + @objc public static func swiftMethod(_ message: String) { print("\(#function) is called with message: \(message)") self.callUnityMethod("Hello, Unity!") diff --git a/Example/Assets/UnitySwift.meta b/Example/Assets/UnitySwift.meta deleted file mode 100644 index c269f2a..0000000 --- a/Example/Assets/UnitySwift.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: c5463632759494c0c9c76357197ff966 -folderAsset: yes -timeCreated: 1467687641 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Example/Assets/UnitySwift/Editor.meta b/Example/Assets/UnitySwift/Editor.meta deleted file mode 100644 index 8042860..0000000 --- a/Example/Assets/UnitySwift/Editor.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 391a19e6f711b498fa514c157fed3a7a -folderAsset: yes -timeCreated: 1467687641 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Example/Assets/UnitySwift/Editor/PostProcessor.cs b/Example/Assets/UnitySwift/Editor/PostProcessor.cs deleted file mode 100644 index 801dab2..0000000 --- a/Example/Assets/UnitySwift/Editor/PostProcessor.cs +++ /dev/null @@ -1,37 +0,0 @@ -#if UNITY_IOS -using UnityEngine; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEditor.iOS.Xcode; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; - -namespace UnitySwift { - public static class PostProcessor { - [PostProcessBuild] - public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath) { - if(buildTarget == BuildTarget.iOS) { - // So PBXProject.GetPBXProjectPath returns wrong path, we need to construct path by ourselves instead - // var projPath = PBXProject.GetPBXProjectPath(buildPath); - var projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; - var proj = new PBXProject(); - proj.ReadFromFile(projPath); - - var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); - - //// Configure build settings - proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); - proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/UnitySwift/UnitySwift-Bridging-Header.h"); - proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "unityswift-Swift.h"); - proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); - proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0"); - - proj.WriteToFile(projPath); - } - } - } -} -#endif \ No newline at end of file diff --git a/Example/Assets/UnitySwift/Editor/PostProcessor.cs.meta b/Example/Assets/UnitySwift/Editor/PostProcessor.cs.meta deleted file mode 100644 index 9d77065..0000000 --- a/Example/Assets/UnitySwift/Editor/PostProcessor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: fd00e9b781c034ecfa81246579806b3f -timeCreated: 1468687463 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h b/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h deleted file mode 100644 index 7f2da10..0000000 --- a/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h +++ /dev/null @@ -1,7 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import -#import -#import "UnityInterface.h" diff --git a/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h.meta b/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h.meta deleted file mode 100644 index 1622bd4..0000000 --- a/Example/Assets/UnitySwift/UnitySwift-Bridging-Header.h.meta +++ /dev/null @@ -1,90 +0,0 @@ -fileFormatVersion: 2 -guid: d88763964993f492aaed83a9d99f81fb -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - '': Linux - second: - enabled: 0 - settings: - CPU: x86 - - first: - '': OSXIntel - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - '': OSXIntel64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Android: Android - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - CPU: AnyCPU - DefaultValueInitialized: true - OS: AnyOS - - first: - Facebook: Win - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Facebook: Win64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Linux64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Win - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Win64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - iPhone: iOS - second: - enabled: 1 - settings: - CompileFlags: - FrameworkDependencies: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Example/Logs/Packages-Update.log b/Example/Logs/Packages-Update.log index ff9f953..1861678 100644 --- a/Example/Logs/Packages-Update.log +++ b/Example/Logs/Packages-Update.log @@ -45,3 +45,16 @@ The following packages were added: com.unity.modules.vr@1.0.0 com.unity.modules.wind@1.0.0 com.unity.modules.xr@1.0.0 + +=== Wed Jul 22 15:40:25 2020 + +Packages were changed. +Update Mode: updateDependencies + +The following packages were updated: + com.unity.ide.rider from version 1.0.8 to 1.1.4 + com.unity.ide.vscode from version 1.0.7 to 1.2.1 + com.unity.test-framework from version 1.0.13 to 1.1.14 + com.unity.timeline from version 1.1.0 to 1.2.6 +The following packages were removed: + com.unity.package-manager-ui@2.2.0 diff --git a/Example/Packages/manifest.json b/Example/Packages/manifest.json index 328d2ab..ae396d3 100644 --- a/Example/Packages/manifest.json +++ b/Example/Packages/manifest.json @@ -2,12 +2,11 @@ "dependencies": { "com.unity.collab-proxy": "1.2.16", "com.unity.ext.nunit": "1.0.0", - "com.unity.ide.rider": "1.0.8", - "com.unity.ide.vscode": "1.0.7", - "com.unity.package-manager-ui": "2.2.0", - "com.unity.test-framework": "1.0.13", + "com.unity.ide.rider": "1.1.4", + "com.unity.ide.vscode": "1.2.1", + "com.unity.test-framework": "1.1.14", "com.unity.textmeshpro": "2.0.1", - "com.unity.timeline": "1.1.0", + "com.unity.timeline": "1.2.6", "com.unity.ugui": "1.0.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Example/Packages/packages-lock.json b/Example/Packages/packages-lock.json new file mode 100644 index 0000000..1225cec --- /dev/null +++ b/Example/Packages/packages-lock.json @@ -0,0 +1,311 @@ +{ + "dependencies": { + "com.unity.collab-proxy": { + "version": "1.2.16", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ext.nunit": { + "version": "1.0.0", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ide.rider": { + "version": "1.1.4", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.test-framework": "1.1.1" + }, + "url": "https://packages.unity.com" + }, + "com.unity.ide.vscode": { + "version": "1.2.1", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.test-framework": { + "version": "1.1.14", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ext.nunit": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.textmeshpro": { + "version": "2.0.1", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ugui": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.timeline": { + "version": "1.2.6", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ugui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.ui": "1.0.0" + } + }, + "com.unity.modules.ai": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.androidjni": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.animation": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.assetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.audio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.cloth": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.director": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.animation": "1.0.0" + } + }, + "com.unity.modules.imageconversion": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imgui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.jsonserialize": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.particlesystem": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics2d": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.screencapture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.subsystems": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.terrain": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.terrainphysics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.terrain": "1.0.0" + } + }, + "com.unity.modules.tilemap": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics2d": "1.0.0" + } + }, + "com.unity.modules.ui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.uielements": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.umbra": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unityanalytics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.unitywebrequest": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unitywebrequestassetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestaudio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.audio": "1.0.0" + } + }, + "com.unity.modules.unitywebrequesttexture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestwww": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.vehicles": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.video": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.vr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } + }, + "com.unity.modules.wind": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.xr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.subsystems": "1.0.0" + } + } + } +} diff --git a/Example/ProjectSettings/EditorSettings.asset b/Example/ProjectSettings/EditorSettings.asset index 529a05c..872db48 100644 --- a/Example/ProjectSettings/EditorSettings.asset +++ b/Example/ProjectSettings/EditorSettings.asset @@ -3,13 +3,33 @@ --- !u!159 &1 EditorSettings: m_ObjectHideFlags: 0 - serializedVersion: 3 + serializedVersion: 9 m_ExternalVersionControlSupport: Visible Meta Files m_SerializationMode: 2 - m_WebSecurityEmulationEnabled: 0 - m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d + m_LineEndingsForNewScripts: 1 m_DefaultBehaviorMode: 0 + m_PrefabRegularEnvironment: {fileID: 0} + m_PrefabUIEnvironment: {fileID: 0} m_SpritePackerMode: 2 m_SpritePackerPaddingPower: 1 - m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd + m_EtcTextureCompressorBehavior: 0 + m_EtcTextureFastCompressor: 2 + m_EtcTextureNormalCompressor: 2 + m_EtcTextureBestCompressor: 5 + m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmref m_ProjectGenerationRootNamespace: + m_CollabEditorSettings: + inProgressEnabled: 1 + m_EnableTextureStreamingInEditMode: 1 + m_EnableTextureStreamingInPlayMode: 1 + m_AsyncShaderCompilation: 1 + m_EnterPlayModeOptionsEnabled: 0 + m_EnterPlayModeOptions: 3 + m_ShowLightmapResolutionOverlay: 1 + m_UseLegacyProbeSampleCount: 1 + m_AssetPipelineMode: 1 + m_CacheServerMode: 0 + m_CacheServerEndpoint: + m_CacheServerNamespacePrefix: default + m_CacheServerEnableDownload: 1 + m_CacheServerEnableUpload: 1 diff --git a/Example/ProjectSettings/GraphicsSettings.asset b/Example/ProjectSettings/GraphicsSettings.asset index 794c061..4f4dac1 100644 --- a/Example/ProjectSettings/GraphicsSettings.asset +++ b/Example/ProjectSettings/GraphicsSettings.asset @@ -3,16 +3,31 @@ --- !u!30 &1 GraphicsSettings: m_ObjectHideFlags: 0 - serializedVersion: 5 + serializedVersion: 13 m_Deferred: m_Mode: 1 m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} m_DeferredReflections: m_Mode: 1 m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} + m_ScreenSpaceShadows: + m_Mode: 1 + m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} m_LegacyDeferred: m_Mode: 1 m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} + m_DepthNormals: + m_Mode: 1 + m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} + m_MotionVectors: + m_Mode: 1 + m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} + m_LightHalo: + m_Mode: 1 + m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} + m_LensFlare: + m_Mode: 1 + m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} m_AlwaysIncludedShaders: - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} @@ -20,18 +35,32 @@ GraphicsSettings: - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] - m_ShaderSettings: - useScreenSpaceShadows: 0 - m_BuildTargetShaderSettings: [] + m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, + type: 0} + m_CustomRenderPipeline: {fileID: 0} + m_TransparencySortMode: 0 + m_TransparencySortAxis: {x: 0, y: 0, z: 1} + m_DefaultRenderingPath: 1 + m_DefaultMobileRenderingPath: 1 + m_TierSettings: [] m_LightmapStripping: 0 m_FogStripping: 0 + m_InstancingStripping: 0 m_LightmapKeepPlain: 1 m_LightmapKeepDirCombined: 1 - m_LightmapKeepDirSeparate: 1 m_LightmapKeepDynamicPlain: 1 m_LightmapKeepDynamicDirCombined: 1 - m_LightmapKeepDynamicDirSeparate: 1 + m_LightmapKeepShadowMask: 1 + m_LightmapKeepSubtractive: 1 m_FogKeepLinear: 1 m_FogKeepExp: 1 m_FogKeepExp2: 1 + m_AlbedoSwatchInfos: [] + m_LightsUseLinearIntensity: 0 + m_LightsUseColorTemperature: 0 + m_LogWhenShaderIsCompiled: 0 + m_AllowEnlightenSupportForUpgradedProject: 1 diff --git a/Example/ProjectSettings/PresetManager.asset b/Example/ProjectSettings/PresetManager.asset index 2cbec8a..67a94da 100644 Binary files a/Example/ProjectSettings/PresetManager.asset and b/Example/ProjectSettings/PresetManager.asset differ diff --git a/Example/ProjectSettings/ProjectVersion.txt b/Example/ProjectSettings/ProjectVersion.txt index 7e64146..7404e25 100644 --- a/Example/ProjectSettings/ProjectVersion.txt +++ b/Example/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2019.2.0f1 -m_EditorVersionWithRevision: 2019.2.0f1 (20c1667945cf) +m_EditorVersion: 2019.4.1f1 +m_EditorVersionWithRevision: 2019.4.1f1 (e6c045e14e4e) diff --git a/Example/ProjectSettings/UnityConnectSettings.asset b/Example/ProjectSettings/UnityConnectSettings.asset index f21f7e9..fa0b146 100644 Binary files a/Example/ProjectSettings/UnityConnectSettings.asset and b/Example/ProjectSettings/UnityConnectSettings.asset differ diff --git a/Example/ProjectSettings/VFXManager.asset b/Example/ProjectSettings/VFXManager.asset index d677936..3a95c98 100644 Binary files a/Example/ProjectSettings/VFXManager.asset and b/Example/ProjectSettings/VFXManager.asset differ diff --git a/README.md b/README.md index 6adae9c..216f524 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ # unity-swift - -> Forked from the seemingly abandoned [miyabi/unity-swift](https://github.com/miyabi/unity-swift) Native plugin to write native code in [Swift](https://swift.org) for [Unity](http://unity3d.com/). @@ -25,19 +23,19 @@ See [unity-replay-kit-bridge/Example/Assets/UnityReplayKitBridge at swift · miy ### How to call Unity methods -Unity interface functions are defined in *UnityInterface.h* in Xcode project built by Unity. This header file is imported in *UnitySwift-Bridging-Header.h*, so you can call the functions directly in your Swift codes. - -To call Unity methods, use `UnitySendMessage` function like below: - ```swift // Example.swift import Foundation -class Example : NSObject { +public class Example : NSObject { static func callUnityMethod(_ message: String) { + let uf = UnityFramework.getInstance() // Call a method on a specified GameObject. - UnitySendMessage("CallbackTarget", "OnCallFromSwift", message) + uf?.sendMessageToGO( + withName: "CallbackTarget", + functionName: "OnCallFromSwift", + message: message) } } ``` @@ -51,21 +49,22 @@ class Example : NSObject { import Foundation -class Example : NSObject { - @objc static func swiftMethod(_ message: String) { +public class Example : NSObject { + @objc public static func swiftMethod(_ message: String) { print("\(#function) is called with message: \(message)") } } ``` -#### Step 2: Include "unityswift-Swift.h" and define C functions to wrap Swift classes in .mm file (Objective-C++). +#### Step 2: Include UnityFramework/UnityFramework-Swift.h and define C functions to wrap Swift classes in .mm file (Objective-C++). ```objc // Example.mm #import -#import "unityswift-Swift.h" // Required - // This header file is generated automatically when Xcode build runs. +#import +// Required +// This header file is generated automatically when Xcode build runs. extern "C" { void _ex_callSwiftMethod(const char *message) { @@ -104,13 +103,12 @@ public class Example { Example.CallSwiftMethod("Hello, Swift!"); ``` -The file names of *UnitySwift-Bridging-Header.h* and *unityswift-Swift.h* are defined in "Objective-C Bridging Header" entry and "Objective-C Generated Interface Header Name" entry in Build Settings. These settings and other settings about Swift compiler are set automatically by [PostProcesser](./Example/Assets/UnitySwift/Editor/PostProcessor.cs) when the Unity build runs. - ## Requirements iOS 9 or later ## Compatibility -Unity 2019.2.0f1 -Xcode 10.3 +Unity 2019.4.1f1 + +Xcode 11.5 diff --git a/unity-swift.unitypackage b/unity-swift.unitypackage index 3b690b9..847632e 100644 Binary files a/unity-swift.unitypackage and b/unity-swift.unitypackage differ