增加steam

This commit is contained in:
yaoyanwei
2025-08-11 15:00:21 +08:00
parent 8fda4168b3
commit 65ee6c6eeb
288 changed files with 34032 additions and 27 deletions

View File

@@ -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);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 405a05810d3640bf97990d1db61805f8
timeCreated: 1749167443

View File

@@ -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;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 18f5fde747c54d00a38f482196793f28
timeCreated: 1749167285

View File

@@ -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);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 943edff1c475473296ce0569c182d86a
timeCreated: 1749166940

View File

@@ -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;
}

View File

@@ -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