Dossier complet
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Packages.Rider.Editor.Debugger
|
||||
{
|
||||
[Flags]
|
||||
internal enum Il2CppDebugSupport
|
||||
{
|
||||
None = 0,
|
||||
PreserveUnityEngineDlls = 1 << 0,
|
||||
PreservePlayerDlls = 1 << 1,
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee862eedc8ac4c2390e20f0eb5f0c29c
|
||||
timeCreated: 1719584852
|
@@ -0,0 +1,53 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Packages.Rider.Editor.Debugger
|
||||
{
|
||||
internal class LinkXmlInstaller : IUnityLinkerProcessor
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public string GenerateAdditionalLinkXmlFile([CanBeNull] BuildReport report, UnityLinkerBuildPipelineData data)
|
||||
{
|
||||
if (!RiderScriptEditor.IsRiderOrFleetInstallation(RiderScriptEditor.CurrentEditor))
|
||||
return string.Empty;
|
||||
|
||||
if (!RiderDebuggerProvider.IsScriptDebuggingEnable(report))
|
||||
return string.Empty;
|
||||
if (!RiderDebuggerProvider.IsIl2CppScriptingBackend(report))
|
||||
return string.Empty;
|
||||
|
||||
var il2CppDebugSupport = RiderDebuggerProvider.Instance.Il2CppDebugSupport;
|
||||
|
||||
if (il2CppDebugSupport == Il2CppDebugSupport.None)
|
||||
return string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var preserveUnityEngineDlls = il2CppDebugSupport.HasFlag(Il2CppDebugSupport.PreserveUnityEngineDlls);
|
||||
var preservePlayerDlls = il2CppDebugSupport.HasFlag(Il2CppDebugSupport.PreservePlayerDlls);
|
||||
|
||||
var path = EditorPluginInterop.GenerateAdditionalLinkXmlFile(report, data, preserveUnityEngineDlls, preservePlayerDlls);
|
||||
return path;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
//Unity Editor 2019 IUnityLinkerProcessor interface methods
|
||||
public void OnBeforeRun(BuildReport report, UnityLinkerBuildPipelineData data) {}
|
||||
public void OnAfterRun(BuildReport report, UnityLinkerBuildPipelineData data) {}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4741b1b8a574355831b49dbd712d0f5
|
||||
timeCreated: 1719925759
|
@@ -0,0 +1,127 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Packages.Rider.Editor.Debugger
|
||||
{
|
||||
internal class RiderDebugLinkXmlProcessor : IUnityLinkerProcessor
|
||||
{
|
||||
public const string DebugLinkFileName = "debug_link";
|
||||
public int callbackOrder { get; }
|
||||
|
||||
public string GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data)
|
||||
{
|
||||
if (!RiderScriptEditor.IsRiderOrFleetInstallation(RiderScriptEditor.CurrentEditor))
|
||||
return string.Empty;
|
||||
|
||||
if (!RiderDebuggerProvider.IsScriptDebuggingEnable(report))
|
||||
return string.Empty;
|
||||
if (!RiderDebuggerProvider.IsIl2CppScriptingBackend(report))
|
||||
return string.Empty;
|
||||
|
||||
var debugLinkXmlPaths = FindLinkDebugXmlFilePaths();
|
||||
|
||||
if (debugLinkXmlPaths.Length == 0)
|
||||
return string.Empty;
|
||||
|
||||
if (debugLinkXmlPaths.Length == 1)
|
||||
return debugLinkXmlPaths[0];
|
||||
|
||||
//create a file in the random folder in the TEMP directory
|
||||
var filePath = Path.Combine(CreateRandomFolderInTempDirectory(), "linker.xml");
|
||||
|
||||
var linker = new XElement("linker");
|
||||
var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), linker);
|
||||
MergeXMLFiles(debugLinkXmlPaths, linker);
|
||||
doc.Save(filePath);
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private static string CreateRandomFolderInTempDirectory()
|
||||
{
|
||||
// Get the path of the Temp directory
|
||||
var tempPath = Path.GetTempPath();
|
||||
|
||||
// Generate a random folder name
|
||||
var randomFolderName = Path.GetRandomFileName();
|
||||
|
||||
// Combine the Temp path with the random folder name
|
||||
var randomFolderPath = Path.Combine(tempPath, randomFolderName);
|
||||
|
||||
// Create the random folder
|
||||
Directory.CreateDirectory(randomFolderPath);
|
||||
|
||||
return randomFolderPath;
|
||||
}
|
||||
|
||||
private static void MergeXMLFiles(string[] filePaths, XElement linker)
|
||||
{
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tempDoc = XDocument.Load(filePath);
|
||||
if (tempDoc.Root == null) continue;
|
||||
foreach (var node in tempDoc.Root.Nodes())
|
||||
linker.Add(node);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(filePath);
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] FindLinkDebugXmlFilePaths()
|
||||
{
|
||||
var projectPath = Path.GetDirectoryName(Application.dataPath);
|
||||
|
||||
var assetsPaths = AssetDatabase.FindAssets(DebugLinkFileName)
|
||||
.Select(AssetDatabase.GUIDToAssetPath)
|
||||
.Where(p => Path.GetExtension(p) == ".xml")
|
||||
.Select(p => Path.Combine(projectPath, p))
|
||||
.ToArray();
|
||||
|
||||
return assetsPaths;
|
||||
}
|
||||
|
||||
//Unity Editor 2019 IUnityLinkerProcessor interface methods
|
||||
public void OnBeforeRun(BuildReport report, UnityLinkerBuildPipelineData data)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterRun(BuildReport report, UnityLinkerBuildPipelineData data)
|
||||
{
|
||||
}
|
||||
|
||||
public static void GenerateTemplateDebugLinkXml()
|
||||
{
|
||||
var filePath =
|
||||
EditorUtility.SaveFilePanel($"Save {DebugLinkFileName}", Application.dataPath, DebugLinkFileName, "xml");
|
||||
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return;
|
||||
|
||||
var linker = new XElement("linker");
|
||||
var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), linker);
|
||||
linker.Add(new XComment($"Preserve Unity Engine assemblies"));
|
||||
linker.Add(new XElement("assembly", new XAttribute("fullname", "UnityEngine"),
|
||||
new XAttribute("preserve", "all")));
|
||||
linker.Add(new XElement("assembly", new XAttribute("fullname", "UnityEngine.CoreModule"),
|
||||
new XAttribute("preserve", "all")));
|
||||
linker.Add(new XComment($"Preserve users assemblies"));
|
||||
linker.Add(new XElement("assembly", new XAttribute("fullname", "Assembly-CSharp"),
|
||||
new XAttribute("preserve", "all")));
|
||||
doc.Save(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 104a984fa4a1472b98482aa76a97e242
|
||||
timeCreated: 1720709699
|
@@ -0,0 +1,92 @@
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
|
||||
namespace Packages.Rider.Editor.Debugger
|
||||
{
|
||||
internal class RiderDebuggerProvider
|
||||
{
|
||||
private const string UnityProjectIl2CPPDebugFlagSettingsName = "unity_project_il2cpp_debug_flag";
|
||||
private const string UnityProjectUseDebugLinkDuringTheBuild = "unity_project_use_debug_link_flag";
|
||||
private const int RequiredRiderVersion = 243;
|
||||
public const string RequiredRiderVersionName = "2024.3";
|
||||
|
||||
private Il2CppDebugSupport m_Il2CppDebugSupportFlag =
|
||||
(Il2CppDebugSupport)EditorPrefs.GetInt(UnityProjectIl2CPPDebugFlagSettingsName,
|
||||
(int)Il2CppDebugSupport.PreserveUnityEngineDlls);
|
||||
|
||||
private bool m_useDebugLinkDuringTheBuild = EditorPrefs.GetBool(UnityProjectUseDebugLinkDuringTheBuild, true);
|
||||
|
||||
private RiderDebuggerProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public static readonly RiderDebuggerProvider Instance = new RiderDebuggerProvider();
|
||||
|
||||
public Il2CppDebugSupport Il2CppDebugSupport
|
||||
{
|
||||
get => m_Il2CppDebugSupportFlag;
|
||||
private set
|
||||
{
|
||||
if (m_Il2CppDebugSupportFlag != value)
|
||||
{
|
||||
EditorPrefs.SetInt(UnityProjectIl2CPPDebugFlagSettingsName, (int)value);
|
||||
m_Il2CppDebugSupportFlag = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleIl2CppSupport(Il2CppDebugSupport preference)
|
||||
{
|
||||
if (Il2CppDebugSupport.HasFlag(preference))
|
||||
Il2CppDebugSupport ^= preference;
|
||||
else
|
||||
Il2CppDebugSupport |= preference;
|
||||
}
|
||||
|
||||
public bool UseDebugLinkDuringTheBuild
|
||||
{
|
||||
get => m_useDebugLinkDuringTheBuild;
|
||||
private set
|
||||
{
|
||||
EditorPrefs.SetBool(UnityProjectUseDebugLinkDuringTheBuild, value);
|
||||
m_useDebugLinkDuringTheBuild = value;
|
||||
}
|
||||
}
|
||||
public void ToggleUseDebugLinkDuringTheBuild(bool value)
|
||||
{
|
||||
if (UseDebugLinkDuringTheBuild != value)
|
||||
UseDebugLinkDuringTheBuild = value;
|
||||
}
|
||||
|
||||
public static bool IsIl2CppScriptingBackend([CanBeNull] BuildReport report)
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
var summaryPlatformGroup = NamedBuildTarget.FromBuildTargetGroup(report == null
|
||||
? EditorUserBuildSettings.selectedBuildTargetGroup
|
||||
: report.summary.platformGroup);
|
||||
#else
|
||||
var summaryPlatformGroup = report == null
|
||||
? EditorUserBuildSettings.selectedBuildTargetGroup
|
||||
: report.summary.platformGroup;
|
||||
#endif
|
||||
|
||||
return PlayerSettings.GetScriptingBackend(summaryPlatformGroup) == ScriptingImplementation.IL2CPP;
|
||||
|
||||
}
|
||||
|
||||
public static bool IsScriptDebuggingEnable([CanBeNull] BuildReport report)
|
||||
{
|
||||
if(report != null)
|
||||
return report.summary.options.HasFlag(BuildOptions.AllowDebugging);
|
||||
|
||||
return EditorUserBuildSettings.allowDebugging;
|
||||
}
|
||||
|
||||
public static bool IsSupportedRiderVersion()
|
||||
{
|
||||
return RiderScriptEditorData.instance != null && RiderScriptEditorData.instance.editorBuildNumber != null && RiderScriptEditorData.instance.editorBuildNumber.Major >= RequiredRiderVersion;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5ec9d26088842c69b1ac57f54d3582d
|
||||
timeCreated: 1719584860
|
Reference in New Issue
Block a user