From 3b65aec32f63a4418ce64be3c9e58f2bff359db5 Mon Sep 17 00:00:00 2001 From: huantian Date: Wed, 22 Jun 2022 12:55:12 -0700 Subject: [PATCH] Convert Starpelly.OS.Windows to be platform agnostic. (#106) --- .gitignore | 3 +++ Assets/Plugins/Starpelly/OS.cs | 23 +++++++++++++++++++ Assets/Plugins/Starpelly/OS.cs.meta | 3 +++ Assets/Plugins/Starpelly/OperatingSystem.meta | 3 +++ .../OperatingSystem/IOperatingSystem.cs | 7 ++++++ .../OperatingSystem/IOperatingSystem.cs.meta | 3 +++ .../Starpelly/OperatingSystem/Linux.cs | 16 +++++++++++++ .../Starpelly/OperatingSystem/Linux.cs.meta | 3 +++ .../Starpelly/OperatingSystem/MacOS.cs | 10 ++++++++ .../Starpelly/OperatingSystem/MacOS.cs.meta | 3 +++ .../Starpelly/{ => OperatingSystem}/User32.cs | 6 +++-- .../{ => OperatingSystem}/User32.cs.meta | 0 .../Windows.cs | 10 ++++---- .../Windows.cs.meta | 0 .../Plugins/Starpelly/OperatingSystems.meta | 8 ------- Assets/Scripts/GlobalGameManager.cs | 4 ++-- Packages/manifest.json | 6 ++--- Packages/packages-lock.json | 8 +++---- 18 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 Assets/Plugins/Starpelly/OS.cs create mode 100644 Assets/Plugins/Starpelly/OS.cs.meta create mode 100644 Assets/Plugins/Starpelly/OperatingSystem.meta create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs.meta create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/Linux.cs create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/Linux.cs.meta create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs create mode 100644 Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs.meta rename Assets/Plugins/Starpelly/{ => OperatingSystem}/User32.cs (95%) rename Assets/Plugins/Starpelly/{ => OperatingSystem}/User32.cs.meta (100%) rename Assets/Plugins/Starpelly/{OperatingSystems => OperatingSystem}/Windows.cs (96%) rename Assets/Plugins/Starpelly/{OperatingSystems => OperatingSystem}/Windows.cs.meta (100%) delete mode 100644 Assets/Plugins/Starpelly/OperatingSystems.meta diff --git a/.gitignore b/.gitignore index 31402627..c77ae4c5 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,6 @@ crashlytics-build.properties # Visual Studio Code /.vscode/ + +# Rider +.idea/ diff --git a/Assets/Plugins/Starpelly/OS.cs b/Assets/Plugins/Starpelly/OS.cs new file mode 100644 index 00000000..a336e597 --- /dev/null +++ b/Assets/Plugins/Starpelly/OS.cs @@ -0,0 +1,23 @@ +namespace Starpelly +{ + public static class OS + { + private static readonly OperatingSystem.IOperatingSystem _os; + + static OS() + { +#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + _os = new OperatingSystem.Windows(); +#elif UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX + _os = new OperatingSystem.Linux(); +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX + _os = new OperatingSystem.MacOS(); +#endif + } + + public static void ChangeWindowTitle(string newTitle) + { + _os.ChangeWindowTitle(newTitle); + } + } +} diff --git a/Assets/Plugins/Starpelly/OS.cs.meta b/Assets/Plugins/Starpelly/OS.cs.meta new file mode 100644 index 00000000..3c948c91 --- /dev/null +++ b/Assets/Plugins/Starpelly/OS.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 36edcede4a1a4ef9bb0902354c3be0d1 +timeCreated: 1655775758 \ No newline at end of file diff --git a/Assets/Plugins/Starpelly/OperatingSystem.meta b/Assets/Plugins/Starpelly/OperatingSystem.meta new file mode 100644 index 00000000..3bb2626e --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7b17a1aeeb0f43bb805dc7ac03408ebb +timeCreated: 1655775758 \ No newline at end of file diff --git a/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs b/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs new file mode 100644 index 00000000..f7180f8a --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs @@ -0,0 +1,7 @@ +namespace Starpelly.OperatingSystem +{ + public interface IOperatingSystem + { + public void ChangeWindowTitle(string newTitle); + } +} diff --git a/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs.meta b/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs.meta new file mode 100644 index 00000000..58e8fa7d --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/IOperatingSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8bb82376a44e4330b6398deddb17d282 +timeCreated: 1655775758 \ No newline at end of file diff --git a/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs b/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs new file mode 100644 index 00000000..7cd68af5 --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs @@ -0,0 +1,16 @@ +#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX +using System.Diagnostics; + +namespace Starpelly.OperatingSystem +{ + public class Linux : IOperatingSystem + { + public void ChangeWindowTitle(string newTitle) + { + var pid = Process.GetCurrentProcess().Id; + var args = $"search --all --pid {pid} --class '.' set_window --name \"{newTitle}\""; + Process.Start("xdotool", args); + } + } +} +#endif diff --git a/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs.meta b/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs.meta new file mode 100644 index 00000000..e5ebf2b8 --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/Linux.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9e5d25ae0c3e4256abae4d2e07f7e14b +timeCreated: 1655775758 \ No newline at end of file diff --git a/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs b/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs new file mode 100644 index 00000000..f752ea67 --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs @@ -0,0 +1,10 @@ +namespace Starpelly.OperatingSystem +{ + public class MacOS : IOperatingSystem + { + public void ChangeWindowTitle(string newTitle) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs.meta b/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs.meta new file mode 100644 index 00000000..ec5f65ad --- /dev/null +++ b/Assets/Plugins/Starpelly/OperatingSystem/MacOS.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cfc6152d5db74f568b229047970f7889 +timeCreated: 1655775758 \ No newline at end of file diff --git a/Assets/Plugins/Starpelly/User32.cs b/Assets/Plugins/Starpelly/OperatingSystem/User32.cs similarity index 95% rename from Assets/Plugins/Starpelly/User32.cs rename to Assets/Plugins/Starpelly/OperatingSystem/User32.cs index 378305f0..aff18792 100644 --- a/Assets/Plugins/Starpelly/User32.cs +++ b/Assets/Plugins/Starpelly/OperatingSystem/User32.cs @@ -1,3 +1,4 @@ +#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN using System; using System.Runtime.InteropServices; using System.Text; @@ -5,7 +6,7 @@ using System.Text; using Starpelly.Common; using Starpelly.Enums.Windows; -namespace Starpelly.OS +namespace Starpelly.OperatingSystem { public class User32 { @@ -53,4 +54,5 @@ namespace Starpelly.OS public static extern IntPtr GetForegroundWindow(); #endregion } -} \ No newline at end of file +} +#endif diff --git a/Assets/Plugins/Starpelly/User32.cs.meta b/Assets/Plugins/Starpelly/OperatingSystem/User32.cs.meta similarity index 100% rename from Assets/Plugins/Starpelly/User32.cs.meta rename to Assets/Plugins/Starpelly/OperatingSystem/User32.cs.meta diff --git a/Assets/Plugins/Starpelly/OperatingSystems/Windows.cs b/Assets/Plugins/Starpelly/OperatingSystem/Windows.cs similarity index 96% rename from Assets/Plugins/Starpelly/OperatingSystems/Windows.cs rename to Assets/Plugins/Starpelly/OperatingSystem/Windows.cs index 68039f5d..715f6451 100644 --- a/Assets/Plugins/Starpelly/OperatingSystems/Windows.cs +++ b/Assets/Plugins/Starpelly/OperatingSystem/Windows.cs @@ -1,12 +1,13 @@ +#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN using System; using System.Runtime.InteropServices; using Starpelly.Enums.Windows; using System.Text; -namespace Starpelly.OS +namespace Starpelly.OperatingSystem { - public class Windows + public class Windows : IOperatingSystem { /// /// Gets the current title of the game window. @@ -29,7 +30,7 @@ namespace Starpelly.OS /// Changes the game's window title. /// /// The title the window will be changed to. - public static void ChangeWindowTitle(string newTitle) + public void ChangeWindowTitle(string newTitle) { var windowPtr = User32.FindWindow(null, GetActiveWindowTitle()); User32.SetWindowText(windowPtr, newTitle); @@ -136,4 +137,5 @@ namespace Starpelly.OS #endregion } -} \ No newline at end of file +} +#endif diff --git a/Assets/Plugins/Starpelly/OperatingSystems/Windows.cs.meta b/Assets/Plugins/Starpelly/OperatingSystem/Windows.cs.meta similarity index 100% rename from Assets/Plugins/Starpelly/OperatingSystems/Windows.cs.meta rename to Assets/Plugins/Starpelly/OperatingSystem/Windows.cs.meta diff --git a/Assets/Plugins/Starpelly/OperatingSystems.meta b/Assets/Plugins/Starpelly/OperatingSystems.meta deleted file mode 100644 index 2f6eae38..00000000 --- a/Assets/Plugins/Starpelly/OperatingSystems.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 24f2fe0d29590e64bbf4bc9d4f230b9f -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/GlobalGameManager.cs b/Assets/Scripts/GlobalGameManager.cs index dad42f57..9f2e90a8 100644 --- a/Assets/Scripts/GlobalGameManager.cs +++ b/Assets/Scripts/GlobalGameManager.cs @@ -49,7 +49,7 @@ namespace HeavenStudio Init(); DontDestroyOnLoad(this.gameObject); instance = this; - Starpelly.OS.Windows.ChangeWindowTitle($"Heaven Studio DEMO"); + Starpelly.OS.ChangeWindowTitle("Heaven Studio DEMO"); } public static GameObject CreateFade() @@ -99,4 +99,4 @@ namespace HeavenStudio } } -} \ No newline at end of file +} diff --git a/Packages/manifest.json b/Packages/manifest.json index 9bd9f495..baa43090 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,9 +3,9 @@ "com.unity.2d.sprite": "1.0.0", "com.unity.assetbundlebrowser": "https://github.com/Unity-Technologies/AssetBundles-Browser.git", "com.unity.collab-proxy": "1.15.4", - "com.unity.ide.rider": "2.0.7", - "com.unity.ide.visualstudio": "2.0.12", - "com.unity.ide.vscode": "1.2.4", + "com.unity.ide.rider": "3.0.14", + "com.unity.ide.visualstudio": "2.0.15", + "com.unity.ide.vscode": "1.2.5", "com.unity.nuget.newtonsoft-json": "2.0.2", "com.unity.postprocessing": "3.2.1", "com.unity.test-framework": "1.1.29", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 273b443b..630a9002 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -31,16 +31,16 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "2.0.7", + "version": "3.0.14", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.1" + "com.unity.ext.nunit": "1.0.6" }, "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.12", + "version": "2.0.15", "depth": 0, "source": "registry", "dependencies": { @@ -49,7 +49,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.vscode": { - "version": "1.2.4", + "version": "1.2.5", "depth": 0, "source": "registry", "dependencies": {},