|
| 1 | +/** |
| 2 | + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * You are hereby granted a non-exclusive, worldwide, royalty-free license to use, |
| 5 | + * copy, modify, and distribute this software in source code or binary form for use |
| 6 | + * in connection with the web services and APIs provided by Facebook. |
| 7 | + * |
| 8 | + * As with any software that integrates with the Facebook platform, your use of |
| 9 | + * this software is subject to the Facebook Developer Principles and Policies |
| 10 | + * [http://developers.facebook.com/policy/]. This copyright notice shall be |
| 11 | + * included in all copies or substantial portions of the software. |
| 12 | + * |
| 13 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 15 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 16 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 17 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 18 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace Facebook.Unity.Editor |
| 22 | +{ |
| 23 | + using UnityEditor; |
| 24 | + using UnityEngine; |
| 25 | + |
| 26 | + public class FacebookImporter : AssetPostprocessor |
| 27 | + { |
| 28 | + private enum WindowsArchitecture |
| 29 | + { |
| 30 | + x86, |
| 31 | + x86_64, |
| 32 | + both |
| 33 | + } |
| 34 | + |
| 35 | + static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) |
| 36 | + { |
| 37 | + Debug.Log("Configuring Facebook SDK dlls for each platform"); |
| 38 | + |
| 39 | + SetCanvasDllConfiguration("/Facebook.Unity.Canvas.dll"); |
| 40 | + SetCanvasDllConfiguration("/CanvasJSSDKBindings.jslib"); |
| 41 | + |
| 42 | + SetAndroidDllConfiguration("/Facebook.Unity.Android.dll"); |
| 43 | + SetAndroidDllConfiguration("/libs/facebook-android-wrapper-14.0.0.aar"); |
| 44 | + |
| 45 | + SetiOSDllConfiguration("/Facebook.Unity.IOS.dll"); |
| 46 | + |
| 47 | + SetiOSEditorSwiftConfiguration("/FBSDKShareTournamentDialog.swift"); |
| 48 | + SetiOSEditorSwiftConfiguration("/FBSDKTournament.swift"); |
| 49 | + SetiOSEditorSwiftConfiguration("/FBSDKTournamentFetcher.swift"); |
| 50 | + SetiOSEditorSwiftConfiguration("/FBSDKTournamentUpdater.swift"); |
| 51 | + |
| 52 | + SetWindowsDllConfiguration("/Facebook.Unity.Windows.dll", WindowsArchitecture.both); |
| 53 | + |
| 54 | + // Windows SDK Dlls x84 and x64 |
| 55 | + SetWindowsDllConfiguration("/LibFBGManaged.dll", WindowsArchitecture.both); |
| 56 | + SetWindowsDllConfiguration("/XInputDotNetPure.dll", WindowsArchitecture.both); |
| 57 | + |
| 58 | + // Windows SDK Dlls only x84 |
| 59 | + SetWindowsDllConfiguration("/x86/LibFBGPlatform.dll", WindowsArchitecture.x86); |
| 60 | + SetWindowsDllConfiguration("/x86/cpprest_2_10.dll", WindowsArchitecture.x86); |
| 61 | + SetWindowsDllConfiguration("/x86/libcrypto-1_1.dll", WindowsArchitecture.x86); |
| 62 | + SetWindowsDllConfiguration("/x86/libcurl.dll", WindowsArchitecture.x86); |
| 63 | + SetWindowsDllConfiguration("/x86/LibFBGUI.dll", WindowsArchitecture.x86); |
| 64 | + SetWindowsDllConfiguration("/x86/libssl-1_1.dll", WindowsArchitecture.x86); |
| 65 | + SetWindowsDllConfiguration("/x86/tinyxml2.dll", WindowsArchitecture.x86); |
| 66 | + SetWindowsDllConfiguration("/x86/WebView2Loader.dll", WindowsArchitecture.x86); |
| 67 | + SetWindowsDllConfiguration("/x86/XInputInterface.dll", WindowsArchitecture.x86); |
| 68 | + SetWindowsDllConfiguration("/x86/zlib1.dll", WindowsArchitecture.x86); |
| 69 | + |
| 70 | + // Windows SDK Dlls only x64 |
| 71 | + SetWindowsDllConfiguration("/x64/LibFBGPlatform.dll", WindowsArchitecture.x86_64); |
| 72 | + SetWindowsDllConfiguration("/x64/cpprest_2_10.dll", WindowsArchitecture.x86_64); |
| 73 | + SetWindowsDllConfiguration("/x64/libcrypto-1_1-x64.dll", WindowsArchitecture.x86_64); |
| 74 | + SetWindowsDllConfiguration("/x64/libcurl.dll", WindowsArchitecture.x86_64); |
| 75 | + SetWindowsDllConfiguration("/x64/LibFBGUI.dll", WindowsArchitecture.x86_64); |
| 76 | + SetWindowsDllConfiguration("/x64/libssl-1_1-x64.dll", WindowsArchitecture.x86_64); |
| 77 | + SetWindowsDllConfiguration("/x64/tinyxml2.dll", WindowsArchitecture.x86_64); |
| 78 | + SetWindowsDllConfiguration("/x64/WebView2Loader.dll", WindowsArchitecture.x86_64); |
| 79 | + SetWindowsDllConfiguration("/x64/XInputInterface.dll", WindowsArchitecture.x86_64); |
| 80 | + SetWindowsDllConfiguration("/x64/zlib1.dll", WindowsArchitecture.x86_64); |
| 81 | + } |
| 82 | + |
| 83 | + private static PluginImporter GetPluginImporter(string path) |
| 84 | + { |
| 85 | + return ((PluginImporter)PluginImporter.GetAtPath("Assets/FacebookSDK"+path)); |
| 86 | + } |
| 87 | + |
| 88 | + private static void SetCanvasDllConfiguration(string path) |
| 89 | + { |
| 90 | + PluginImporter canvasDLL = GetPluginImporter("/Plugins/Canvas" + path); |
| 91 | + if (canvasDLL) |
| 92 | + { |
| 93 | + canvasDLL.SetCompatibleWithAnyPlatform(false); |
| 94 | + canvasDLL.SetCompatibleWithPlatform(BuildTarget.WebGL, true); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + private static void SetAndroidDllConfiguration(string path) |
| 99 | + { |
| 100 | + PluginImporter androidDLL = GetPluginImporter("/Plugins/Android" + path); |
| 101 | + if (androidDLL) |
| 102 | + { |
| 103 | + androidDLL.SetCompatibleWithAnyPlatform(false); |
| 104 | + androidDLL.SetCompatibleWithPlatform(BuildTarget.Android, true); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + private static void SetiOSDllConfiguration(string path) |
| 109 | + { |
| 110 | + PluginImporter iOSDLL = GetPluginImporter("/Plugins/iOS" + path); |
| 111 | + if (iOSDLL) |
| 112 | + { |
| 113 | + iOSDLL.SetCompatibleWithAnyPlatform(false); |
| 114 | + iOSDLL.SetCompatibleWithPlatform(BuildTarget.iOS, true); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + private static void SetiOSEditorSwiftConfiguration(string path) |
| 119 | + { |
| 120 | + PluginImporter iOSDLL = GetPluginImporter("/SDK/Editor/iOS/Swift" + path); |
| 121 | + if (iOSDLL) |
| 122 | + { |
| 123 | + iOSDLL.SetCompatibleWithAnyPlatform(false); |
| 124 | + iOSDLL.SetCompatibleWithEditor(true); |
| 125 | + iOSDLL.SetCompatibleWithPlatform(BuildTarget.iOS, true); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + private static void SetWindowsDllConfiguration(string path, WindowsArchitecture architecture) |
| 130 | + { |
| 131 | + PluginImporter windowsDLL = GetPluginImporter("/Plugins/Windows" + path); |
| 132 | + if (windowsDLL) |
| 133 | + { |
| 134 | + bool isEditor = architecture == WindowsArchitecture.x86_64 || architecture == WindowsArchitecture.both; |
| 135 | + |
| 136 | + windowsDLL.SetCompatibleWithAnyPlatform(false); |
| 137 | + windowsDLL.SetCompatibleWithEditor(isEditor); |
| 138 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.WebGL, false); |
| 139 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.Android, false); |
| 140 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.iOS, false); |
| 141 | + |
| 142 | + switch (architecture) |
| 143 | + { |
| 144 | + case WindowsArchitecture.x86: |
| 145 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, true); |
| 146 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows, "CPU", "AnyCPU"); |
| 147 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false); |
| 148 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows64, "CPU", "none"); |
| 149 | + break; |
| 150 | + case WindowsArchitecture.x86_64: |
| 151 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false); |
| 152 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows, "CPU", "none"); |
| 153 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true); |
| 154 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows64, "CPU", "AnyCPU"); |
| 155 | + break; |
| 156 | + case WindowsArchitecture.both: |
| 157 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, true); |
| 158 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows, "CPU", "AnyCPU"); |
| 159 | + windowsDLL.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true); |
| 160 | + windowsDLL.SetPlatformData(BuildTarget.StandaloneWindows64, "CPU", "AnyCPU"); |
| 161 | + break; |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments