diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkEditorCommandUpdater.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkEditorCommandUpdater.cs index 1b27e69c..2f6d8882 100644 --- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkEditorCommandUpdater.cs +++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkEditorCommandUpdater.cs @@ -11,10 +11,10 @@ internal sealed class LDtkEditorCommandUpdater { public string ProjectPath; public string ProjectName; - + public string ExePath; public string Arg; - + public string Command; public LDtkEditorCommandUpdater(string projectPath) @@ -24,8 +24,8 @@ public LDtkEditorCommandUpdater(string projectPath) ExePath = GetExecutablePath(); Arg = $"\\\"{ProjectName}\\\""; Command += $"{ExePath} \"{ProjectName}\""; - -#if UNITY_EDITOR_OSX + +#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX Command += $" $1"; #endif } @@ -33,26 +33,27 @@ public LDtkEditorCommandUpdater(string projectPath) private string GetExecutablePath() { string fromPath = LDtkPathUtility.AssetsPathToAbsolutePath(ProjectPath); - - + + //if mac/Linux, we're launching a different file that's meant to launch the exe #if UNITY_EDITOR_OSX - //if mac, we're launching a different file that's meant to launch the exe string appPath = LDtkTilesetExporterUtil.PathToMacSh(); +#elif UNITY_EDITOR_LINUX + string appPath = LDtkTilesetExporterUtil.PathToLinuxSh(); #else string appPath = LDtkTilesetExporterUtil.PathToExe(); #endif - + var commandContent = LDtkPathUtility.GetRelativePath(fromPath, appPath); //backslashes break deserialization commandContent = LDtkPathUtility.CleanPathSlashes(commandContent); - + //Debug.Log($"fromPath {fromPath}"); //Debug.Log($"appPath {appPath}"); //Debug.Log($"relPath {relPath}"); - + return commandContent; } - + public void TryDrawFixButton(LdtkJson data) { //if it defined no tileset defs, it's fine @@ -60,14 +61,14 @@ public void TryDrawFixButton(LdtkJson data) { return; } - + if (!IsInstalled(out var installReason)) { using (new EditorGUILayout.HorizontalScope()) { EditorGUIUtility.SetIconSize(Vector2.one * 32); EditorGUILayout.HelpBox($"The importer requires an app installed to the Library folder. This is a one time process.\nReason: {installReason}", MessageType.Error); - + EditorGUIUtility.SetIconSize(new Vector2(16, 16)); GUIContent installContent = new GUIContent() { @@ -90,17 +91,17 @@ public void TryDrawFixButton(LdtkJson data) LDtkEditorGUIUtility.DrawDivider(); return; } - + if (HasCustomCommand(data, out var reason)) { return; } - + using (new EditorGUILayout.HorizontalScope()) { EditorGUIUtility.SetIconSize(Vector2.one * 32); EditorGUILayout.HelpBox($"This project needs a command that should run this after saving:\n{Command}\nReason: {reason}", MessageType.Error); - + using (new EditorGUILayout.VerticalScope(GUILayout.Width(50))) { EditorGUIUtility.SetIconSize(new Vector2(16, 14)); @@ -143,7 +144,7 @@ public void TryDrawFixButton(LdtkJson data) GUIUtility.ExitGUI(); } - + EditorGUIUtility.SetIconSize(new Vector2(11, 13)); GUIContent copyContent = new GUIContent() { @@ -156,7 +157,7 @@ public void TryDrawFixButton(LdtkJson data) } } } - + EditorGUILayout.Space(); LDtkEditorGUIUtility.DrawDivider(); } @@ -181,17 +182,17 @@ bool IsBlockedFromAddingCommand() { return false; } - - int result = EditorUtility.DisplayDialogComplex(ProjectName, - "Didn't add command.\n" + - "Close all LDtk processes, and try again.\n" + - "\n" + "Alternatively, you may add the command manually:\n" + - "- Copy the path to the clipboard\n" + - "- Go to LDtk's project settings\n" + - "- Create a new command\n" + - "- Set the timing to \"Run after saving\"\n" + - "- Paste the following path from your clipboard:\n" + - $"\"{Command}\"\n", + + int result = EditorUtility.DisplayDialogComplex(ProjectName, + "Didn't add command.\n" + + "Close all LDtk processes, and try again.\n" + + "\n" + "Alternatively, you may add the command manually:\n" + + "- Copy the path to the clipboard\n" + + "- Go to LDtk's project settings\n" + + "- Create a new command\n" + + "- Set the timing to \"Run after saving\"\n" + + "- Paste the following path from your clipboard:\n" + + $"\"{Command}\"\n", "Try Again", "Close", "Copy to Clipboard"); switch (result) { @@ -205,7 +206,7 @@ bool IsBlockedFromAddingCommand() } } } - + if (ModifyProjectWithCommand(ProjectPath, ExePath, Arg)) { EditorUtility.DisplayDialog("Modified", $"Modified\n\"{ProjectName}\"\nwith the custom command.\nNow open the project and save!", "Ok"); @@ -223,11 +224,11 @@ public static bool ModifyProjectWithCommand(string projectPath, string exeRelPat { return false; } - + const string before = @"""customCommands"": [],"; const string after = @"""customCommands"": [{ ""command"": ""_PATH"", ""when"": ""AfterSave"" }],"; string insert = after.Replace("_PATH", $"{exeRelPath} {arg}"); - + string[] lines = File.ReadAllLines(projectPath); bool found = false; for (int i = 0; i < lines.Length; i++) @@ -257,7 +258,7 @@ public bool IsInstalled(out string reason) reason = $"The app's version ({old}) does not match the required one ({required})"; return false; } - + reason = null; return true; } @@ -265,17 +266,17 @@ public bool IsInstalled(out string reason) reason = $"The app doesn't exist"; return false; } - + public bool HasCustomCommand(LdtkJson data, out string reason) { LdtkCustomCommand[] commands = data.CustomCommands; - + if (commands == null) { reason = "customCommands was null. Old LDtk version?"; return false; } - + foreach (LdtkCustomCommand command in commands) { if (command.Command == Command) @@ -285,13 +286,13 @@ public bool HasCustomCommand(LdtkJson data, out string reason) reason = "The command exists, but the timing is not set to \"Run after saving\""; return false; } - + //ensure that there is a 2nd arg. string[] split = Regex.Matches(command.Command, @"[\""].+?[\""]|[^ ]+") .Cast() .Select(m => m.Value) .ToArray(); - + if (split.Length != 2 || split[1] != $"\"{ProjectName}\"") { reason = $"The command exists, but doesn't have a single parameter of the project name." + diff --git a/Assets/LDtkUnity/Editor/Utility/LDtkTilesetExporterUtility.cs b/Assets/LDtkUnity/Editor/Utility/LDtkTilesetExporterUtility.cs index 769239aa..a99a4903 100644 --- a/Assets/LDtkUnity/Editor/Utility/LDtkTilesetExporterUtility.cs +++ b/Assets/LDtkUnity/Editor/Utility/LDtkTilesetExporterUtility.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using UnityEditor; using UnityEngine; using Debug = UnityEngine.Debug; @@ -11,40 +12,49 @@ internal static class LDtkTilesetExporterUtil private const string EXPORT_ZIP = "LDtkTilesetExporter.zip"; private const string EXPORT_APP = "ExportTilesetDefinition.exe"; private const string MAC_APP = "ExportTilesetDefinitionMac.sh"; + private const string LINUX_APP = "ExportTilesetDefinitionLinux.sh"; //[MenuItem("UnzipToProject/Unzip")] public static void UnzipToLibrary() { string pathToZip = PathToZip(); string destDir = PathToLibraryDir(); - + LDtkPathUtility.TryCreateDirectory(destDir); if (Directory.Exists(destDir)) { DirectoryInfo di = new DirectoryInfo(destDir); foreach (FileInfo file in di.GetFiles()) { - file.Delete(); + file.Delete(); } } Debug.Assert(File.Exists(pathToZip), "File.Exists(pathToZip)"); Debug.Assert(Directory.Exists(destDir), "Directory.Exists(destDir)"); - + ZipUtil.Extract(pathToZip, destDir); - -#if UNITY_EDITOR_OSX + +#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX string pathToExe = PathToExe(); - //if mac, we need to create a shell script to run the exe + //if mac/Linux, we need to create a shell script to run the exe +#if UNITY_EDITOR_OSX string shPath = Path.Combine(destDir, MAC_APP); string shContent = $"#!/bin/sh\n /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono {pathToExe} $1"; +#elif UNITY_EDITOR_LINUX + string shPath = Path.Combine(destDir, LINUX_APP); + var unityPath = Path.GetDirectoryName(EditorApplication.applicationPath); + var monoPath = Path.Combine(unityPath, "Data", "MonoBleedingEdge", "bin", "mono"); + string shContent = $"#!/bin/sh\n {monoPath} {pathToExe} $1"; +#endif + File.WriteAllText(shPath, shContent); - - //on mac, the app needs some permission. Use "sudo chmod +x" + + //on mac/Linux, the app needs some permission. Use "sudo chmod +x" Process.Start("/bin/bash", $"-c \" chmod +x {shPath}\" "); #endif - + LDtkDebug.Log($"Extracted the tileset export app to \"{destDir}\""); } @@ -53,13 +63,13 @@ private static void CheckAppVersion() { Debug.Log($"app version up to date? {GetAppUpToDate()}"); } - + //[MenuItem("UnzipToProject/LogPathToExe")] public static void LogPathToExe() { Debug.Log(PathToExe()); }*/ - + public static string PathToLibraryDir() { string destDir = Application.dataPath; @@ -67,12 +77,12 @@ public static string PathToLibraryDir() destDir = Path.GetFullPath(destDir); return destDir; } - + public static string PathToZip() { string packagePath = Path.Combine(LDtkInternalUtility.ASSETS, EXPORT_ZIP); if (File.Exists(packagePath)) return packagePath; - + string assetsPath = Path.Combine(LDtkInternalUtility.PACKAGES, EXPORT_ZIP); if (File.Exists(assetsPath)) return assetsPath; @@ -88,7 +98,13 @@ public static string PathToMacSh() string exePath = Path.Combine(PathToLibraryDir(), MAC_APP); return exePath; } - + + public static string PathToLinuxSh() + { + string exePath = Path.Combine(PathToLibraryDir(), LINUX_APP); + return exePath; + } + public static bool GetAppUpToDate(out Version version, out Version requiredVersion) { FileVersionInfo info = FileVersionInfo.GetVersionInfo(PathToExe()); diff --git a/Packages/manifest.json b/Packages/manifest.json index 193d5420..393dd3d4 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -8,6 +8,7 @@ "com.unity.ide.visualstudio": "2.0.22", "com.unity.test-framework": "1.4.4", "com.unity.testtools.codecoverage": "1.2.5", + "com.unity.toolchain.linux-x86_64": "2.0.9", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 0aa02e73..938160a2 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -30,7 +30,7 @@ } }, "com.unity.ext.nunit": { - "version": "2.0.5", + "version": "2.0.3", "depth": 1, "source": "registry", "dependencies": {}, @@ -61,6 +61,22 @@ "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.sysroot": { + "version": "2.0.10", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.sysroot.linux-x86_64": { + "version": "2.0.9", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.sysroot": "2.0.10" + }, + "url": "https://packages.unity.com" + }, "com.unity.test-framework": { "version": "1.4.4", "depth": 0, @@ -82,6 +98,16 @@ }, "url": "https://packages.unity.com" }, + "com.unity.toolchain.linux-x86_64": { + "version": "2.0.9", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.sysroot": "2.0.10", + "com.unity.sysroot.linux-x86_64": "2.0.9" + }, + "url": "https://packages.unity.com" + }, "com.unity.modules.ai": { "version": "1.0.0", "depth": 0, @@ -129,12 +155,6 @@ "com.unity.modules.animation": "1.0.0" } }, - "com.unity.modules.hierarchycore": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", - "dependencies": {} - }, "com.unity.modules.imageconversion": { "version": "1.0.0", "depth": 0, @@ -223,8 +243,7 @@ "dependencies": { "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.hierarchycore": "1.0.0" + "com.unity.modules.jsonserialize": "1.0.0" } }, "com.unity.modules.umbra": {