Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class CSProjectInfo : ReferenceItemInfo
{
private readonly List<CSProjectDependency<CSProjectInfo>> csProjectDependencies = new List<CSProjectDependency<CSProjectInfo>>();
private readonly List<CSProjectDependency<PluginAssemblyInfo>> pluginAssemblyDependencies = new List<CSProjectDependency<PluginAssemblyInfo>>();
private readonly List<CSProjectDependency<WinMDInfo>> winmdDependencies = new List<CSProjectDependency<WinMDInfo>>();

/// <summary>
/// The associated Assembly-Definition info if available.
Expand All @@ -63,6 +64,8 @@ public class CSProjectInfo : ReferenceItemInfo

public IReadOnlyCollection<CSProjectDependency<PluginAssemblyInfo>> PluginDependencies { get; }

public IReadOnlyCollection<CSProjectDependency<WinMDInfo>> WinMDDependencies { get; }

/// <summary>
/// Creates a new instance of the CSProject info.
/// </summary>
Expand All @@ -87,6 +90,7 @@ internal CSProjectInfo(UnityProjectInfo unityProjectInfo, AssemblyDefinitionInfo

ProjectDependencies = new ReadOnlyCollection<CSProjectDependency<CSProjectInfo>>(csProjectDependencies);
PluginDependencies = new ReadOnlyCollection<CSProjectDependency<PluginAssemblyInfo>>(pluginAssemblyDependencies);
WinMDDependencies = new ReadOnlyCollection<CSProjectDependency<WinMDInfo>>(winmdDependencies);
}

private ProjectType GetProjectType(AssemblyDefinitionInfo assemblyDefinitionInfo)
Expand Down Expand Up @@ -161,6 +165,15 @@ internal void AddDependency(PluginAssemblyInfo pluginAssemblyInfo)
AddDependency(pluginAssemblyDependencies, pluginAssemblyInfo);
}

/// <summary>
/// Adds a dependency to the project.
/// </summary>
/// <param name="winmdInfo">The winmd dependency.</param>
internal void AddDependency(WinMDInfo winmdInfo)
{
AddDependency(winmdDependencies, winmdInfo);
}

