From aac26240206e3f582929ab7ddbb16d9efe567290 Mon Sep 17 00:00:00 2001 From: bselva Date: Sat, 12 Jul 2025 13:02:36 +0530 Subject: [PATCH 1/2] Added Source converted to Package --- unity_package/Core.meta | 8 + unity_package/Core/Editor.meta | 8 + unity_package/Core/Editor/BuildScript.meta | 8 + .../Core/Editor/BuildScript/Build.cs | 1040 +++ .../Core/Editor/BuildScript/Build.cs.meta | 11 + .../FlutterUnityIntegration.Editor.asmdef | 19 + ...FlutterUnityIntegration.Editor.asmdef.meta | 7 + unity_package/Core/Editor/Helper.meta | 8 + .../Core/Editor/Helper/BuildPathsHelper.cs | 24 + .../Editor/Helper/BuildPathsHelper.cs.meta | 2 + .../Core/Editor/Helper/SweetShellHelper.cs | 52 + .../Editor/Helper/SweetShellHelper.cs.meta | 11 + .../Core/Editor/Helper/SymbolDefineHelper.cs | 58 + .../Editor/Helper/SymbolDefineHelper.cs.meta | 2 + unity_package/Core/Editor/PostBuild.meta | 8 + .../Core/Editor/PostBuild/XCodePostBuild.cs | 382 + .../Editor/PostBuild/XCodePostBuild.cs.meta | 11 + unity_package/Core/FlutterUnity.jslib | 9 + unity_package/Core/FlutterUnity.jslib.meta | 86 + .../Core/FlutterUnityIntegration.asmdef | 14 + .../Core/FlutterUnityIntegration.asmdef.meta | 7 + unity_package/Core/Plugins.meta | 8 + unity_package/Core/Plugins/iOS.meta | 8 + .../Core/Plugins/iOS/NativeCallProxy.h | 23 + .../Core/Plugins/iOS/NativeCallProxy.h.meta | 86 + .../Core/Plugins/iOS/NativeCallProxy.mm | 21 + .../Core/Plugins/iOS/NativeCallProxy.mm.meta | 86 + unity_package/Core/Runtime.meta | 8 + unity_package/Core/Runtime/NativeAPI.cs | 118 + unity_package/Core/Runtime/NativeAPI.cs.meta | 11 + .../Core/Runtime/SingletonMonoBehaviour.cs | 20 + .../Runtime/SingletonMonoBehaviour.cs.meta | 11 + .../Core/Runtime/UnityMessageManager.cs | 162 + .../Core/Runtime/UnityMessageManager.cs.meta | 11 + unity_package/Demo.meta | 8 + unity_package/Demo/FUH.Demo.asmdef | 16 + unity_package/Demo/FUH.Demo.asmdef.meta | 7 + unity_package/Demo/Prefabs.meta | 8 + unity_package/Demo/Prefabs/Canvas_cool.prefab | 838 ++ .../Demo/Prefabs/Canvas_cool.prefab.meta | 7 + unity_package/Demo/Prefabs/EventSystem.prefab | 68 + .../Demo/Prefabs/EventSystem.prefab.meta | 7 + unity_package/Demo/Scenes.meta | 8 + unity_package/Demo/Scenes/NativeScene.unity | 1330 +++ .../Demo/Scenes/NativeScene.unity.meta | 7 + unity_package/Demo/Scenes/SampleScene.meta | 8 + unity_package/Demo/Scenes/SampleScene.unity | 798 ++ .../Demo/Scenes/SampleScene.unity.meta | 7 + .../Scenes/SampleScene/LightingData.asset | Bin 0 -> 17761 bytes .../SampleScene/LightingData.asset.meta | 8 + .../Scenes/SampleScene/ReflectionProbe-0.exr | Bin 0 -> 163874 bytes .../SampleScene/ReflectionProbe-0.exr.meta | 143 + unity_package/Demo/Scenes/scene_2.unity | 624 ++ unity_package/Demo/Scenes/scene_2.unity.meta | 7 + unity_package/Demo/Scripts.meta | 8 + unity_package/Demo/Scripts/GameManager.cs | 38 + .../Demo/Scripts/GameManager.cs.meta | 11 + unity_package/Demo/Scripts/Rotate.cs | 46 + unity_package/Demo/Scripts/Rotate.cs.meta | 11 + unity_package/Demo/Scripts/SceneLoader.cs | 47 + .../Demo/Scripts/SceneLoader.cs.meta | 11 + unity_package/JsonDotNet.meta | 8 + unity_package/JsonDotNet/Assemblies.meta | 9 + unity_package/JsonDotNet/Assemblies/AOT.meta | 9 + .../Assemblies/AOT/Newtonsoft.Json.XML | 8015 ++++++++++++++++ .../Assemblies/AOT/Newtonsoft.Json.XML.meta | 8 + .../Assemblies/AOT/Newtonsoft.Json.dll | Bin 0 -> 399360 bytes .../Assemblies/AOT/Newtonsoft.Json.dll.meta | 33 + .../JsonDotNet/Assemblies/Standalone.meta | 9 + .../Assemblies/Standalone/Newtonsoft.Json.XML | 8040 +++++++++++++++++ .../Standalone/Newtonsoft.Json.XML.meta | 8 + .../Standalone/Newtonsoft.Json.dll.txt | Bin 0 -> 404480 bytes .../Standalone/Newtonsoft.Json.dll.txt.meta | 7 + .../JsonDotNet/Assemblies/Windows.meta | 9 + .../Assemblies/Windows/Newtonsoft.Json.XML | 7977 ++++++++++++++++ .../Windows/Newtonsoft.Json.XML.meta | 8 + .../Windows/Newtonsoft.Json.dll.txt | Bin 0 -> 426496 bytes .../Windows/Newtonsoft.Json.dll.txt.meta | 7 + unity_package/JsonDotNet/link.xml | 7 + unity_package/JsonDotNet/link.xml.meta | 6 + unity_package/README.txt | 5 + unity_package/README.txt.meta | 7 + unity_package/link.xml | 32 + unity_package/link.xml.meta | 7 + unity_package/package.json | 18 + unity_package/package.json.meta | 7 + 86 files changed, 30655 insertions(+) create mode 100644 unity_package/Core.meta create mode 100644 unity_package/Core/Editor.meta create mode 100644 unity_package/Core/Editor/BuildScript.meta create mode 100644 unity_package/Core/Editor/BuildScript/Build.cs create mode 100644 unity_package/Core/Editor/BuildScript/Build.cs.meta create mode 100644 unity_package/Core/Editor/FlutterUnityIntegration.Editor.asmdef create mode 100644 unity_package/Core/Editor/FlutterUnityIntegration.Editor.asmdef.meta create mode 100644 unity_package/Core/Editor/Helper.meta create mode 100644 unity_package/Core/Editor/Helper/BuildPathsHelper.cs create mode 100644 unity_package/Core/Editor/Helper/BuildPathsHelper.cs.meta create mode 100644 unity_package/Core/Editor/Helper/SweetShellHelper.cs create mode 100644 unity_package/Core/Editor/Helper/SweetShellHelper.cs.meta create mode 100644 unity_package/Core/Editor/Helper/SymbolDefineHelper.cs create mode 100644 unity_package/Core/Editor/Helper/SymbolDefineHelper.cs.meta create mode 100644 unity_package/Core/Editor/PostBuild.meta create mode 100644 unity_package/Core/Editor/PostBuild/XCodePostBuild.cs create mode 100644 unity_package/Core/Editor/PostBuild/XCodePostBuild.cs.meta create mode 100644 unity_package/Core/FlutterUnity.jslib create mode 100644 unity_package/Core/FlutterUnity.jslib.meta create mode 100644 unity_package/Core/FlutterUnityIntegration.asmdef create mode 100644 unity_package/Core/FlutterUnityIntegration.asmdef.meta create mode 100644 unity_package/Core/Plugins.meta create mode 100644 unity_package/Core/Plugins/iOS.meta create mode 100644 unity_package/Core/Plugins/iOS/NativeCallProxy.h create mode 100644 unity_package/Core/Plugins/iOS/NativeCallProxy.h.meta create mode 100644 unity_package/Core/Plugins/iOS/NativeCallProxy.mm create mode 100644 unity_package/Core/Plugins/iOS/NativeCallProxy.mm.meta create mode 100644 unity_package/Core/Runtime.meta create mode 100644 unity_package/Core/Runtime/NativeAPI.cs create mode 100644 unity_package/Core/Runtime/NativeAPI.cs.meta create mode 100644 unity_package/Core/Runtime/SingletonMonoBehaviour.cs create mode 100644 unity_package/Core/Runtime/SingletonMonoBehaviour.cs.meta create mode 100644 unity_package/Core/Runtime/UnityMessageManager.cs create mode 100644 unity_package/Core/Runtime/UnityMessageManager.cs.meta create mode 100644 unity_package/Demo.meta create mode 100644 unity_package/Demo/FUH.Demo.asmdef create mode 100644 unity_package/Demo/FUH.Demo.asmdef.meta create mode 100644 unity_package/Demo/Prefabs.meta create mode 100644 unity_package/Demo/Prefabs/Canvas_cool.prefab create mode 100644 unity_package/Demo/Prefabs/Canvas_cool.prefab.meta create mode 100644 unity_package/Demo/Prefabs/EventSystem.prefab create mode 100644 unity_package/Demo/Prefabs/EventSystem.prefab.meta create mode 100644 unity_package/Demo/Scenes.meta create mode 100644 unity_package/Demo/Scenes/NativeScene.unity create mode 100644 unity_package/Demo/Scenes/NativeScene.unity.meta create mode 100644 unity_package/Demo/Scenes/SampleScene.meta create mode 100644 unity_package/Demo/Scenes/SampleScene.unity create mode 100644 unity_package/Demo/Scenes/SampleScene.unity.meta create mode 100644 unity_package/Demo/Scenes/SampleScene/LightingData.asset create mode 100644 unity_package/Demo/Scenes/SampleScene/LightingData.asset.meta create mode 100644 unity_package/Demo/Scenes/SampleScene/ReflectionProbe-0.exr create mode 100644 unity_package/Demo/Scenes/SampleScene/ReflectionProbe-0.exr.meta create mode 100644 unity_package/Demo/Scenes/scene_2.unity create mode 100644 unity_package/Demo/Scenes/scene_2.unity.meta create mode 100644 unity_package/Demo/Scripts.meta create mode 100644 unity_package/Demo/Scripts/GameManager.cs create mode 100644 unity_package/Demo/Scripts/GameManager.cs.meta create mode 100644 unity_package/Demo/Scripts/Rotate.cs create mode 100644 unity_package/Demo/Scripts/Rotate.cs.meta create mode 100644 unity_package/Demo/Scripts/SceneLoader.cs create mode 100644 unity_package/Demo/Scripts/SceneLoader.cs.meta create mode 100644 unity_package/JsonDotNet.meta create mode 100644 unity_package/JsonDotNet/Assemblies.meta create mode 100644 unity_package/JsonDotNet/Assemblies/AOT.meta create mode 100644 unity_package/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.XML create mode 100644 unity_package/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.XML.meta create mode 100644 unity_package/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.dll create mode 100644 unity_package/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.dll.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Standalone.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.XML create mode 100644 unity_package/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.XML.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll.txt create mode 100644 unity_package/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll.txt.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Windows.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Windows/Newtonsoft.Json.XML create mode 100644 unity_package/JsonDotNet/Assemblies/Windows/Newtonsoft.Json.XML.meta create mode 100644 unity_package/JsonDotNet/Assemblies/Windows/Newtonsoft.Json.dll.txt create mode 100644 unity_package/JsonDotNet/Assemblies/Windows/Newtonsoft.Json.dll.txt.meta create mode 100644 unity_package/JsonDotNet/link.xml create mode 100644 unity_package/JsonDotNet/link.xml.meta create mode 100644 unity_package/README.txt create mode 100644 unity_package/README.txt.meta create mode 100644 unity_package/link.xml create mode 100644 unity_package/link.xml.meta create mode 100644 unity_package/package.json create mode 100644 unity_package/package.json.meta diff --git a/unity_package/Core.meta b/unity_package/Core.meta new file mode 100644 index 000000000..bf797558a --- /dev/null +++ b/unity_package/Core.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8a5f45640c2512d4d8266cd99bef90d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity_package/Core/Editor.meta b/unity_package/Core/Editor.meta new file mode 100644 index 000000000..ac4afcf94 --- /dev/null +++ b/unity_package/Core/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce285f5b99c7a4c1387f17e5f6fd9367 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity_package/Core/Editor/BuildScript.meta b/unity_package/Core/Editor/BuildScript.meta new file mode 100644 index 000000000..e4af7d83f --- /dev/null +++ b/unity_package/Core/Editor/BuildScript.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7aac45229f294394aa9c86aa8bbba361 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity_package/Core/Editor/BuildScript/Build.cs b/unity_package/Core/Editor/BuildScript/Build.cs new file mode 100644 index 000000000..218ff3fec --- /dev/null +++ b/unity_package/Core/Editor/BuildScript/Build.cs @@ -0,0 +1,1040 @@ +using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEditor.Build; +using UnityEngine; +using Application = UnityEngine.Application; +using BuildResult = UnityEditor.Build.Reporting.BuildResult; + +#if USING_ADDRESSABLES +using UnityEditor.AddressableAssets; +using UnityEditor.AddressableAssets.Settings; +#endif +namespace FlutterUnityIntegration.Editor +{ + public class Build : EditorWindow + { + private static readonly string ProjectPath = Path.GetFullPath(Path.Combine(Application.dataPath, "..")); + private static readonly string APKPath = Path.Combine(ProjectPath, "Builds/" + Application.productName + ".apk"); + + private static readonly string AndroidExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../android/unityLibrary")); + private static readonly string WindowsExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../windows/unityLibrary/data")); + private static readonly string IOSExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios/UnityLibrary")); + private static readonly string WebExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../web/UnityLibrary")); + private static readonly string IOSExportPluginPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios_xcode/UnityLibrary")); + + private static bool _pluginMode = false; + private static string _persistentKey = "flutter-unity-widget-pluginMode"; + + private const string USING_ADDRESSABLES = "USING_ADDRESSABLES"; + + private static string _persistentKeyHasAddressable = "flutter-unity-widget-hasAddressable"; + private static bool _usingAddressables = false; + + public static string _persistentOverrideStatus = "flutter-unity-widget-OverrideStatus"; + private static bool _overrideBuildPaths = false; + + + //#region GUI Member Methods + [MenuItem("Flutter/Export Android (Debug) %&n", false, 101)] + public static void DoBuildAndroidLibraryDebug() + { + DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, false); + } + + [MenuItem("Flutter/Export Android (Release) %&m", false, 102)] + public static void DoBuildAndroidLibraryRelease() + { + DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, true); + } + + [MenuItem("Flutter/Export Android Plugin %&p", false, 103)] + public static void DoBuildAndroidPlugin() + { + DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), true, true); + } + + [MenuItem("Flutter/Export IOS (Debug) %&i", false, 201)] + public static void DoBuildIOSDebug() + { + BuildIOS(IOSExportPath, false); + } + + [MenuItem("Flutter/Export IOS (Release) %&i", false, 202)] + public static void DoBuildIOSRelease() + { + BuildIOS(IOSExportPath, true); + } + + [MenuItem("Flutter/Export IOS Plugin %&o", false, 203)] + public static void DoBuildIOSPlugin() + { + BuildIOS(IOSExportPluginPath, true); + + // Automate so manual steps + SetupIOSProjectForPlugin(); + + // Build Archive + // BuildUnityFrameworkArchive(); + + } + + [MenuItem("Flutter/Export Web GL %&w", false, 301)] + public static void DoBuildWebGL() + { + BuildWebGL(WebExportPath); + } + + // Hide this button as windows isn't implemented in the Flutter plugin yet. + // [MenuItem("Flutter/Export Windows %&d", false, 401)] + public static void DoBuildWindowsOS() + { + BuildWindowsOS(WindowsExportPath); + } + + [MenuItem("Flutter/Settings %&S", false, 501)] + public static void PluginSettings() + { + EditorWindow.GetWindow(typeof(Build)); + } + + bool hasChanges = false; + private void OnGUI() + { + GUILayout.Label("Flutter Unity Widget Settings", EditorStyles.boldLabel); + + + EditorGUI.BeginChangeCheck(); + _pluginMode = EditorGUILayout.Toggle("Plugin Mode", _pluginMode); + + if (EditorGUI.EndChangeCheck()) + { + EditorPrefs.SetBool(_persistentKey, _pluginMode); + } + + using (new EditorGUILayout.HorizontalScope()) + { + + EditorGUI.BeginChangeCheck(); + _usingAddressables = EditorGUILayout.Toggle("Using Addressables", _usingAddressables); + if (EditorGUI.EndChangeCheck()) + { + EditorPrefs.SetBool(_persistentKeyHasAddressable, _usingAddressables); + hasChanges = true; + Repaint(); + } + + if (GUILayout.Button("Apply Symbols")) + { + if (hasChanges) + { + Apply(); + Repaint(); + } + else + { + Debug.Log("No Changes required!"); + } + } + } + + EditorGUI.BeginChangeCheck(); + _overrideBuildPaths = EditorGUILayout.Toggle("Override Build Paths", _overrideBuildPaths); + if (EditorGUI.EndChangeCheck()) + { + EditorPrefs.SetBool(_persistentOverrideStatus, _overrideBuildPaths); + Repaint(); + } + + + // Web Export Path + using (var horizontalScope = new GUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("WebGL Export Path", GUILayout.Width(150)); + GUI.enabled = false; + EditorGUILayout.TextField(BuildPathsHelper.Overriden_WebExportPath); + GUI.enabled = true; + + if (GUILayout.Button("...", GUILayout.Width(30))) + { + string selectedPath = EditorUtility.OpenFolderPanel("Select WebGL Export Folder", "", ""); + if (!string.IsNullOrEmpty(selectedPath)) + { + selectedPath = Path.Combine(selectedPath, "UnityLibrary"); + BuildPathsHelper.Overriden_WebExportPath = selectedPath; + } + + EditorPrefs.SetString(BuildPathsHelper._persistentWebExportPath, selectedPath); + } + } + + GUI.enabled = false; + + if (_overrideBuildPaths) + { + // Android Export Path + using (var horizontalScope = new GUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("Android Export Path", GUILayout.Width(150)); + + GUI.enabled = false; + EditorGUILayout.TextField(BuildPathsHelper.Overriden_AndroidExportPath); + //GUI.enabled = true; + + if (GUILayout.Button("...", GUILayout.Width(30))) + { + string selectedPath = EditorUtility.OpenFolderPanel("Select Android Export Folder", "", "unityLibrary"); + if (!string.IsNullOrEmpty(selectedPath)) + { + selectedPath = Path.Combine(selectedPath, "UnityLibrary"); + BuildPathsHelper.Overriden_AndroidExportPath = selectedPath; + } + EditorPrefs.SetString(BuildPathsHelper.Overriden_AndroidExportPath, selectedPath); + } + } + + // Windows Export Path + + //using (var horizontalScope = new GUILayout.HorizontalScope()) + //{ + // EditorGUILayout.LabelField("Windows Export Path", GUILayout.Width(150)); + + // GUI.enabled = false; + // EditorGUILayout.TextField(BuildPathsHelper.Overriden_WindowsExportPath); + // GUI.enabled = true; + + // if (GUILayout.Button("...", GUILayout.Width(30))) + // { + // string selectedPath = EditorUtility.OpenFolderPanel("Select Windows Export Folder", "", ""); + // if (!string.IsNullOrEmpty(selectedPath)) + // { + // selectedPath = Path.Combine(selectedPath, "UnityLibrary"); + // BuildPathsHelper.Overriden_WindowsExportPath = selectedPath; + // } + // EditorPrefs.SetString(BuildPathsHelper._persistentWindowsExportPath, selectedPath); + // } + //} + + // iOS Export Path + using (var horizontalScope = new GUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("iOS Export Path", GUILayout.Width(150)); + + GUI.enabled = false; + EditorGUILayout.TextField(BuildPathsHelper.Overriden_IOSExportPath); + //GUI.enabled = true; + + if (GUILayout.Button("...", GUILayout.Width(30))) + { + string selectedPath = EditorUtility.OpenFolderPanel("Select iOS Export Folder", "", ""); + if (!string.IsNullOrEmpty(selectedPath)) + { + selectedPath = Path.Combine(selectedPath, "UnityLibrary"); + BuildPathsHelper.Overriden_IOSExportPath = selectedPath; + } + EditorPrefs.SetString(BuildPathsHelper._persistentIOSExportPath, selectedPath); + } + } + + + // iOS Plugin Export Path + using (var horizontalScope = new GUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("iOS Plugin Path", GUILayout.Width(150)); + + GUI.enabled = false; + EditorGUILayout.TextField(BuildPathsHelper.Overriden_IOSExportPluginPath); + //GUI.enabled = true; + + if (GUILayout.Button("...", GUILayout.Width(30))) + { + string selectedPath = EditorUtility.OpenFolderPanel("Select iOS Plugin Folder", "", ""); + if (!string.IsNullOrEmpty(selectedPath)) + { + selectedPath = Path.Combine(selectedPath, "UnityLibrary"); + BuildPathsHelper.Overriden_IOSExportPluginPath = selectedPath; + } + EditorPrefs.SetString(BuildPathsHelper._persistentIOSExportPluginPath, selectedPath); + } + + } + GUI.enabled = true; + + } + + } + + private void Apply() + { + EditorApplication.delayCall += () => { + SymbolDefineHelper.SetScriptingDefine(USING_ADDRESSABLES, _usingAddressables); + }; + Close(); + } + + + + private void OnEnable() + { + InitPrefs(); + } + + private static void InitPrefs() + { + _pluginMode = EditorPrefs.GetBool(_persistentKey, false); + _usingAddressables = EditorPrefs.GetBool(_persistentKeyHasAddressable, false); + _overrideBuildPaths = EditorPrefs.GetBool(_persistentOverrideStatus, false); + BuildPathsHelper.Overriden_WebExportPath = EditorPrefs.GetString(BuildPathsHelper._persistentWebExportPath, BuildPathsHelper.Overriden_WebExportPath); + } + + //#endregion + + + //#region Build Member Methods + + private static void BuildWindowsOS(String path) + { + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); + + if (Directory.Exists(path)) + Directory.Delete(path, true); + + if (Directory.Exists(WindowsExportPath)) + Directory.Delete(WindowsExportPath, true); + + var playerOptions = new BuildPlayerOptions + { + scenes = GetEnabledScenes(), + target = BuildTarget.StandaloneWindows64, + locationPathName = path, + options = BuildOptions.AllowDebugging + }; + + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); + + // build addressable + ExportAddressables(); + var report = BuildPipeline.BuildPlayer(playerOptions); + + if (report.summary.result != BuildResult.Succeeded) + throw new Exception("Build failed"); + + Debug.Log("-- Windows Build: SUCCESSFUL --"); + } + + private static void BuildWebGL(String path) + { + InitPrefs(); + + + if (_overrideBuildPaths) + { + // Check if the Unity project is in the expected location + if (!IsProjectLocationValid(path, "web")) + { + return; + } + } + + path = _overrideBuildPaths ? BuildPathsHelper.Overriden_WebExportPath : path; + + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); + + if (Directory.Exists(path)) + Directory.Delete(path, true); + + if (Directory.Exists(WebExportPath)) + Directory.Delete(WebExportPath, true); + + + + // EditorUserBuildSettings. = true; + + var playerOptions = new BuildPlayerOptions(); + playerOptions.scenes = GetEnabledScenes(); + playerOptions.target = BuildTarget.WebGL; + playerOptions.locationPathName = path; + + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL); + // build addressable + ExportAddressables(); + var report = BuildPipeline.BuildPlayer(playerOptions); + + if (report.summary.result != BuildResult.Succeeded) + throw new Exception("Build failed"); + + // Copy(path, WebExportPath); + ModifyWebGLExport(); + + Debug.Log("-- WebGL Build: SUCCESSFUL --"); + } + + private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isReleaseBuild) + { + InitPrefs(); + + if (_overrideBuildPaths) + { + // Check if the Unity project is in the expected location + if (!IsProjectLocationValid(AndroidExportPath, "android")) + { + return; + } + } + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); + + + + if (Directory.Exists(APKPath)) + Directory.Delete(APKPath, true); + + if (Directory.Exists(AndroidExportPath)) + Directory.Delete(AndroidExportPath, true); + + EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle; + EditorUserBuildSettings.exportAsGoogleAndroidProject = true; + + var playerOptions = new BuildPlayerOptions(); + playerOptions.scenes = GetEnabledScenes(); + playerOptions.target = BuildTarget.Android; + playerOptions.locationPathName = APKPath; + if (!isReleaseBuild) + { + // remove this line if you don't use a debugger and you want to speed up the flutter build + playerOptions.options = BuildOptions.AllowDebugging | BuildOptions.Development; + } +#if UNITY_6000_0_OR_NEWER + PlayerSettings.SetIl2CppCodeGeneration(NamedBuildTarget.Android, isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize); +#elif UNITY_2022_1_OR_NEWER + PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); +#elif UNITY_2021_2_OR_NEWER + PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); + EditorUserBuildSettings.il2CppCodeGeneration = isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize; +#endif + + // Switch to Android standalone build. + EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); + // build addressable + ExportAddressables(); + var report = BuildPipeline.BuildPlayer(playerOptions); + + if (report.summary.result != BuildResult.Succeeded) + throw new Exception("Build failed"); + + Copy(buildPath, AndroidExportPath); + + // Modify build.gradle + ModifyAndroidGradle(isPlugin); + + if (isPlugin) + { + SetupAndroidProjectForPlugin(); + } + else + { + SetupAndroidProject(); + } + + // Copy over resources from the launcher module that are used by the library, Avoid deleting the existing src/main/res contents. + Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"), false); + + if (isReleaseBuild) + { + Debug.Log($"-- Android Release Build: SUCCESSFUL --"); + } + else + { + Debug.Log($"-- Android Debug Build: SUCCESSFUL --"); + } + } + + private static void ModifyWebGLExport() + { + + var path = _overrideBuildPaths ? BuildPathsHelper.Overriden_WebExportPath : WebExportPath; + + // Modify index.html + var indexFile = Path.Combine(path, "index.html"); + var indexHtmlText = File.ReadAllText(indexFile); + + indexHtmlText = indexHtmlText.Replace("