Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions com.rlabrecque.steamworks.net/Editor/RedistInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ static void CheckForOldDlls() {

static void AddDefineSymbols()
{
if (!EditorSteamworksNETSettings.Instance.CanManageDefineSymbols)
{
return;
}

string currentDefines;
HashSet<string> defines;

Expand Down
3 changes: 3 additions & 0 deletions com.rlabrecque.steamworks.net/Editor/Settings.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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();
}
}
}

/// <summary>
/// The instance of the SteamworksNETSettings class.
/// </summary>
public static EditorSteamworksNETSettings Instance
{
get
{
var json = File.Exists(FilePath) ? File.ReadAllText(FilePath) : "{}";
var settings = CreateInstance<EditorSteamworksNETSettings>();
JsonUtility.FromJsonOverwrite(json, settings);
return settings;
}
}

private void Save()
{
var jsonToSave = JsonUtility.ToJson(this, true);
File.WriteAllText(FilePath, jsonToSave);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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<StyleSheet>(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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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<string> keywords = null)
: base(SettingsPath, scopes, keywords)
{
}

public override void OnActivate(string searchContext, VisualElement rootElement)
{
base.OnActivate(searchContext, rootElement);
rootElement.Add(new EditorSteamworksNETSettingsElement());
}

/// <summary>
/// Method which adds your settings provider to ProjectSettings
/// </summary>
/// <returns>A <see cref="EditorSteamworksNETSettingsProvider"/>.</returns>
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
return new EditorSteamworksNETSettingsProvider(SettingsScope.Project);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.