diff --git a/com.rlabrecque.steamworks.net/Editor/RedistInstall.cs b/com.rlabrecque.steamworks.net/Editor/RedistInstall.cs index c86300a5..90659801 100644 --- a/com.rlabrecque.steamworks.net/Editor/RedistInstall.cs +++ b/com.rlabrecque.steamworks.net/Editor/RedistInstall.cs @@ -66,6 +66,11 @@ static void CheckForOldDlls() { static void AddDefineSymbols() { + if (!EditorSteamworksNETSettings.Instance.CanManageDefineSymbols) + { + return; + } + string currentDefines; HashSet defines; diff --git a/com.rlabrecque.steamworks.net/Editor/Settings.meta b/com.rlabrecque.steamworks.net/Editor/Settings.meta new file mode 100644 index 00000000..583fa2d8 --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1f8184d59cc54b41bd59665c1741eb93 +timeCreated: 1749166917 \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs new file mode 100644 index 00000000..12f819c2 --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs @@ -0,0 +1,54 @@ +using System.IO; +using UnityEditor.Compilation; +using UnityEngine; + +public sealed class EditorSteamworksNETSettings : ScriptableObject +{ + private const string FilePath = "ProjectSettings/SteamworksNETSettings.json"; + + [Tooltip("When enabled, the Steamworks.NET package will add the necessary define symbols to your project.")] + [SerializeField] + private bool canManageDefineSymbols = true; + + public bool CanManageDefineSymbols + { + get => canManageDefineSymbols; + + set + { + if (canManageDefineSymbols == value) + { + return; + } + + canManageDefineSymbols = value; + Save(); + + if (canManageDefineSymbols) + { + // Reload domain to ensure that define symbols are applied correctly. + CompilationPipeline.RequestScriptCompilation(); + } + } + } + + /// + /// The instance of the SteamworksNETSettings class. + /// + public static EditorSteamworksNETSettings Instance + { + get + { + var json = File.Exists(FilePath) ? File.ReadAllText(FilePath) : "{}"; + var settings = CreateInstance(); + JsonUtility.FromJsonOverwrite(json, settings); + return settings; + } + } + + private void Save() + { + var jsonToSave = JsonUtility.ToJson(this, true); + File.WriteAllText(FilePath, jsonToSave); + } +} \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs.meta b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs.meta new file mode 100644 index 00000000..f617486e --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 405a05810d3640bf97990d1db61805f8 +timeCreated: 1749167443 \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs new file mode 100644 index 00000000..92afff7a --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs @@ -0,0 +1,90 @@ +using System.IO; +using UnityEditor; +using UnityEngine.UIElements; + +public sealed class EditorSteamworksNETSettingsElement : VisualElement +{ + private readonly EditorSteamworksNETSettings _settings; + + private const string UssFilePath = + "Packages/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss"; + + public EditorSteamworksNETSettingsElement() + { + _settings = EditorSteamworksNETSettings.Instance; + var styleSheet = AssetDatabase.LoadAssetAtPath(UssFilePath); + + if (styleSheet) + { + styleSheets.Add(styleSheet); + } + else + { + throw new FileNotFoundException($"File not found: {UssFilePath}"); + } + + var root = new VisualElement(); + root.Add(CreateWindowTitleBar()); + root.Add(CreateDefineSymbolsSection()); + Add(root); + } + + private static VisualElement CreateWindowTitleBar() + { + var titleBar = new VisualElement(); + titleBar.AddToClassList("project-settings-title-bar"); + + var title = new Label { text = "Steamworks.NET Settings" }; + title.AddToClassList("project-settings-title-bar__label"); + + titleBar.Add(title); + return titleBar; + } + + private VisualElement CreateDefineSymbolsSection() + { + var toggleField = new Toggle("Can Manage the Define Symbols") + { + tooltip = "Set to true to allow Steamworks.NET to add define symbols in your project." + }; + + toggleField.SetValueWithoutNotify(_settings.CanManageDefineSymbols); + toggleField.RegisterValueChangedCallback(e => { _settings.CanManageDefineSymbols = e.newValue; }); + + const string Title = "Define Symbols"; + + const string Description = + "The Steamworks.NET package makes use of define symbols to enable or disable certain features. " + + "With this setting you can choose to let the package add these define symbols automatically or not.\n" + + "The default value is true."; + + return CreateSection(title: Title, description: Description, content: toggleField); + } + + private static VisualElement CreateSection(string title, string description, VisualElement content) + { + var section = new VisualElement { name = "Section" }; + section.AddToClassList("steamworks-section"); + + var sectionHeader = new Label { text = title }; + sectionHeader.AddToClassList("steamworks-section__header"); + + var helpBox = new HelpBox(); + helpBox.AddToClassList("steamworks-section__description"); + var helpBoxIcon = new VisualElement(); + helpBoxIcon.AddToClassList("unity-help-box__icon"); + helpBoxIcon.AddToClassList("unity-help-box__icon--info"); + var helpBoxLabel = new Label { text = description }; + helpBoxLabel.AddToClassList("unity-help-box__label"); + helpBox.Add(helpBoxIcon); + helpBox.Add(helpBoxLabel); + + content.AddToClassList("steamworks-section__content"); + + section.Add(sectionHeader); + section.Add(helpBox); + section.Add(content); + + return section; + } +} \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs.meta b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs.meta new file mode 100644 index 00000000..c1ceb99a --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsElement.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 18f5fde747c54d00a38f482196793f28 +timeCreated: 1749167285 \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs new file mode 100644 index 00000000..0385f6dc --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine.UIElements; + +public sealed class EditorSteamworksNETSettingsProvider : SettingsProvider +{ + private const string SettingsPath = "Project/Steamworks.NET"; + + private EditorSteamworksNETSettingsProvider(SettingsScope scopes, IEnumerable keywords = null) + : base(SettingsPath, scopes, keywords) + { + } + + public override void OnActivate(string searchContext, VisualElement rootElement) + { + base.OnActivate(searchContext, rootElement); + rootElement.Add(new EditorSteamworksNETSettingsElement()); + } + + /// + /// Method which adds your settings provider to ProjectSettings + /// + /// A . + [SettingsProvider] + public static SettingsProvider CreateSettingsProvider() + { + return new EditorSteamworksNETSettingsProvider(SettingsScope.Project); + } +} \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs.meta b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs.meta new file mode 100644 index 00000000..179d64d3 --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsProvider.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 943edff1c475473296ce0569c182d86a +timeCreated: 1749166940 \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss new file mode 100644 index 00000000..7adb8077 --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss @@ -0,0 +1,22 @@ +.steamworks-section { + background-color: #424242; + border-color: #191919; + border-width: 1px; + padding: 5px; + margin: 5px; +} + +.steamworks-section__header { + font-size: 16px; + -unity-font-style: bold; + margin-bottom: 5px; +} + +.steamworks-section__description { + margin-bottom: 5px; +} + +.steamworks-section__content { + margin-left: 10px; + margin-bottom: 5px; +} \ No newline at end of file diff --git a/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss.meta b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss.meta new file mode 100644 index 00000000..46b63e02 --- /dev/null +++ b/com.rlabrecque.steamworks.net/Editor/Settings/EditorSteamworksNETSettingsStyleSheet.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcba6a16ac8056e418e5f791a8bbb67c +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0