private void AddDependency<T>(List<CSProjectDependency<T>> items, T referenceInfo) where T : ReferenceItemInfo
{
items.Add(new CSProjectDependency<T>(referenceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ private void CreateProjectReferencesSet(CSProjectInfo projectInfo, ITemplatePart
additionalSearchPaths.Add(Path.GetDirectoryName(dependency.Dependency.ReferencePath.LocalPath));
}

foreach (CSProjectDependency<WinMDInfo> dependency in projectInfo.WinMDDependencies)
{
List<string> platformConditions = GetPlatformConditions(inEditor ? projectInfo.InEditorPlatforms : projectInfo.PlayerPlatforms, inEditor ? dependency.InEditorSupportedPlatforms : dependency.PlayerSupportedPlatforms);

TemplateReplacementSet replacementSet = pluginReferenceTemplatePart.CreateReplacementSet(templateReplacementSet);
pluginReferenceTemplatePart.Tokens["REFERENCE"].AssignValue(replacementSet, dependency.Dependency.Name);
pluginReferenceTemplatePart.Tokens["HINT_PATH"].AssignValue(replacementSet, dependency.Dependency.ReferencePath.LocalPath);
pluginReferenceTemplatePart.Tokens["CONDITION"].AssignValue(replacementSet, platformConditions.Count == 0 ? "false" : string.Join(" OR ", platformConditions));

additionalSearchPaths.Add(Path.GetDirectoryName(dependency.Dependency.ReferencePath.LocalPath));
}

templatePart.Tokens["REFERENCE_CONFIGURATION"].AssignValue(templateReplacementSet, inEditor ? "InEditor" : "Player");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class UnityProjectInfo : IDisposable
/// </summary>
public IReadOnlyCollection<PluginAssemblyInfo> Plugins { get; private set; }

/// <summary>
/// Gets all the parsed winmds for this Unity project.
/// </summary>
public IReadOnlyCollection<WinMDInfo> WinMDs { get; private set; }

public UnityProjectInfo(HashSet<BuildTarget> supportedBuildTargets)
{
AvailablePlatforms = new ReadOnlyCollection<CompilationPlatformInfo>(CompilationPipeline.GetAssemblyDefinitionPlatforms()
Expand Down Expand Up @@ -86,7 +91,8 @@ public void Dispose()

public void RefreshPlugins()
{
Plugins = new ReadOnlyCollection<PluginAssemblyInfo>(ScanForPluginDLLs());
ScanForReferences(out List<PluginAssemblyInfo> plugins, out List<WinMDInfo> winmds);
Plugins = new ReadOnlyCollection<PluginAssemblyInfo>(plugins);

foreach (PluginAssemblyInfo plugin in Plugins)
{
Expand All @@ -97,6 +103,8 @@ public void RefreshPlugins()
}
}

WinMDs = new ReadOnlyCollection<WinMDInfo>(winmds);

RefreshProjects();
}

Expand Down Expand Up @@ -270,6 +278,21 @@ private CSProjectInfo GetProjectInfo(Dictionary<string, CSProjectInfo> projectsM
toReturn.AddDependency(plugin);
}
}

foreach (WinMDInfo winmd in WinMDs)
{
if (!dependencies.IsBaseOf(winmd.ReferencePath))
{
if (winmd.IsValid)
{
toReturn.AddDependency(winmd);
}
else
{
Debug.LogError($"References to {winmd} were excluded because the winmd is configured incorrectly. Make sure this winmd is setup to only support WSAPlayer in the Unity inspector.");
}
}
}
}

foreach (string reference in toReturn.AssemblyDefinitionInfo.References)
Expand All @@ -296,31 +319,44 @@ private CSProjectInfo GetProjectInfo(Dictionary<string, CSProjectInfo> projectsM
return toReturn;
}

private List<PluginAssemblyInfo> ScanForPluginDLLs()
private void ScanForReferences(out List<PluginAssemblyInfo> plugins, out List<WinMDInfo> winmds)
{
List<PluginAssemblyInfo> toReturn = new List<PluginAssemblyInfo>();
plugins = new List<PluginAssemblyInfo>();
winmds = new List<WinMDInfo>();

foreach (string assetAssemblyPath in Directory.GetFiles(Utilities.AssetPath, "*.dll", SearchOption.AllDirectories))
IEnumerable<string> assetReferences = Directory.EnumerateFiles(Utilities.AssetPath, "*.*", SearchOption.AllDirectories)
.Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.ToLower() [](start = 31, length = 14)

Could do .Select(t=>t.ToLower()).Where(t=> t.EndsWith() || ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you go this route you end up with all lower case file names which can cause issues with finding the asset relative path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, my bad. Was thinking of how best to cache. Could you pass StringCompareOptions to EndsWith?

foreach (string assetPath in assetReferences)
{
string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetAssemblyPath);
string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetPath);
PluginImporter importer = (PluginImporter)AssetImporter.GetAtPath(assetRelativePath);
if (importer == null)
{
Debug.LogWarning($"Didn't get an importer for '{assetRelativePath}', most likely due to it being in a Unity hidden folder (prefixed by a .)");
continue;
}

PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetAssemblyPath, importer.isNativePlugin ? PluginType.Native : PluginType.Managed);
toReturn.Add(toAdd);
if (assetRelativePath.EndsWith(".dll"))
{
PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetPath, importer.isNativePlugin ? PluginType.Native : PluginType.Managed);
plugins.Add(toAdd);
}
else if (assetRelativePath.EndsWith(".winmd"))
{
WinMDInfo toAdd = new WinMDInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetPath);
winmds.Add(toAdd);
}
}

foreach (string packageDllPath in Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.dll", SearchOption.AllDirectories))
IEnumerable<string> packageReferences = Directory.EnumerateFiles(Utilities.PackageLibraryCachePath, "*.*", SearchOption.AllDirectories)
.Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd"));
foreach (string packagePath in packageReferences)
{
string metaPath = packageDllPath + ".meta";
string metaPath = packagePath + ".meta";

if (!File.Exists(metaPath))
{
Debug.LogWarning($"Skipping a packages DLL that didn't have an associated meta: '{packageDllPath}'");
Debug.LogWarning($"Skipping a packages reference that didn't have an associated meta: '{packagePath}'");
continue;
}
Guid guid;
Expand All @@ -329,18 +365,24 @@ private List<PluginAssemblyInfo> ScanForPluginDLLs()
string guidLine = reader.ReadUntil("guid");
if (!Guid.TryParse(guidLine.Split(':')[1].Trim(), out guid))
{
Debug.LogWarning($"Skipping a packages DLL that didn't have a valid guid in the .meta file: '{packageDllPath}'");
Debug.LogWarning($"Skipping a packages reference that didn't have a valid guid in the .meta file: '{packagePath}'");
continue;
}
}

bool isManaged = Utilities.IsManagedAssembly(packageDllPath);
PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, guid, packageDllPath, isManaged ? PluginType.Managed : PluginType.Native);
toReturn.Add(toAdd);
if (packagePath.EndsWith(".dll"))
{
bool isManaged = Utilities.IsManagedAssembly(packagePath);
PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, guid, packagePath, isManaged ? PluginType.Managed : PluginType.Native);
plugins.Add(toAdd);
}
else if (packagePath.EndsWith(".winmd"))
{
WinMDInfo toAdd = new WinMDInfo(this, guid, packagePath);
winmds.Add(toAdd);
}
}

return toReturn;
}
}
}
#endif
#endif
Loading