diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index bafcd30b3..228a47856 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -108,6 +108,14 @@ int32 Engine::Main(const Char* cmdLine) Globals::StartupFolder = Globals::BinariesFolder = Platform::GetMainDirectory(); #if USE_EDITOR Globals::StartupFolder /= TEXT("../../../.."); +#if PLATFORM_MAC + if (Globals::BinariesFolder.EndsWith(TEXT(".app/Contents"))) + { + // If running editor from application package on macOS + Globals::StartupFolder = Globals::BinariesFolder; + Globals::BinariesFolder /= TEXT("MacOS"); + } +#endif #endif StringUtils::PathRemoveRelativeParts(Globals::StartupFolder); FileSystem::NormalizePath(Globals::BinariesFolder); @@ -125,7 +133,6 @@ int32 Engine::Main(const Char* cmdLine) } EngineImpl::InitPaths(); - EngineImpl::InitLog(); #if USE_EDITOR @@ -545,7 +552,8 @@ void EngineImpl::InitLog() LOG(Info, "Product: {0}, Company: {1}", Globals::ProductName, Globals::CompanyName); LOG(Info, "Current culture: {0}", Platform::GetUserLocaleName()); LOG(Info, "Command line: {0}", CommandLine); - LOG(Info, "Base directory: {0}", Globals::StartupFolder); + LOG(Info, "Base folder: {0}", Globals::StartupFolder); + LOG(Info, "Binaries folder: {0}", Globals::BinariesFolder); LOG(Info, "Temporary folder: {0}", Globals::TemporaryFolder); LOG(Info, "Project folder: {0}", Globals::ProjectFolder); #if USE_EDITOR diff --git a/Source/Platforms/Mac/Default.icns b/Source/Platforms/Mac/Default.icns new file mode 100644 index 000000000..455acd991 Binary files /dev/null and b/Source/Platforms/Mac/Default.icns differ diff --git a/Source/Platforms/Mac/Default.plist b/Source/Platforms/Mac/Default.plist new file mode 100644 index 000000000..3041bba71 --- /dev/null +++ b/Source/Platforms/Mac/Default.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIconFile + icon.icns + CFBundleExecutable + {Executable} + CFBundleName + FlaxEditor + CFBundleIdentifier + com.flaxengine.editor + CFBundlePackageType + APPL + CFBundleShortVersionString + {Version} + CFBundleVersion + {Version} + NSRequiresAquaSystemAppearance + + NSHumanReadableCopyright + {Copyright} + CFBundleSupportedPlatforms + + MacOSX + + NSPrincipalClass + NSApplication + LSApplicationCategoryType + public.app-category.developer-tools + LSMinimumSystemVersion + 10.15 + LSMinimumSystemVersionByArchitecture + + {Arch} + 10.15 + + NSHighResolutionCapable + + + diff --git a/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs b/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs index 981c15a55..91da6d83d 100644 --- a/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs +++ b/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Text; using Flax.Build; using Flax.Build.Platforms; @@ -126,6 +127,45 @@ namespace Flax.Deploy // Deploy project DeployFile(RootPath, OutputPath, "Flax.flaxproj"); + // Package Editor into macOS app + if (Platform.BuildTargetPlatform == TargetPlatform.Mac) + { + var arch = Platform.BuildTargetArchitecture; + Log.Info(string.Empty); + Log.Info("Creating macOS app..."); + var appPath = Path.Combine(Deployer.PackageOutputPath, "FlaxEditor.app"); + var appContentsPath = Path.Combine(appPath, "Contents"); + var appBinariesPath = Path.Combine(appContentsPath, "MacOS"); + Utilities.DirectoryDelete(appPath); + Directory.CreateDirectory(appPath); + Directory.CreateDirectory(appContentsPath); + Directory.CreateDirectory(appBinariesPath); + + // Copy icons set + Directory.CreateDirectory(Path.Combine(appContentsPath, "Resources")); + Utilities.FileCopy(Path.Combine(Globals.EngineRoot, "Source/Platforms/Mac/Default.icns"), Path.Combine(appContentsPath, "Resources/icon.icns")); + + // Create PkgInfo file + File.WriteAllText(Path.Combine(appContentsPath, "PkgInfo"), "APPL???", Encoding.ASCII); + + // Create Info.plist + var plist = File.ReadAllText(Path.Combine(Globals.EngineRoot, "Source/Platforms/Mac/Default.plist")); + var flaxProject = EngineTarget.EngineProject; + plist = plist.Replace("{Version}", flaxProject.Version.ToString()); + plist = plist.Replace("{Copyright}", flaxProject.Copyright); + plist = plist.Replace("{Executable}", "FlaxEditor"); + plist = plist.Replace("{Arch}", arch == TargetArchitecture.ARM64 ? "arm64" : "x86_64"); + File.WriteAllText(Path.Combine(appContentsPath, "Info.plist"), plist, Encoding.ASCII); + + // Copy output editor files + Utilities.DirectoryCopy(OutputPath, appContentsPath); + + // Copy native binaries for app execution + var defaultEditorConfig = "Development"; + var ediotrBinariesPath = Path.Combine(appContentsPath, "Binaries/Editor/Mac", defaultEditorConfig); + Utilities.DirectoryCopy(ediotrBinariesPath, appBinariesPath, true, true); + } + // Compress if (Configuration.DontCompress) return;