Dossier complet

This commit is contained in:
2025-01-17 13:04:56 +01:00
commit 649efce666
15116 changed files with 970754 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1b393f6b29a9ee84c803af1ab4944b71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 78ec63f042464a0a93f0b63298957e93
timeCreated: 1719583187

View File

@@ -0,0 +1,12 @@
using System;
namespace Packages.Rider.Editor.Debugger
{
[Flags]
internal enum Il2CppDebugSupport
{
None = 0,
PreserveUnityEngineDlls = 1 << 0,
PreservePlayerDlls = 1 << 1,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ee862eedc8ac4c2390e20f0eb5f0c29c
timeCreated: 1719584852

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f4741b1b8a574355831b49dbd712d0f5
timeCreated: 1719925759

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 104a984fa4a1472b98482aa76a97e242
timeCreated: 1720709699

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e5ec9d26088842c69b1ac57f54d3582d
timeCreated: 1719584860

View File

@@ -0,0 +1,111 @@
using System;
using System.Linq;
using JetBrains.Rider.PathLocator;
using Packages.Rider.Editor.Util;
using Unity.CodeEditor;
namespace Packages.Rider.Editor
{
internal interface IDiscovery
{
CodeEditor.Installation[] PathCallback();
}
internal class Discovery : IDiscovery
{
public static readonly RiderPathLocator RiderPathLocator;
public static readonly RiderFileOpener RiderFileOpener;
static Discovery()
{
var env = new RiderLocatorEnvironment();
RiderPathLocator = new RiderPathLocator(env);
RiderFileOpener = new RiderFileOpener(env);
}
public CodeEditor.Installation[] PathCallback()
{
// still we want to search for installations, when Preferences is opened
var res = RiderPathLocator.GetAllRiderPaths()
.Select(riderInfo => new CodeEditor.Installation
{
Path = riderInfo.Path,
Name = riderInfo.Presentation
})
.ToList();
var editorPath = RiderScriptEditor.CurrentEditor;
if (RiderScriptEditor.IsRiderOrFleetInstallation(editorPath) &&
!res.Any(a => a.Path == editorPath) &&
FileSystemUtil.EditorPathExists(editorPath))
{
// External editor manually set from custom location
var info = new RiderPathLocator.RiderInfo(RiderPathLocator, editorPath, false);
var installation = new CodeEditor.Installation
{
Path = info.Path,
Name = info.Presentation
};
res.Add(installation);
}
return res.ToArray();
}
}
internal class RiderLocatorEnvironment : IRiderLocatorEnvironment
{
public OS CurrentOS
{
get
{
switch (UnityEngine.SystemInfo.operatingSystemFamily)
{
case UnityEngine.OperatingSystemFamily.Windows:
return OS.Windows;
case UnityEngine.OperatingSystemFamily.MacOSX:
return OS.MacOSX;
case UnityEngine.OperatingSystemFamily.Linux:
return OS.Linux;
default:
return OS.Other;
}
}
}
public T FromJson<T>(string json)
{
return (T)UnityEngine.JsonUtility.FromJson(json, typeof(T));
}
public void Verbose(string message, Exception e = null)
{
// only writes to Editor.log
Console.WriteLine(message);
if (e != null)
Console.WriteLine(e);
}
public void Info(string message, Exception e = null)
{
UnityEngine.Debug.Log(message);
if (e != null)
UnityEngine.Debug.Log(e);
}
public void Warn(string message, Exception e = null)
{
UnityEngine.Debug.LogWarning(message);
if (e != null)
UnityEngine.Debug.LogWarning(e);
}
public void Error(string message, Exception e = null)
{
UnityEngine.Debug.LogError(message);
if (e != null)
UnityEngine.Debug.LogException(e);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dab656c79e1985c40b31faebcda44442
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,172 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEditor.Build.Reporting;
using Debug = UnityEngine.Debug;
namespace Packages.Rider.Editor
{
internal static class EditorPluginInterop
{
private static string EditorPluginAssemblyNamePrefix = "JetBrains.Rider.Unity.Editor.Plugin.";
public static readonly string EditorPluginAssemblyName = $"{EditorPluginAssemblyNamePrefix}Net46.Repacked";
public static readonly string EditorPluginAssemblyNameFallback = $"{EditorPluginAssemblyNamePrefix}Full.Repacked";
private static string ourEntryPointTypeName = "JetBrains.Rider.Unity.Editor.PluginEntryPoint";
private static Assembly ourEditorPluginAssembly;
public static Assembly EditorPluginAssembly
{
get
{
if (ourEditorPluginAssembly != null)
return ourEditorPluginAssembly;
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
ourEditorPluginAssembly = assemblies.FirstOrDefault(a =>
{
try
{
return a.GetName().Name.StartsWith(EditorPluginAssemblyNamePrefix); // some user assemblies may fail here
}
catch (Exception)
{
// ignored
}
return default;
});
return ourEditorPluginAssembly;
}
}
private static void DisableSyncSolutionOnceCallBack()
{
// RiderScriptableSingleton.Instance.CsprojProcessedOnce = true;
// Otherwise EditorPlugin regenerates all on every AppDomain reload
var assembly = EditorPluginAssembly;
if (assembly == null) return;
var type = assembly.GetType("JetBrains.Rider.Unity.Editor.Utils.RiderScriptableSingleton");
if (type == null) return;
var baseType = type.BaseType;
if (baseType == null) return;
var instance = baseType.GetProperty("Instance");
if (instance == null) return;
var instanceVal = instance.GetValue(null);
var member = type.GetProperty("CsprojProcessedOnce");
if (member==null) return;
member.SetValue(instanceVal, true);
}
public static string LogPath
{
get
{
try
{
var assembly = EditorPluginAssembly;
if (assembly == null) return null;
var type = assembly.GetType(ourEntryPointTypeName);
if (type == null) return null;
var field = type.GetField("LogPath", BindingFlags.NonPublic | BindingFlags.Static);
if (field == null) return null;
return field.GetValue(null) as string;
}
catch (Exception)
{
Debug.Log("Unable to do OpenFile to Rider from dll, fallback to com.unity.ide.rider implementation.");
}
return null;
}
}
public static bool OpenFileDllImplementation(string path, int line, int column)
{
var openResult = false;
// reflection for fast OpenFileLineCol, when Rider is started and protocol connection is established
try
{
var assembly = EditorPluginAssembly;
if (assembly == null) return false;
var type = assembly.GetType(ourEntryPointTypeName);
if (type == null) return false;
var field = type.GetField("OpenAssetHandler", BindingFlags.NonPublic | BindingFlags.Static);
if (field == null) return false;
var handlerInstance = field.GetValue(null);
var method = handlerInstance.GetType()
.GetMethod("OnOpenedAsset", new[] {typeof(string), typeof(int), typeof(int)});
if (method == null) return false;
var assetFilePath = path;
if (!string.IsNullOrEmpty(path))
assetFilePath = Path.GetFullPath(path);
openResult = (bool) method.Invoke(handlerInstance, new object[] {assetFilePath, line, column});
}
catch (Exception e)
{
Debug.Log("Unable to do OpenFile to Rider from dll, fallback to com.unity.ide.rider implementation.");
Debug.LogException(e);
}
return openResult;
}
public static bool EditorPluginIsLoadedFromAssets(Assembly assembly)
{
if (assembly == null)
return false;
var location = assembly.Location;
var currentDir = Directory.GetCurrentDirectory();
return location.StartsWith(currentDir, StringComparison.InvariantCultureIgnoreCase);
}
internal static void InitEntryPoint(Assembly assembly)
{
try
{
var version = RiderScriptEditorData.instance.editorBuildNumber;
if (version != null)
{
if (version.Major < 192)
DisableSyncSolutionOnceCallBack(); // is require for Rider prior to 2019.2
}
else
DisableSyncSolutionOnceCallBack();
var type = assembly.GetType("JetBrains.Rider.Unity.Editor.AfterUnity56.EntryPoint");
if (type == null)
type = assembly.GetType("JetBrains.Rider.Unity.Editor.UnitTesting.EntryPoint"); // oldRider
RuntimeHelpers.RunClassConstructor(type.TypeHandle);
}
catch (TypeInitializationException ex)
{
Debug.LogException(ex);
if (ex.InnerException != null)
Debug.LogException(ex.InnerException);
}
}
public static string GenerateAdditionalLinkXmlFile(BuildReport report, object data, bool preserveUnityEngineDlls, bool preservePlayerDlls)
{
try
{
var assembly = EditorPluginAssembly;
if (assembly == null) return string.Empty;
var type = assembly.GetType(ourEntryPointTypeName);
if (type == null) return string.Empty;
var method = type.GetMethod(nameof(GenerateAdditionalLinkXmlFile), BindingFlags.NonPublic | BindingFlags.Static);
if (method == null) return string.Empty;
return method.Invoke(null, new object[]{report, data, preserveUnityEngineDlls, preservePlayerDlls}) as string;
}
catch (Exception e)
{
Debug.LogError($"Unable to do {nameof(GenerateAdditionalLinkXmlFile)} to Rider from dll\n{e}");
}
return string.Empty;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9bd02a3a916be64c9b47b1305149423
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
fileFormatVersion: 2
guid: ea3ec41b33345cd4f9298a51abdaa198
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 1
validateReferences: 0
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: x86_64
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace Packages.Rider.Editor
{
internal enum LoggingLevel
{
/// <summary>
/// Do not use it in logging. Only in config to disable logging.
/// </summary>
OFF,
/// <summary>For errors that lead to application failure</summary>
FATAL,
/// <summary>For errors that must be shown in Exception Browser</summary>
ERROR,
/// <summary>Suspicious situations but not errors</summary>
WARN,
/// <summary>Regular level for important events</summary>
INFO,
/// <summary>Additional info for debbuging</summary>
VERBOSE,
/// <summary>Methods &amp; callstacks tracing, more than verbose</summary>
TRACE,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71bb46b59a9a7a346bbab1e185c723df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
using UnityEditor;
using UnityEngine;
namespace Packages.Rider.Editor
{
internal static class PluginSettings
{
public static LoggingLevel SelectedLoggingLevel
{
get => (LoggingLevel) EditorPrefs.GetInt("Rider_SelectedLoggingLevel", 0);
private set => EditorPrefs.SetInt("Rider_SelectedLoggingLevel", (int) value);
}
public static bool LogEventsCollectorEnabled
{
get => EditorPrefs.GetBool("Rider_LogEventsCollectorEnabled", true);
private set => EditorPrefs.SetBool("Rider_LogEventsCollectorEnabled", value);
}
/// <summary>
/// Preferences menu layout
/// </summary>
/// <remarks>
/// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
/// </remarks>
[SettingsProvider]
private static SettingsProvider RiderPreferencesItem()
{
if (!RiderScriptEditor.IsRiderOrFleetInstallation(RiderScriptEditor.CurrentEditor))
return null;
if (!RiderScriptEditorData.instance.shouldLoadEditorPlugin)
return null;
var provider = new SettingsProvider("Preferences/Rider", SettingsScope.User)
{
label = "Rider",
keywords = new[] { "Rider" },
guiHandler = (searchContext) =>
{
EditorGUIUtility.labelWidth = 200f;
EditorGUILayout.BeginVertical();
GUILayout.BeginVertical();
LogEventsCollectorEnabled =
EditorGUILayout.Toggle(new GUIContent("Pass Console to Rider:"), LogEventsCollectorEnabled);
GUILayout.EndVertical();
GUILayout.Label("");
if (!string.IsNullOrEmpty(EditorPluginInterop.LogPath))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Log file:");
var previous = GUI.enabled;
GUI.enabled = previous && SelectedLoggingLevel != LoggingLevel.OFF;
var button = GUILayout.Button(new GUIContent("Open log"));
if (button)
{
// would use Rider if `log` is on the list of extensions, otherwise would use editor configured in the OS
UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(EditorPluginInterop.LogPath, 0);
}
GUI.enabled = previous;
GUILayout.EndHorizontal();
}
var loggingMsg =
@"Sets the amount of Rider Debug output. If you are about to report an issue, please select Verbose logging level and attach Unity console output to the issue.";
SelectedLoggingLevel =
(LoggingLevel) EditorGUILayout.EnumPopup(new GUIContent("Logging Level:", loggingMsg),
SelectedLoggingLevel);
EditorGUILayout.HelpBox(loggingMsg, MessageType.None);
const string url = "https://github.com/JetBrains/resharper-unity";
if (LinkButton(url))
Application.OpenURL(url);;
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
var assembly = EditorPluginInterop.EditorPluginAssembly;
if (assembly != null)
{
var version = assembly.GetName().Version;
GUILayout.Label("Plugin version: " + version, new GUIStyle(GUI.skin.label)
{
margin = new RectOffset(4, 4, 4, 4),
});
}
GUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
};
return provider;
}
public static bool LinkButton(string url)
{
var bClicked = GUILayout.Button(url, RiderStyles.LinkLabelStyle);
var rect = GUILayoutUtility.GetLastRect();
rect.width = RiderStyles.LinkLabelStyle.CalcSize(new GUIContent(url)).x;
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
return bClicked;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1bfe12aa306c0c74db4f4f1a1a0ae5ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa290bd9a165a0543a4bf85ac73914bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using Unity.CodeEditor;
using UnityEditor;
namespace Packages.Rider.Editor.PostProcessors
{
internal class RiderAssetPostprocessor: AssetPostprocessor
{
public static bool OnPreGeneratingCSProjectFiles()
{
var path = RiderScriptEditor.GetEditorRealPath(CodeEditor.CurrentEditorInstallation);
if (RiderScriptEditor.IsRiderOrFleetInstallation(path))
return !ProjectGeneration.ProjectGeneration.isRiderProjectGeneration;
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45471ad7b8c1f964da5e3c07d57fbf4f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 313cbe17019f1934397f91069831062c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,253 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEditor.PackageManager;
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal class AssemblyNameProvider : IAssemblyNameProvider
{
private readonly Dictionary<string, PackageInfo> m_PackageInfoCache = new Dictionary<string, PackageInfo>();
private readonly Dictionary<string, ResponseFileData> m_ResponseFilesCache = new Dictionary<string, ResponseFileData>();
private readonly string[] _specialPackagesForProjectGen = new[] { "com.unity.entities", "com.unity.collections" };
ProjectGenerationFlag m_ProjectGenerationFlag = (ProjectGenerationFlag)EditorPrefs.GetInt("unity_project_generation_flag", 3);
public string[] ProjectSupportedExtensions => EditorSettings.projectGenerationUserExtensions;
public string ProjectGenerationRootNamespace => EditorSettings.projectGenerationRootNamespace;
private Assembly[] m_AllEditorAssemblies;
private Assembly[] m_AllPlayerAssemblies;
private Assembly[] m_AllAssemblies;
public ProjectGenerationFlag ProjectGenerationFlag
{
get => m_ProjectGenerationFlag;
private set
{
EditorPrefs.SetInt("unity_project_generation_flag", (int)value);
m_ProjectGenerationFlag = value;
}
}
public string GetAssemblyNameFromScriptPath(string path)
{
return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
}
public Assembly[] GetAllAssemblies()
{
if (m_AllEditorAssemblies == null)
{
m_AllEditorAssemblies = GetAssembliesByType(AssembliesType.Editor);
m_AllAssemblies = m_AllEditorAssemblies;
}
if (ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
{
if (m_AllPlayerAssemblies == null)
{
m_AllPlayerAssemblies = GetAssembliesByType(AssembliesType.Player);
m_AllAssemblies = new Assembly[m_AllEditorAssemblies.Length + m_AllPlayerAssemblies.Length];
Array.Copy(m_AllEditorAssemblies, m_AllAssemblies, m_AllEditorAssemblies.Length);
Array.Copy(m_AllPlayerAssemblies, 0, m_AllAssemblies, m_AllEditorAssemblies.Length, m_AllPlayerAssemblies.Length);
}
}
return m_AllAssemblies;
}
private static Assembly[] GetAssembliesByType(AssembliesType type)
{
// This is a very expensive Unity call...
var compilationPipelineAssemblies = CompilationPipeline.GetAssemblies(type);
var assemblies = new Assembly[compilationPipelineAssemblies.Length];
var i = 0;
foreach (var compilationPipelineAssembly in compilationPipelineAssemblies)
{
// The CompilationPipeline's assemblies have an output path of Libraries/ScriptAssemblies
// TODO: It might be worth using the app's copy of Assembly and updating output path when we need it
// But that requires tracking editor and player assemblies separately
var outputPath = type == AssembliesType.Editor
? $@"Temp\Bin\Debug\{compilationPipelineAssembly.name}\"
: $@"Temp\Bin\Debug\{compilationPipelineAssembly.name}\Player\";
assemblies[i] = new Assembly(
compilationPipelineAssembly.name,
outputPath,
compilationPipelineAssembly.sourceFiles,
compilationPipelineAssembly.defines,
compilationPipelineAssembly.assemblyReferences,
compilationPipelineAssembly.compiledAssemblyReferences,
compilationPipelineAssembly.flags,
compilationPipelineAssembly.compilerOptions
#if UNITY_2020_2_OR_NEWER
, compilationPipelineAssembly.rootNamespace
#endif
);
i++;
}
return assemblies;
}
public Assembly GetNamedAssembly(string name)
{
foreach (var assembly in GetAllAssemblies())
{
if (assembly.name == name)
return assembly;
}
return null;
}
public string GetProjectName(string name, string[] defines)
{
if (!ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
return name;
return !defines.Contains("UNITY_EDITOR") ? name + ".Player" : name;
}
public IEnumerable<string> GetAllAssetPaths()
{
return AssetDatabase.GetAllAssetPaths();
}
private static string GetPackageRootDirectoryName(string assetPath)
{
const string packagesPrefix = "packages/";
if (!assetPath.StartsWith(packagesPrefix, StringComparison.OrdinalIgnoreCase))
{
return null;
}
var followupSeparator = assetPath.IndexOf('/', packagesPrefix.Length);
// Note that we return the first path segment without modifying/normalising case!
return followupSeparator == -1 ? assetPath : assetPath.Substring(0, followupSeparator);
}
public PackageInfo GetPackageInfoForAssetPath(string assetPath)
{
var packageName = GetPackageRootDirectoryName(assetPath);
if (packageName == null)
{
return null;
}
// Assume the package name casing is consistent. If it's not, we'll fall back to an uppercase variant that's
// saved in the same dictionary. This gives us cheaper case sensitive matching, with a fallback if our assumption
// is incorrect
if (m_PackageInfoCache.TryGetValue(packageName, out var cachedPackageInfo))
return cachedPackageInfo;
var packageNameUpper = packageName.ToUpperInvariant();
if (m_PackageInfoCache.TryGetValue(packageNameUpper, out cachedPackageInfo))
return cachedPackageInfo;
var result = PackageInfo.FindForAssetPath(packageName);
m_PackageInfoCache[packageName] = result;
m_PackageInfoCache[packageNameUpper] = result;
return result;
}
public void ResetCaches()
{
m_PackageInfoCache.Clear();
m_ResponseFilesCache.Clear();
m_AllEditorAssemblies = null;
m_AllPlayerAssemblies = null;
}
public bool IsInternalizedPackagePath(string path)
{
if (string.IsNullOrEmpty(path))
{
return false;
}
var packageInfo = GetPackageInfoForAssetPath(path);
if (packageInfo == null)
{
return false;
}
if (ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies) && _specialPackagesForProjectGen.Contains(packageInfo.name))
{
// special case for RIDER-104519 Rider is reporting errors in scripts that work fine in Unity when utilizing DOTS
// it would be better to only generate .Player projects and not Editor ones, but that would require big changes in ProjectGeneration
return false;
}
var packageSource = packageInfo.source;
switch (packageSource)
{
case PackageSource.Embedded:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Embedded);
case PackageSource.Registry:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Registry);
case PackageSource.BuiltIn:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.BuiltIn);
case PackageSource.Unknown:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Unknown);
case PackageSource.Local:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Local);
case PackageSource.Git:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Git);
#if UNITY_2019_3_OR_NEWER
case PackageSource.LocalTarball:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.LocalTarBall);
#endif
}
return false;
}
public ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory,
ApiCompatibilityLevel apiCompatibilityLevel)
{
var key = responseFilePath + ":" + (int) apiCompatibilityLevel;
if (!m_ResponseFilesCache.TryGetValue(key, out var responseFileData))
{
var systemReferenceDirectories =
CompilationPipeline.GetSystemAssemblyDirectories(apiCompatibilityLevel);
responseFileData = CompilationPipeline.ParseResponseFile(
responseFilePath,
projectDirectory,
systemReferenceDirectories
);
m_ResponseFilesCache.Add(key, responseFileData);
}
return responseFileData;
}
public IEnumerable<string> GetRoslynAnalyzerPaths()
{
return PluginImporter.GetAllImporters()
.Where(i => !i.isNativePlugin && AssetDatabase.GetLabels(i).SingleOrDefault(l => l == "RoslynAnalyzer") != null)
.Select(i => i.assetPath);
}
public void ToggleProjectGeneration(ProjectGenerationFlag preference)
{
if (ProjectGenerationFlag.HasFlag(preference))
{
ProjectGenerationFlag ^= preference;
}
else
{
ProjectGenerationFlag |= preference;
}
}
public void ResetProjectGenerationFlag()
{
ProjectGenerationFlag = ProjectGenerationFlag.None;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 56c8c6e437b14f8e9a91e9832c11bc1a
timeCreated: 1580717719

View File

@@ -0,0 +1,51 @@
using System;
using System.IO;
using System.Security;
using System.Text;
using Packages.Rider.Editor.Util;
namespace Packages.Rider.Editor.ProjectGeneration {
class FileIOProvider : IFileIO
{
public bool Exists(string path)
{
return File.Exists(path);
}
public TextReader GetReader(string path)
{
return new StreamReader(path);
}
public string ReadAllText(string path)
{
return File.ReadAllText(path);
}
public void WriteAllText(string path, string content)
{
File.WriteAllText(path, content, Encoding.UTF8);
LastWriteTracker.UpdateLastWriteIfNeeded(path);
}
public string EscapedRelativePathFor(string file, string rootDirectoryFullPath)
{
// We have to normalize the path, because the PackageManagerRemapper assumes
// dir seperators will be os specific.
var absolutePath = Path.GetFullPath(file.NormalizePath());
var path = SkipPathPrefix(absolutePath, rootDirectoryFullPath);
return SecurityElement.Escape(path);
}
private static string SkipPathPrefix(string path, string prefix)
{
var root = prefix[prefix.Length - 1] == Path.DirectorySeparatorChar
? prefix
: prefix + Path.DirectorySeparatorChar;
return path.StartsWith(root, StringComparison.Ordinal)
? path.Substring(root.Length)
: path;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6ba838b1348d5e46a7eaacd1646c1d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Packages.Rider.Editor.ProjectGeneration {
class GUIDProvider : IGUIDGenerator
{
public string ProjectGuid(string name)
{
return SolutionGuidGenerator.GuidForProject(name);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cfde1a59fb35574189691a9de1df93b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Compilation;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal interface IAssemblyNameProvider
{
string[] ProjectSupportedExtensions { get; }
string ProjectGenerationRootNamespace { get; }
ProjectGenerationFlag ProjectGenerationFlag { get; }
string GetAssemblyNameFromScriptPath(string path);
string GetProjectName(string name, string[] defines);
bool IsInternalizedPackagePath(string path);
Assembly[] GetAllAssemblies();
Assembly GetNamedAssembly(string name);
IEnumerable<string> GetAllAssetPaths();
UnityEditor.PackageManager.PackageInfo GetPackageInfoForAssetPath(string assetPath);
ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, ApiCompatibilityLevel systemReferenceDirectories);
IEnumerable<string> GetRoslynAnalyzerPaths();
void ToggleProjectGeneration(ProjectGenerationFlag preference);
void ResetCaches();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5eea837708474d7e9c1cb4b2eca0213f
timeCreated: 1580717710

View File

@@ -0,0 +1,17 @@
using System.IO;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal interface IFileIO
{
bool Exists(string path);
TextReader GetReader(string path);
string ReadAllText(string path);
void WriteAllText(string path, string content);
// rootDirectoryFullPath is assumed to be the result of Path.GetFullPath
// Passing the directory with a trailing slash (Path.DirectorySeparatorChar) will avoid an allocation
string EscapedRelativePathFor(string path, string rootDirectoryFullPath);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1bdab5b8331b4506bf4eae379235c053
timeCreated: 1580717666

View File

@@ -0,0 +1,7 @@
namespace Packages.Rider.Editor.ProjectGeneration
{
internal interface IGUIDGenerator
{
string ProjectGuid(string name);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8c7e8e301f8b4c30bbf9db502d637f0f
timeCreated: 1580717700

View File

@@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal interface IGenerator
{
bool SyncIfNeeded(IEnumerable<string> affectedFiles, IEnumerable<string> reimportedFiles, bool checkProjectFiles = false);
void Sync();
bool HasSolutionBeenGenerated();
string SolutionFile();
IAssemblyNameProvider AssemblyNameProvider { get; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 39cb9ab8a3b2452cbf58ffbea841d203
timeCreated: 1580717654

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal static class LastWriteTracker
{
internal static bool HasLastWriteTimeChanged()
{
if (!IsUnityCompatible()) return false;
// any external changes of sln/csproj should cause their regeneration
// Directory.GetCurrentDirectory(), "*.csproj", "*.sln"
var files = new List<FileInfo>();
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
files.AddRange(directoryInfo.GetFiles("*.csproj"));
files.Add(new FileInfo(Path.Combine(directoryInfo.FullName, directoryInfo.Name + ".sln")));
return files.Any(a => a.LastWriteTime > RiderScriptEditorPersistedState.instance.LastWrite);
}
internal static void UpdateLastWriteIfNeeded(string path)
{
if (!IsUnityCompatible()) return;
var fileInfo = new FileInfo(path);
if (fileInfo.Directory == null)
return;
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
if (fileInfo.Directory.FullName.Equals(directoryInfo.FullName, StringComparison.OrdinalIgnoreCase) &&
(fileInfo.Extension.Equals(".csproj", StringComparison.OrdinalIgnoreCase)
|| fileInfo.Name.Equals(directoryInfo.Name + ".sln", StringComparison.OrdinalIgnoreCase)))
{
RiderScriptEditorPersistedState.instance.LastWrite = fileInfo.LastWriteTime;
}
}
internal static bool IsUnityCompatible()
{
#if UNITY_2020_1_OR_NEWER
return true;
#else
return false;
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7019e230344c48d4b81602e2e978e5de
timeCreated: 1645608955

View File

@@ -0,0 +1,41 @@
using System.IO;
#if UNITY_2020_1_OR_NEWER
using UnityEditor.PackageManager;
#endif
namespace Packages.Rider.Editor.ProjectGeneration
{
internal static class PackageManagerTracker
{
private static bool HasManifestJsonLastWriteTimeChanged()
{
if (!LastWriteTracker.IsUnityCompatible()) return false;
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
var manifestFile = new FileInfo(Path.Combine(directoryInfo.FullName, "Packages/manifest.json"));
if (manifestFile.Exists)
{
// for the manifest.json, we store the LastWriteTime here
var res = manifestFile.LastWriteTime > RiderScriptEditorPersistedState.instance.ManifestJsonLastWrite;
if (res) RiderScriptEditorPersistedState.instance.ManifestJsonLastWrite = manifestFile.LastWriteTime;
return res;
}
return false;
}
/// <summary>
/// If the manifest.json was changed outside Unity and Rider calls Unity to Refresh, we should call PM to Refresh its state also
/// </summary>
/// <param name="checkProjectFiles"></param>
internal static void SyncIfNeeded(bool checkProjectFiles)
{
#if UNITY_2020_1_OR_NEWER
if (checkProjectFiles && HasManifestJsonLastWriteTimeChanged())
{
Client.Resolve();
}
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 32e50e97779a4753a461190076119a99
timeCreated: 1676882821

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7078f19173ceac84fb9e29b9f6175201
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using System;
namespace Packages.Rider.Editor.ProjectGeneration
{
[Flags]
enum ProjectGenerationFlag
{
None = 0,
Embedded = 1,
Local = 2,
Registry = 4,
Git = 8,
BuiltIn = 16,
Unknown = 32,
PlayerAssemblies = 64,
LocalTarBall = 128,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 78af99d0156944f293b020b49a6830c2
timeCreated: 1580820569

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using UnityEditor.Compilation;
using UnityEngine;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal class ProjectPart
{
public string Name { get; }
public string OutputPath { get; }
public Assembly Assembly { get; }
public List<string> AdditionalAssets { get; }
public string[] SourceFiles { get; }
public string RootNamespace { get; }
public Assembly[] AssemblyReferences { get; }
public string[] CompiledAssemblyReferences { get; }
public string[] Defines { get; }
public ScriptCompilerOptions CompilerOptions { get; }
public ProjectPart(string name, Assembly assembly, List<string> additionalAssets)
{
Name = name;
Assembly = assembly;
AdditionalAssets = additionalAssets;
OutputPath = assembly != null ? assembly.outputPath : "Temp/Bin/Debug";
SourceFiles = assembly != null ? assembly.sourceFiles : Array.Empty<string>();
#if UNITY_2020_2_OR_NEWER
RootNamespace = assembly != null ? assembly.rootNamespace : string.Empty;
#else
RootNamespace = UnityEditor.EditorSettings.projectGenerationRootNamespace;
#endif
AssemblyReferences = assembly != null ? assembly.assemblyReferences : Array.Empty<Assembly>();
CompiledAssemblyReferences = assembly != null ? assembly.compiledAssemblyReferences : Array.Empty<string>();
Defines = assembly != null ? assembly.defines : Array.Empty<string>();
CompilerOptions = assembly != null ? assembly.compilerOptions : new ScriptCompilerOptions();
}
public List<ResponseFileData> GetResponseFileData(IAssemblyNameProvider assemblyNameProvider, string projectDirectory)
{
if (Assembly == null)
return new List<ResponseFileData>();
var data = new List<ResponseFileData>();
foreach (var responseFile in Assembly.compilerOptions.ResponseFiles)
{
var responseFileData = assemblyNameProvider.ParseResponseFile(responseFile, projectDirectory, Assembly.compilerOptions.ApiCompatibilityLevel);
foreach (var error in responseFileData.Errors)
Debug.Log($"{responseFile} Parse Error : {error}");
data.Add(responseFileData);
}
return data;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0691c2fe40564a64b3a9b7372c5eca2a
timeCreated: 1604050230

View File

@@ -0,0 +1,23 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace Packages.Rider.Editor.ProjectGeneration
{
internal static class SolutionGuidGenerator
{
public static string GuidForProject(string projectName)
{
return ComputeGuidHashFor(projectName + "salt");
}
private static string ComputeGuidHashFor(string input)
{
using (var md5 = MD5.Create())
{
var hash = md5.ComputeHash(Encoding.Default.GetBytes(input));
return new Guid(hash).ToString();
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3e4e7fdc19414089a0fb43e43b1bdae1
timeCreated: 1580717740

Some files were not shown because too many files have changed in this diff Show More