From fe32e679c2d3dc4fbc3b903932a458ccbc730c36 Mon Sep 17 00:00:00 2001 From: Adriano Carlos Verona Date: Tue, 4 Sep 2018 23:06:46 -0400 Subject: [PATCH] Fixed issue in which Unity types could be referenced from multiple assemblies. also added some more log and pointed out that 2018.1 is the recommend version to run the converter. --- .../Editor/UnityScript2CSharpRunner.cs | 14 ++++++++++---- UnityScript2CSharp/Program.cs | 19 +++++++++---------- readme.md | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/EditorIntegration/Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs b/EditorIntegration/Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs index 12626a8..2ac2742 100644 --- a/EditorIntegration/Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs +++ b/EditorIntegration/Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs @@ -2,16 +2,21 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Threading; using Assets.Editor; using UnityEditor; -using UnityEditor.Compilation; using UnityEngine; -using UnityEngine.SceneManagement; using Application = UnityEngine.Application; using Debug = UnityEngine.Debug; +#if UNITY_2017_3_OR_NEWER + +using System.Linq; +using UnityEngine.SceneManagement; +using UnityEditor.Compilation; + +#endif + [Serializable] public class UnityScript2CSharpRunner : UnityEditor.EditorWindow { @@ -248,7 +253,8 @@ public class UnityScript2CSharpRunner : UnityEditor.EditorWindow var referencedAssemblies = CompilationPipeline.GetAssemblies() .SelectMany(a => a.compiledAssemblyReferences) - .Where(a => !a.Contains(unityInstallPath) || a.Contains("UnityExtensions")); + .Where(a => !a.Contains(unityInstallPath) || a.Contains("UnityExtensions")) + .Distinct(StringComparer.InvariantCultureIgnoreCase); foreach (var assemblyPath in referencedAssemblies) { diff --git a/UnityScript2CSharp/Program.cs b/UnityScript2CSharp/Program.cs index 9e2d24b..22732a2 100644 --- a/UnityScript2CSharp/Program.cs +++ b/UnityScript2CSharp/Program.cs @@ -234,16 +234,8 @@ namespace UnityScript2CSharp private static void AppendUnityAssembliesReferences(string unityAssembliesRootPath, List references) { var modularizedUnityEngineFolder = Path.Combine(unityAssembliesRootPath, "UnityEngine"); - if (Directory.Exists(modularizedUnityEngineFolder)) - { - foreach (var assemblyPath in Directory.GetFiles(modularizedUnityEngineFolder, "*.dll")) - { - references.Add(assemblyPath); - } - } - else - references.Add(Path.Combine(unityAssembliesRootPath, "UnityEngine.dll")); - + + references.Add(Path.Combine(unityAssembliesRootPath, "UnityEngine.dll")); references.Add(Path.Combine(unityAssembliesRootPath, "UnityEditor.dll")); } @@ -331,6 +323,13 @@ namespace UnityScript2CSharp Console.WriteLine("Converting '{0}' ({1} scripts)", assemblyType, scripts.Count); + if (args.Verbose) + { + Console.WriteLine("Referenced assemblies:"); + foreach(var r in references) + System.Console.WriteLine($"\t{r}"); + } + Action handler = (scriptPath, context, unsupportedCount) => HandleConvertedScript(scriptPath, context, args.RemoveOriginalFiles, args.Verbose, unsupportedCount); if (args.DryRun) handler = (_, __, ___) => {}; diff --git a/readme.md b/readme.md index 3b81b09..34ee81d 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ Before running the conversion tool: 1. Keep in mind that you'll have best results (i.e, a smoother conversion process) if your UnityScripts have *#pragma strict* applied to them. -1. Launch Unity editor (**preferably, 2018.2**) and make sure you allow APIUpdater to run and update any obsolete API usages. This is necessary to avoid compilation errors during the conversion. +1. Launch Unity editor (**preferably, 2018.1**) and make sure you allow APIUpdater to run and update any obsolete API usages. This is necessary to avoid compilation errors during the conversion. Next step is to run the converter. For that we recomend trying the _Editor Unity Package Integration_ first: