Example #1
0
        internal void GenerateAndWriteSolutionAndProjects(ScriptEditorUtility.ScriptEditor scriptEditor)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            IEnumerable <MonoIsland> islands = EditorCompilationInterface.GetAllMonoIslands().
                                               Where(i => 0 < i._files.Length && i._files.Any(f => ShouldFileBePartOfSolution(f)));

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var responseFilePath = Path.Combine("Assets", MonoCSharpCompiler.ReponseFilename);

            var responseFileData = ScriptCompilerBase.ParseResponseFileFromFile(Path.Combine(_projectDirectory, responseFilePath));

            if (responseFileData.Errors.Length > 0)
            {
                foreach (var error in responseFileData.Errors)
                {
                    UnityEngine.Debug.LogErrorFormat("{0} Parse Error : {1}", responseFilePath, error);
                }
            }

            SyncSolution(islands);
            var allProjectIslands = RelevantIslandsForMode(islands, ModeForCurrentExternalEditor()).ToList();

            foreach (MonoIsland island in allProjectIslands)
            {
                SyncProject(island, allAssetProjectParts, responseFileData, allProjectIslands);
            }

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
            {
                WriteVSCodeSettingsFiles();
            }
        }
        internal void GenerateAndWriteSolutionAndProjects(ScriptEditorUtility.ScriptEditor scriptEditor)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            IEnumerable <MonoIsland> islands = EditorCompilationInterface.GetAllMonoIslands().
                                               Where(i => 0 < i._files.Length && i._files.Any(f => ShouldFileBePartOfSolution(f)));

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var responseFilePath = Path.Combine("Assets", MonoCSharpCompiler.ResponseFilename);

            var monoIslands = islands.ToList();


            SyncSolution(monoIslands);
            var allProjectIslands = RelevantIslandsForMode(monoIslands, ModeForCurrentExternalEditor()).ToList();

            foreach (MonoIsland island in allProjectIslands)
            {
                var responseFileData = parseResponseFileData(island, responseFilePath);
                SyncProject(island, allAssetProjectParts, responseFileData, allProjectIslands);
            }

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
            {
                WriteVSCodeSettingsFiles();
            }
        }
Example #3
0
 public void Sync()
 {
     this.SetupProjectSupportedExtensions();
     if (!AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles())
     {
         ScriptEditorUtility.ScriptEditor scriptEditorFromPreferences = ScriptEditorUtility.GetScriptEditorFromPreferences();
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.SystemDefault || scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.Other)
         {
             return;
         }
         IEnumerable <MonoIsland> islands = from i in EditorCompilationInterface.GetAllMonoIslands()
                                            where 0 < i._files.Length && i._files.Any((string f) => this.ShouldFileBePartOfSolution(f))
                                            select i;
         Dictionary <string, string> allAssetsProjectParts = this.GenerateAllAssetProjectParts();
         string[] responseFileDefinesFromFile = ScriptCompilerBase.GetResponseFileDefinesFromFile(MonoCSharpCompiler.ReponseFilename);
         this.SyncSolution(islands);
         List <MonoIsland> list = SolutionSynchronizer.RelevantIslandsForMode(islands, SolutionSynchronizer.ModeForCurrentExternalEditor()).ToList <MonoIsland>();
         foreach (MonoIsland current in list)
         {
             this.SyncProject(current, allAssetsProjectParts, responseFileDefinesFromFile, list);
         }
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
         {
             this.WriteVSCodeSettingsFiles();
         }
     }
     AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
 }
