initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,207 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEditor.PackageManager;
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IAssemblyNameProvider
{
string[] ProjectSupportedExtensions { get; }
string ProjectGenerationRootNamespace { get; }
ProjectGenerationFlag ProjectGenerationFlag { get; }
string GetAssemblyNameFromScriptPath(string path);
string GetAssemblyName(string assemblyOutputPath, string assemblyName);
bool IsInternalizedPackagePath(string path);
IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution);
IEnumerable<string> GetAllAssetPaths();
UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath);
ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories);
void ToggleProjectGeneration(ProjectGenerationFlag preference);
}
public class AssemblyNameProvider : IAssemblyNameProvider
{
private readonly Dictionary<string, UnityEditor.PackageManager.PackageInfo> m_PackageInfoCache = new Dictionary<string, UnityEditor.PackageManager.PackageInfo>();
ProjectGenerationFlag m_ProjectGenerationFlag = (ProjectGenerationFlag)EditorPrefs.GetInt(
"unity_project_generation_flag",
(int)(ProjectGenerationFlag.Local | ProjectGenerationFlag.Embedded));
public string[] ProjectSupportedExtensions => EditorSettings.projectGenerationUserExtensions;
public string ProjectGenerationRootNamespace => EditorSettings.projectGenerationRootNamespace;
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 IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
{
IEnumerable<Assembly> assemblies = GetAssembliesByType(AssembliesType.Editor, shouldFileBePartOfSolution, @"Temp\Bin\Debug\");
if (!ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
{
return assemblies;
}
var playerAssemblies = GetAssembliesByType(AssembliesType.Player, shouldFileBePartOfSolution, @"Temp\Bin\Debug\Player\");
return assemblies.Concat(playerAssemblies);
}
private static IEnumerable<Assembly> GetAssembliesByType(AssembliesType type, Func<string, bool> shouldFileBePartOfSolution, string outputPath)
{
foreach (var assembly in CompilationPipeline.GetAssemblies(type))
{
if (assembly.sourceFiles.Any(shouldFileBePartOfSolution))
{
yield return new Assembly(
assembly.name,
outputPath,
assembly.sourceFiles,
assembly.defines,
assembly.assemblyReferences,
assembly.compiledAssemblyReferences,
assembly.flags,
assembly.compilerOptions
#if UNITY_2020_2_OR_NEWER
, assembly.rootNamespace
#endif
);
}
}
}
public string GetCompileOutputPath(string assemblyName)
{
return assemblyName.EndsWith(".Player", StringComparison.Ordinal) ? @"Temp\Bin\Debug\Player\" : @"Temp\Bin\Debug\";
}
public IEnumerable<string> GetAllAssetPaths()
{
return AssetDatabase.GetAllAssetPaths();
}
private static string ResolvePotentialParentPackageAssetPath(string assetPath)
{
const string packagesPrefix = "packages/";
if (!assetPath.StartsWith(packagesPrefix, StringComparison.OrdinalIgnoreCase))
{
return null;
}
var followupSeparator = assetPath.IndexOf('/', packagesPrefix.Length);
if (followupSeparator == -1)
{
return assetPath.ToLowerInvariant();
}
return assetPath.Substring(0, followupSeparator).ToLowerInvariant();
}
public UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath)
{
var parentPackageAssetPath = ResolvePotentialParentPackageAssetPath(assetPath);
if (parentPackageAssetPath == null)
{
return null;
}
if (m_PackageInfoCache.TryGetValue(parentPackageAssetPath, out var cachedPackageInfo))
{
return cachedPackageInfo;
}
var result = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(parentPackageAssetPath);
m_PackageInfoCache[parentPackageAssetPath] = result;
return result;
}
public bool IsInternalizedPackagePath(string path)
{
if (string.IsNullOrEmpty(path.Trim()))
{
return false;
}
var packageInfo = FindForAssetPath(path);
if (packageInfo == null)
{
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);
case PackageSource.LocalTarball:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.LocalTarBall);
}
return false;
}
public ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories)
{
return CompilationPipeline.ParseResponseFile(
responseFilePath,
projectDirectory,
systemReferenceDirectories
);
}
public void ToggleProjectGeneration(ProjectGenerationFlag preference)
{
if (ProjectGenerationFlag.HasFlag(preference))
{
ProjectGenerationFlag ^= preference;
}
else
{
ProjectGenerationFlag |= preference;
}
}
internal void ResetPackageInfoCache()
{
m_PackageInfoCache.Clear();
}
public void ResetProjectGenerationFlag()
{
ProjectGenerationFlag = ProjectGenerationFlag.None;
}
public string GetAssemblyName(string assemblyOutputPath, string assemblyName)
{
return assemblyOutputPath.EndsWith(@"\Player\", StringComparison.Ordinal) ? assemblyName + ".Player" : assemblyName;
}
}
}

View file

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

View file

@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.IO;
using System.Text;
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IFileIO
{
bool Exists(string fileName);
string ReadAllText(string fileName);
void WriteAllText(string fileName, string content);
}
class FileIOProvider : IFileIO
{
public bool Exists(string fileName)
{
return File.Exists(fileName);
}
public string ReadAllText(string fileName)
{
return File.ReadAllText(fileName);
}
public void WriteAllText(string fileName, string content)
{
File.WriteAllText(fileName, content, Encoding.UTF8);
}
}
}

View file

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

View file

@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IGUIDGenerator
{
string ProjectGuid(string projectName, string assemblyName);
string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage);
}
class GUIDProvider : IGUIDGenerator
{
public string ProjectGuid(string projectName, string assemblyName)
{
return SolutionGuidGenerator.GuidForProject(projectName + assemblyName);
}
public string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage)
{
return SolutionGuidGenerator.GuidForSolution(projectName, scriptingLanguage);
}
}
}

View file

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

View file

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

View file

@ -0,0 +1,23 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
namespace Microsoft.Unity.VisualStudio.Editor
{
[Flags]
public 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,11 @@
fileFormatVersion: 2
guid: 555fcccd6b79a864f83e7a319daa1c3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,27 @@
using System;
namespace Microsoft.Unity.VisualStudio.Editor
{
internal class ProjectProperties
{
public string ProjectGuid { get; set; } = string.Empty;
public string LangVersion { get; set; } = "latest";
public string AssemblyName { get; set; } = string.Empty;
public string RootNamespace { get; set; } = string.Empty;
public string OutputPath { get; set; } = string.Empty;
// Analyzers
public string[] Analyzers { get; set; } = Array.Empty<string>();
public string RulesetPath { get; set; } = string.Empty;
// RSP alterable
public string[] Defines { get; set; } = Array.Empty<string>();
public bool Unsafe { get; set; } = false;
// VSTU Flavouring
public string FlavoringProjectType { get; set; } = string.Empty;
public string FlavoringBuildTarget { get; set; } = string.Empty;
public string FlavoringUnityVersion { get; set; } = string.Empty;
public string FlavoringPackageVersion { get; set; } = string.Empty;
}
}

View file

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