增加steam
This commit is contained in:
76
Assets/Editor/RedistCopy.cs
Normal file
76
Assets/Editor/RedistCopy.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
// This file is provided under The MIT License as part of Steamworks.NET.
|
||||
// Copyright (c) 2013-2022 Riley Labrecque
|
||||
// Please see the included LICENSE.txt for additional information.
|
||||
|
||||
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
|
||||
#define DISABLESTEAMWORKS
|
||||
#endif
|
||||
|
||||
#if !DISABLESTEAMWORKS
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using System.IO;
|
||||
using Steamworks;
|
||||
|
||||
public class RedistCopy {
|
||||
[PostProcessBuild]
|
||||
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
|
||||
// We only want to do this on Steam supported platforms.
|
||||
if ((target != BuildTarget.StandaloneWindows) && (target != BuildTarget.StandaloneWindows64) && (target != BuildTarget.StandaloneLinux64)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CopyDebugInfo(target, pathToBuiltProject);
|
||||
|
||||
DeleteOldSteamApiDlls(target, pathToBuiltProject);
|
||||
}
|
||||
|
||||
static void CopyDebugInfo(BuildTarget target, string pathToBuiltProject) {
|
||||
string baseDir = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data");
|
||||
string pluginsDir = Path.Combine(baseDir, "Plugins");
|
||||
|
||||
// Create if it doesn't exist yet
|
||||
Directory.CreateDirectory(pluginsDir);
|
||||
|
||||
string[] DebugInfo = {
|
||||
"Steamworks.NET created by Riley Labrecque",
|
||||
"http://steamworks.github.io",
|
||||
"",
|
||||
"Steamworks.NET Version: " + Steamworks.Version.SteamworksNETVersion,
|
||||
"Steamworks SDK Version: " + Steamworks.Version.SteamworksSDKVersion,
|
||||
"Steam API DLL Version: " + Steamworks.Version.SteamAPIDLLVersion,
|
||||
"Steam API DLL Size: " + Steamworks.Version.SteamAPIDLLSize,
|
||||
"Steam API64 DLL Size: " + Steamworks.Version.SteamAPI64DLLSize,
|
||||
""
|
||||
};
|
||||
File.WriteAllLines(Path.Combine(pluginsDir, "Steamworks.NET.txt"), DebugInfo);
|
||||
}
|
||||
|
||||
static void DeleteOldSteamApiDlls(BuildTarget target, string pathToBuiltProject) {
|
||||
string strDllPath = Path.Combine(pathToBuiltProject, "steam_api.dll");
|
||||
if (File.Exists(strDllPath)) {
|
||||
try {
|
||||
File.Delete(strDllPath);
|
||||
}
|
||||
catch (System.Exception e) {
|
||||
Debug.LogWarning($"[Steamworks.NET] Attempted to delete an old copy of 'steam_api.dll' in the following location: '{strDllPath}', but could not due to the following exception:");
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
string strDll64Path = Path.Combine(pathToBuiltProject, "steam_api64.dll");
|
||||
if (File.Exists(strDll64Path)) {
|
||||
try {
|
||||
File.Delete(strDll64Path);
|
||||
}
|
||||
catch (System.Exception e) {
|
||||
Debug.LogWarning($"[Steamworks.NET] Attempted to delete an old copy of 'steam_api64.dll' in the following location: '{strDll64Path}', but could not due to the following exception:");
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !DISABLESTEAMWORKS
|
||||
11
Assets/Editor/RedistCopy.cs.meta
Normal file
11
Assets/Editor/RedistCopy.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96dd4cffb1a008c4e8d429c9f4186034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
Assets/Editor/RedistInstall.cs
Normal file
98
Assets/Editor/RedistInstall.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
// This file is provided under The MIT License as part of Steamworks.NET.
|
||||
// Copyright (c) 2013-2022 Riley Labrecque
|
||||
// Please see the included LICENSE.txt for additional information.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This copies various files into their required locations when Unity is launched to make installation a breeze.
|
||||
[InitializeOnLoad]
|
||||
public class RedistInstall {
|
||||
static RedistInstall() {
|
||||
// We only want to do this on Steam supported platforms.
|
||||
if (EditorUserBuildSettings.selectedBuildTargetGroup != BuildTargetGroup.Standalone) {
|
||||
return;
|
||||
}
|
||||
// Delay calls to fix compile issues with custom build profiles in Unity 6.00+
|
||||
EditorApplication.delayCall += () => {
|
||||
WriteSteamAppIdTxtFile();
|
||||
AddDefineSymbols();
|
||||
CheckForOldDlls();
|
||||
};
|
||||
}
|
||||
|
||||
static void WriteSteamAppIdTxtFile() {
|
||||
string strCWDPath = Directory.GetCurrentDirectory();
|
||||
string strSteamAppIdPath = Path.Combine(strCWDPath, "steam_appid.txt");
|
||||
|
||||
// If the steam_appid.txt file already exists, then there's nothing to do.
|
||||
if (File.Exists(strSteamAppIdPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("[Steamworks.NET] 'steam_appid.txt' is not present in the project root. Writing...");
|
||||
|
||||
try {
|
||||
StreamWriter appIdFile = File.CreateText(strSteamAppIdPath);
|
||||
appIdFile.Write("480");
|
||||
appIdFile.Close();
|
||||
|
||||
Debug.Log("[Steamworks.NET] Successfully copied 'steam_appid.txt' into the project root.");
|
||||
}
|
||||
catch (System.Exception e) {
|
||||
Debug.LogWarning("[Steamworks.NET] Could not copy 'steam_appid.txt' into the project root. Please place 'steam_appid.txt' into the project root manually.");
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckForOldDlls() {
|
||||
string strCwdPath = Directory.GetCurrentDirectory();
|
||||
|
||||
// Unfortunately we can't just delete these outright because Unity loads the dlls in the project root instantly and Windows won't let us delete them because they are in use.
|
||||
|
||||
string strDllPath = Path.Combine(strCwdPath, "steam_api.dll");
|
||||
if (File.Exists(strDllPath)) {
|
||||
Debug.LogError("[Steamworks.NET] Please delete the old version of 'steam_api.dll' in your project root before continuing.");
|
||||
}
|
||||
|
||||
string strDll64Path = Path.Combine(strCwdPath, "steam_api64.dll");
|
||||
if (File.Exists(strDll64Path)) {
|
||||
Debug.LogError("[Steamworks.NET] Please delete the old version of 'steam_api64.dll' in your project root before continuing.");
|
||||
}
|
||||
}
|
||||
|
||||
static void AddDefineSymbols()
|
||||
{
|
||||
if (!EditorSteamworksNETSettings.Instance.CanManageDefineSymbols)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string currentDefines;
|
||||
HashSet<string> defines;
|
||||
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
currentDefines = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup));
|
||||
#else
|
||||
currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
|
||||
#endif
|
||||
defines = new HashSet<string>(currentDefines.Split(';'))
|
||||
{
|
||||
"STEAMWORKS_NET"
|
||||
};
|
||||
|
||||
string newDefines = string.Join(";", defines);
|
||||
if (newDefines != currentDefines)
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), newDefines);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newDefines);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Editor/RedistInstall.cs.meta
Normal file
11
Assets/Editor/RedistInstall.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a716febd50f03244b98d9a5a0c6b36f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Editor/Settings.meta
Normal file
3
Assets/Editor/Settings.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f8184d59cc54b41bd59665c1741eb93
|
||||
timeCreated: 1749166917
|
||||
54
Assets/Editor/Settings/EditorSteamworksNETSettings.cs
Normal file
54
Assets/Editor/Settings/EditorSteamworksNETSettings.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 405a05810d3640bf97990d1db61805f8
|
||||
timeCreated: 1749167443
|
||||
90
Assets/Editor/Settings/EditorSteamworksNETSettingsElement.cs
Normal file
90
Assets/Editor/Settings/EditorSteamworksNETSettingsElement.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18f5fde747c54d00a38f482196793f28
|
||||
timeCreated: 1749167285
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 943edff1c475473296ce0569c182d86a
|
||||
timeCreated: 1749166940
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
18
Assets/Editor/com.rlabrecque.steamworks.net.editor.asmdef
Normal file
18
Assets/Editor/com.rlabrecque.steamworks.net.editor.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "com.rlabrecque.steamworks.net.editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:68bd7fdb68ef2684e982e8a9825b18a5"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be281b7992e9e1840851a78ba9db107c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user