Example #4
0
        private static JSONValue JsonForProject()
        {
            List <ProjectStateRestHandler.Island> list = (from i in EditorCompilationInterface.GetAllMonoIslands()
                                                          select new ProjectStateRestHandler.Island
            {
                MonoIsland = i,
                Name = Path.GetFileNameWithoutExtension(i._output),
                References = i._references.ToList <string>()
            }).ToList <ProjectStateRestHandler.Island>();

            foreach (ProjectStateRestHandler.Island current in list)
            {
                List <string> list2 = new List <string>();
                List <string> list3 = new List <string>();
                foreach (string current2 in current.References)
                {
                    string refName = Path.GetFileNameWithoutExtension(current2);
                    if (current2.StartsWith("Library/") && list.Any((ProjectStateRestHandler.Island i) => i.Name == refName))
                    {
                        list2.Add(refName);
                        list3.Add(current2);
                    }
                    if (current2.EndsWith("/UnityEditor.dll") || current2.EndsWith("/UnityEngine.dll") || current2.EndsWith("\\UnityEditor.dll") || current2.EndsWith("\\UnityEngine.dll"))
                    {
                        list3.Add(current2);
                    }
                }
                current.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
                current.References.Add(InternalEditorUtility.GetEngineAssemblyPath());
                foreach (string current3 in list2)
                {
                    current.References.Add(current3);
                }
                foreach (string current4 in list3)
                {
                    current.References.Remove(current4);
                }
            }
            string[]  array   = list.SelectMany((ProjectStateRestHandler.Island i) => i.MonoIsland._files).Concat(ProjectStateRestHandler.GetAllSupportedFiles()).Distinct <string>().ToArray <string>();
            string[]  strings = ProjectStateRestHandler.RelativeToProjectPath(ProjectStateRestHandler.FindEmptyDirectories(ProjectStateRestHandler.AssetsPath, array));
            JSONValue result  = default(JSONValue);

            result["islands"] = new JSONValue((from i in list
                                               select ProjectStateRestHandler.JsonForIsland(i) into i2
                                               where !i2.IsNull()
                                               select i2).ToList <JSONValue>());
            result["basedirectory"] = ProjectStateRestHandler.ProjectPath;
            JSONValue value = default(JSONValue);

            value["files"]            = JSONHandler.ToJSON(array);
            value["emptydirectories"] = JSONHandler.ToJSON(strings);
            result["assetdatabase"]   = value;
            return(result);
        }
 // Do not remove. Called through reflection by Visual Studio Tools for Unity.
 // Use EditorCompilationInterface.GetAllMonoIslands internally instead of this method.
 internal static UnityEditor.Scripting.MonoIsland[] GetMonoIslands()
 {
     return(EditorCompilationInterface.GetAllMonoIslands());
 }
Example #6
0
        private static JSONValue JsonForProject()
        {
            var islands = EditorCompilationInterface.GetAllMonoIslands().Select(i => new Island
            {
                MonoIsland = i,
                Name       = Path.GetFileNameWithoutExtension(i._output),
                References = i._references.ToList()
            }).ToList();

            // Mono islands have references to each others output location. For MD we want to have the reference
            // be to the actual project, so we are going to update the references here
            foreach (Island island in islands)
            {
                var toAdd    = new List <string>();
                var toRemove = new List <string>();

                foreach (var reference in island.References)
                {
                    var refName = Path.GetFileNameWithoutExtension(reference);

                    if (reference.StartsWith("Library/") && islands.Any(i => i.Name == refName))
                    {
                        toAdd.Add(refName);
                        toRemove.Add(reference);
                    }

                    if (reference.EndsWith("/UnityEditor.dll") || reference.EndsWith("/UnityEngine.dll") ||
                        reference.EndsWith("\\UnityEditor.dll") || reference.EndsWith("\\UnityEngine.dll"))
                    {
                        toRemove.Add(reference);
                    }
                }

                island.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
                island.References.Add(InternalEditorUtility.GetEngineAssemblyPath());

                foreach (var a in toAdd)
                {
                    island.References.Add(a);
                }

                foreach (var r in toRemove)
                {
                    island.References.Remove(r);
                }
            }

            var files            = islands.SelectMany(i => i.MonoIsland._files).Concat(GetAllSupportedFiles()).Distinct().ToArray();
            var emptyDirectories = RelativeToProjectPath(FindEmptyDirectories(AssetsPath, files));

            var result = new JSONValue();

            result["islands"]       = new JSONValue(islands.Select(i => JsonForIsland(i)).Where(i2 => !i2.IsNull()).ToList());
            result["basedirectory"] = ProjectPath;

            var assetDatabase = new JSONValue();

            assetDatabase["files"]            = ToJSON(files);
            assetDatabase["emptydirectories"] = ToJSON(emptyDirectories);

            result["assetdatabase"] = assetDatabase;
            return(result);
        }