예제 #1
0
        private static string ProcessPlatformTemplate(string platformTemplate, string platformName, string configuration, BuildTarget buildTarget, TargetFramework targetFramework, IEnumerable <string> references, IEnumerable <string> defines, params HashSet <string>[] priorToCheck)
        {
            if (Utilities.TryGetXMLTemplate(platformTemplate, "PLATFORM_COMMON_REFERENCE", out string platformCommonReferenceTemplate))
            {
                ProcessReferences(buildTarget, references, out HashSet <string> platformAssemblySearchPaths, out HashSet <string> platformAssemblyReferencePaths, priorToCheck);

                string targetUWPPlatform = uwpTargetPlatformVersion;
                if (string.IsNullOrWhiteSpace(targetUWPPlatform))
                {
                    targetUWPPlatform = Utilities.GetUWPSDKs().Max().ToString(4);
                }

                string minUWPPlatform = uwpMinPlatformVersion;
                if (string.IsNullOrWhiteSpace(minUWPPlatform) || new Version(minUWPPlatform) < DefaultMinUWPSDK)
                {
                    minUWPPlatform = DefaultMinUWPSDK.ToString();
                }
                string[] versionParts = Application.unityVersion.Split('.');
                Dictionary <string, string> platformTokens = new Dictionary <string, string>()
                {
                    { "<!--TARGET_FRAMEWORK_TOKEN-->", targetFramework.AsMSBuildString() },
                    { "<!--PLATFORM_COMMON_DEFINE_CONSTANTS-->", string.Join(";", defines) },
                    { "<!--PLATFORM_COMMON_ASSEMBLY_SEARCH_PATHS_TOKEN-->", string.Join(";", platformAssemblySearchPaths) },

                    // These are UWP specific, but they will be no-op if not needed
                    { "<!--UWP_TARGET_PLATFORM_VERSION_TOKEN-->", targetUWPPlatform },
                    { "<!--UWP_MIN_PLATFORM_VERSION_TOKEN-->", minUWPPlatform },

                    { "<!--UNITY_MAJOR_VERSION_TOKEN-->", versionParts[0] },
                    { "<!--UNITY_MINOR_VERSION_TOKEN-->", versionParts[1] }
                };

                platformTokens.Add(platformCommonReferenceTemplate, string.Join("\r\n", GetReferenceEntries(platformCommonReferenceTemplate, platformAssemblyReferencePaths)));

                return(Utilities.ReplaceTokens(platformTemplate, platformTokens));
            }
            else
            {
                Debug.LogError($"Invalid platform template format for '{platformName}' with configuration '{configuration}'");
                return(platformTemplate);
            }
        }
        private void ProcessPlatformTemplate(ITemplatePart rootPart, TemplateReplacementSet rootReplacementSet, string platformName, string configuration, BuildTarget buildTarget, TargetFramework targetFramework, IEnumerable <string> references, IEnumerable <string> defines, params HashSet <string>[] priorToCheck)
        {
            ProcessReferences(buildTarget, references, out HashSet <string> platformAssemblySearchPaths, out HashSet <string> platformAssemblyReferencePaths, priorToCheck);

            string minUWPPlatform = EditorUserBuildSettings.wsaMinUWPSDK;

            if (string.IsNullOrWhiteSpace(minUWPPlatform) || new Version(minUWPPlatform) < MSBuildTools.DefaultMinUWPSDK)
            {
                minUWPPlatform = MSBuildTools.DefaultMinUWPSDK.ToString();
            }

            // This is a try replace because some may hardcode this value
            rootPart.TryReplaceToken("TARGET_FRAMEWORK", rootReplacementSet, targetFramework.AsMSBuildString());

            rootPart.Tokens["PLATFORM_COMMON_DEFINE_CONSTANTS"].AssignValue(rootReplacementSet, new DelimitedStringSet(";", defines));
            rootPart.Tokens["PLATFORM_COMMON_ASSEMBLY_SEARCH_PATHS"].AssignValue(rootReplacementSet, new DelimitedStringSet(";", platformAssemblySearchPaths));

            // These are UWP specific, but they will be no-op if not needed
            if (buildTarget == BuildTarget.WSAPlayer && configuration == "Player")
            {
                string targetUWPPlatform = EditorUserBuildSettings.wsaUWPSDK;
                if (string.IsNullOrWhiteSpace(targetUWPPlatform))
                {
                    targetUWPPlatform = Utilities.GetUWPSDKs().Max().ToString(4);
                }
                rootPart.TryReplaceToken("UWP_TARGET_PLATFORM_VERSION", rootReplacementSet, targetUWPPlatform);
                rootPart.TryReplaceToken("UWP_MIN_PLATFORM_VERSION", rootReplacementSet, minUWPPlatform);
            }

            ITemplatePart platformCommonReferencePart = rootPart.Templates["PLATFORM_COMMON_REFERENCE"];

            foreach (string reference in platformAssemblyReferencePaths)
            {
                TemplateReplacementSet replacementSet = platformCommonReferencePart.CreateReplacementSet(rootReplacementSet);
                platformCommonReferencePart.Tokens["REFERENCE"].AssignValue(replacementSet, Path.GetFileNameWithoutExtension(reference));
                platformCommonReferencePart.Tokens["HINT_PATH"].AssignValue(replacementSet, reference);
            }
        }