示例#1
0
        private static void RunGenerateSDKProjects()
        {
            // Create a copy of the packages as they might change after we create the MSBuild project
            string generatedProjectPath = Path.Combine(Utilities.MSBuildOutputFolder, "Projects");

            try
            {
                Utilities.EnsureCleanDirectory(generatedProjectPath);
            }
            catch (IOException ex)
            {
                if (ex.Message.Contains(@"db.lock"))
                {
                    Debug.LogError("Generated project appears to be still open with Visual Studio.");
                    throw new InvalidDataException("Generated project appears to be still open with Visual Studio.", ex);
                }
                else
                {
                    throw;
                }
            }

            Utilities.EnsureCleanDirectory(Path.Combine(Utilities.MSBuildOutputFolder, "Output"));

            MakePackagesCopy(Utilities.MSBuildOutputFolder);

            List <CompilationPlatformInfo> platforms = CompilationPipeline.GetAssemblyDefinitionPlatforms()
                                                       .Where(t => supportedBuildTargets.Contains(t.BuildTarget))
                                                       .Select(CompilationPlatformInfo.GetCompilationPlatform)
                                                       .OrderBy(t => t.Name)
                                                       .ToList();

            CompilationPlatformInfo editorPlatform = CompilationPlatformInfo.GetEditorPlatform();

            CreateCommonPropsFile(platforms, editorPlatform, generatedProjectPath);
            UnityProjectInfo unityProjectInfo = new UnityProjectInfo(platforms, generatedProjectPath);

            // Read the solution template
            string solutionTemplateText = File.ReadAllText(Utilities.GetAssetsRelativePathFrom(TemplateFiles.Instance.MSBuildSolutionTemplatePath));

            // Read the project template
            string projectTemplateText = File.ReadAllText(Utilities.GetAssetsRelativePathFrom(TemplateFiles.Instance.SDKProjectFileTemplatePath));

            unityProjectInfo.ExportSolution(solutionTemplateText, projectTemplateText, generatedProjectPath);

            foreach (string otherFile in TemplateFiles.Instance.OtherFiles)
            {
                File.Copy(otherFile, Path.Combine(generatedProjectPath, Path.GetFileName(otherFile)));
            }
        }
 private void TryAddEnabledPlatform(Dictionary <BuildTarget, CompilationPlatformInfo> playerPlatforms, Dictionary <string, bool> enabledPlatforms, string platformName, BuildTarget platformTarget)
 {
     if (enabledPlatforms.TryGetValue(platformName, out bool platformEnabled) && platformEnabled)
     {
         CompilationPlatformInfo platform = UnityProjectInfo.AvailablePlatforms.FirstOrDefault(t => t.BuildTarget == platformTarget);
         if (platform != null)
         {
             playerPlatforms.Add(platformTarget, platform);
         }
         else
         {
             Debug.LogError($"Platform '{platformName}' was specified as enabled by '{ReferencePath.AbsolutePath}' plugin, but not available in processed compilation settings.");
         }
     }
 }
示例#3
0
        private static void ProcessPlatformTemplateForConfiguration(CompilationPlatformInfo platform, string projectOutputFolder, bool inEditorConfiguration)
        {
            string configuration = inEditorConfiguration ? "InEditor" : "Player";

            string platformTemplate = File.ReadAllText(TemplateFiles.Instance.GetTemplateFilePathForPlatform(platform.Name, configuration));

            string platformPropsText;

            if (inEditorConfiguration)
            {
                platformPropsText = ProcessPlatformTemplate(platformTemplate, platform.Name, configuration, platform.BuildTarget, platform.TargetFramework,
                                                            platform.CommonPlatformReferences.Concat(platform.AdditionalInEditorReferences), platform.CommonPlatformDefines.Concat(platform.AdditionalInEditorDefines));
            }
            else
            {
                platformPropsText = ProcessPlatformTemplate(platformTemplate, platform.Name, configuration, platform.BuildTarget, platform.TargetFramework,
                                                            platform.CommonPlatformReferences.Concat(platform.AdditionalPlayerReferences), platform.CommonPlatformDefines.Concat(platform.AdditionalPlayerDefines));
            }

            File.WriteAllText(Path.Combine(projectOutputFolder, $"{platform.Name}.{configuration}.props"), platformPropsText);
        }
示例#4
0
        private static void CreateCommonPropsFile(IEnumerable <CompilationPlatformInfo> availablePlatforms, CompilationPlatformInfo editorPlatform, string projectOutputFolder)
        {
            foreach (CompilationPlatformInfo platform in availablePlatforms)
            {
                // Check for specialized template, otherwise get the common one
                ProcessPlatformTemplateForConfiguration(platform, projectOutputFolder, true);
                ProcessPlatformTemplateForConfiguration(platform, projectOutputFolder, false);
            }

            ProcessPlatformTemplateForConfiguration(editorPlatform, projectOutputFolder, true);
        }
 private bool ContainsDefineHelper(string define, bool inEditor, CompilationPlatformInfo platform)
 {
     return(platform.CommonPlatformDefines.Contains(define) ||
            (inEditor ? platform.AdditionalInEditorDefines.Contains(define) : platform.AdditionalPlayerDefines.Contains(define)));
 }