Exemplo n.º 1
0
        private static string BuildPlayer(string[] scenes, string locationPathName, string assetBundleManifestPath, BuildTarget target, BuildOptions options)
        {
            if (string.IsNullOrEmpty(locationPathName))
            {
                if (!(((options & BuildOptions.InstallInBuildFolder) != BuildOptions.CompressTextures) && PostprocessBuildPlayer.SupportsInstallInBuildFolder(target)))
                {
                    return("The 'locationPathName' parameter for BuildPipeline.BuildPlayer should not be null or empty.");
                }
            }
            else if (string.IsNullOrEmpty(Path.GetFileName(locationPathName)))
            {
                string extensionForBuildTarget = PostprocessBuildPlayer.GetExtensionForBuildTarget(target, options);
                if (!string.IsNullOrEmpty(extensionForBuildTarget))
                {
                    return($"For the '{target}' target the 'locationPathName' parameter for BuildPipeline.BuildPlayer should not end with a directory separator.
Provided path: '{locationPathName}', expected a path with the extension '.{extensionForBuildTarget}'.");
                }
            }
            try
            {
                return(BuildPlayerInternal(scenes, locationPathName, assetBundleManifestPath, target, options).SummarizeErrors());
            }
            catch (Exception exception)
            {
                LogBuildExceptionAndExit("BuildPipeline.BuildPlayer", exception);
                return("");
            }
        }
Exemplo n.º 2
0
        private static string BuildPlayer(string[] scenes, string locationPathName, string assetBundleManifestPath, BuildTarget target, BuildOptions options)
        {
            string result;

            if (string.IsNullOrEmpty(locationPathName))
            {
                if ((options & BuildOptions.InstallInBuildFolder) == BuildOptions.None || !PostprocessBuildPlayer.SupportsInstallInBuildFolder(target))
                {
                    result = "The 'locationPathName' parameter for BuildPipeline.BuildPlayer should not be null or empty.";
                    return(result);
                }
            }
            else if (string.IsNullOrEmpty(Path.GetFileName(locationPathName)))
            {
                string extensionForBuildTarget = PostprocessBuildPlayer.GetExtensionForBuildTarget(target, options);
                if (!string.IsNullOrEmpty(extensionForBuildTarget))
                {
                    result = string.Format("For the '{0}' target the 'locationPathName' parameter for BuildPipeline.BuildPlayer should not end with a directory separator.\nProvided path: '{1}', expected a path with the extension '.{2}'.", target, locationPathName, extensionForBuildTarget);
                    return(result);
                }
            }
            try
            {
                result = BuildPipeline.BuildPlayerInternal(scenes, locationPathName, assetBundleManifestPath, target, options).SummarizeErrors();
            }
            catch (Exception exception)
            {
                BuildPipeline.LogBuildExceptionAndExit("BuildPipeline.BuildPlayer", exception);
                result = "";
            }
            return(result);
        }
Exemplo n.º 3
0
        internal static bool ValidateLocationPathNameForBuildTargetGroup(string locationPathName, BuildTargetGroup buildTargetGroup, BuildTarget target, BuildOptions options, out string errorMessage)
        {
            if (string.IsNullOrEmpty(locationPathName))
            {
                var willInstallInBuildFolder = (options & BuildOptions.InstallInBuildFolder) != 0 &&
                                               PostprocessBuildPlayer.SupportsInstallInBuildFolder(buildTargetGroup, target);
                if (!willInstallInBuildFolder)
                {
                    errorMessage =
                        "The 'locationPathName' parameter for BuildPipeline.BuildPlayer should not be null or empty.";
                    return(false);
                }
            }
            else if (string.IsNullOrEmpty(Path.GetFileName(locationPathName)))
            {
                var extensionForBuildTarget = PostprocessBuildPlayer.GetExtensionForBuildTarget(buildTargetGroup, target, options);

                if (!string.IsNullOrEmpty(extensionForBuildTarget))
                {
                    errorMessage = string.Format(
                        "For the '{0}' target the 'locationPathName' parameter for BuildPipeline.BuildPlayer should not end with a directory separator.\n" +
                        "Provided path: '{1}', expected a path with the extension '.{2}'.", target, locationPathName,
                        extensionForBuildTarget);
                    return(false);
                }
            }

            errorMessage = "";

            return(true);
        }
		public static void Postprocess(BuildTarget target, string installPath, string companyName, string productName, int width, int height, string downloadWebplayerUrl, string manualDownloadWebplayerUrl, BuildOptions options, RuntimeClassRegistry usedClassRegistry, BuildReport report)
		{
			string stagingArea = "Temp/StagingArea";
			string stagingAreaData = "Temp/StagingArea/Data";
			string stagingAreaDataManaged = "Temp/StagingArea/Data/Managed";
			string playbackEngineDirectory = BuildPipeline.GetPlaybackEngineDirectory(target, options);
			bool flag = (options & BuildOptions.InstallInBuildFolder) != BuildOptions.None && PostprocessBuildPlayer.SupportsInstallInBuildFolder(target);
			if (installPath == string.Empty && !flag)
			{
				throw new Exception(installPath + " must not be an empty string");
			}
			IBuildPostprocessor buildPostProcessor = ModuleManager.GetBuildPostProcessor(target);
			if (buildPostProcessor != null)
			{
				BuildPostProcessArgs args;
				args.target = target;
				args.stagingAreaData = stagingAreaData;
				args.stagingArea = stagingArea;
				args.stagingAreaDataManaged = stagingAreaDataManaged;
				args.playerPackage = playbackEngineDirectory;
				args.installPath = installPath;
				args.companyName = companyName;
				args.productName = productName;
				args.productGUID = PlayerSettings.productGUID;
				args.options = options;
				args.usedClassRegistry = usedClassRegistry;
				args.report = report;
				buildPostProcessor.PostProcess(args);
				return;
			}
			throw new UnityException(string.Format("Build target '{0}' not supported", target));
		}
            internal static bool IsInstallInBuildFolderOption()
            {
                BuildTarget      buildTarget      = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
                BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;

                return(EditorUserBuildSettings.installInBuildFolder &&
                       PostprocessBuildPlayer.SupportsInstallInBuildFolder(buildTargetGroup, buildTarget) &&
                       (Unsupported.IsSourceBuild() || IsMetroPlayer(buildTarget)));
            }
            private static bool PickBuildLocation(BuildTargetGroup targetGroup, BuildTarget target, BuildOptions options, out bool updateExistingBuild)
            {
                updateExistingBuild = false;
                var previousPath = EditorUserBuildSettings.GetBuildLocation(target);

                string defaultFolder;
                string defaultName;

                if (previousPath == String.Empty)
                {
                    defaultFolder = FileUtil.DeleteLastPathNameComponent(Application.dataPath);
                    defaultName   = "";
                }
                else
                {
                    defaultFolder = FileUtil.DeleteLastPathNameComponent(previousPath);
                    defaultName   = FileUtil.GetLastPathNameComponent(previousPath);
                }

                string extension = PostprocessBuildPlayer.GetExtensionForBuildTarget(targetGroup, target, options);

                // Invalidate default name, if extension mismatches the default file (for ex., when switching between folder type export to file type export, see Android)
                if (extension != Path.GetExtension(defaultName).Replace(".", ""))
                {
                    defaultName = string.Empty;
                }

                // Hack: For Windows Standalone, we want the BuildPanel to choose a folder,
                // but we don't want BuildPlayer to take a folder path because historically it took an .exe path
                // and we would be breaking tons of projects!
                bool   isWindowsStandalone = target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64;
                string realExtension       = extension;

                if (isWindowsStandalone)
                {
                    extension = string.Empty;
                    // Remove the filename.exe part from the path
                    if (!string.IsNullOrEmpty(defaultName))
                    {
                        defaultName = Path.GetDirectoryName(defaultName);
                    }
                }

                string title = "Build " + BuildPlatforms.instance.GetBuildTargetDisplayName(targetGroup, target);
                string path  = EditorUtility.SaveBuildPanel(target, title, defaultFolder, defaultName, extension, out updateExistingBuild);

                if (path == string.Empty)
                {
                    return(false);
                }

                if (isWindowsStandalone)
                {
                    extension = realExtension;
                    path      = Path.Combine(path, Paths.MakeValidFileName(PlayerSettings.productName) + '.' + extension);
                }

                if (!IsBuildPathValid(path))
                {
                    return(false);
                }

                // Enforce extension if needed
                if (extension != string.Empty && FileUtil.GetPathExtension(path).ToLower() != extension)
                {
                    path += '.' + extension;
                }

                // A path may not be empty initially, but it could contain, e.g., a drive letter (as in Windows),
                // so even appending an extension will work fine, but in reality the name will be, for example,
                // G:/
                //Debug.Log(path);

                string currentlyChosenName = FileUtil.GetLastPathNameComponent(path);

                if (currentlyChosenName == string.Empty)
                {
                    return(false); // No nameless projects, please
                }
                // We don't want to re-create a directory that already exists, this may
                // result in access-denials that will make users unhappy.
                string check_dir = extension != string.Empty ? FileUtil.DeleteLastPathNameComponent(path) : path;

                if (!Directory.Exists(check_dir))
                {
                    Directory.CreateDirectory(check_dir);
                }

                // On OSX we've got replace/update dialog, for other platforms warn about deleting
                // files in target folder.
                if ((target == BuildTarget.iOS) && (Application.platform != RuntimePlatform.OSXEditor))
                {
                    if (!FolderIsEmpty(path) && !UserWantsToDeleteFiles(path))
                    {
                        return(false);
                    }
                }

                EditorUserBuildSettings.SetBuildLocation(target, path);
                return(true);
            }
            internal static BuildPlayerOptions GetBuildPlayerOptionsInternal(bool askForBuildLocation, BuildPlayerOptions defaultBuildPlayerOptions)
            {
                var options = defaultBuildPlayerOptions;

                bool updateExistingBuild = false;

                BuildTarget      buildTarget      = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
                BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;

                // Pick location for the build
                string newLocation = "";

                //Check if Lz4 is supported for the current buildtargetgroup and enable it if need be
                if (PostprocessBuildPlayer.SupportsLz4Compression(buildTargetGroup, buildTarget))
                {
                    if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4)
                    {
                        options.options |= BuildOptions.CompressWithLz4;
                    }
                    else if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4HC)
                    {
                        options.options |= BuildOptions.CompressWithLz4HC;
                    }
                }

                bool developmentBuild = EditorUserBuildSettings.development;

                if (developmentBuild)
                {
                    options.options |= BuildOptions.Development;
                }
                if (EditorUserBuildSettings.datalessPlayer && developmentBuild)
                {
                    options.options |= BuildOptionsExperimental.DatalessPlayer;
                }
                if (EditorUserBuildSettings.allowDebugging && developmentBuild)
                {
                    options.options |= BuildOptions.AllowDebugging;
                }
                if (EditorUserBuildSettings.symlinkLibraries)
                {
                    options.options |= BuildOptions.SymlinkLibraries;
                }
                if (EditorUserBuildSettings.enableHeadlessMode)
                {
                    options.options |= BuildOptions.EnableHeadlessMode;
                }
                if (EditorUserBuildSettings.connectProfiler && (developmentBuild || buildTarget == BuildTarget.WSAPlayer))
                {
                    options.options |= BuildOptions.ConnectWithProfiler;
                }
                if (EditorUserBuildSettings.buildScriptsOnly)
                {
                    options.options |= BuildOptions.BuildScriptsOnly;
                }

                if (IsInstallInBuildFolderOption())
                {
                    options.options |= BuildOptions.InstallInBuildFolder;
                }
                else
                {
                    if (askForBuildLocation && !PickBuildLocation(buildTargetGroup, buildTarget, options.options, out updateExistingBuild))
                    {
                        throw new BuildMethodException();
                    }

                    newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);

                    if (newLocation.Length == 0)
                    {
                        throw new BuildMethodException("Build location for buildTarget " + buildTarget.ToString() + "is not valid.");
                    }

                    if (!askForBuildLocation)
                    {
                        switch (UnityEditorInternal.InternalEditorUtility.BuildCanBeAppended(buildTarget, newLocation))
                        {
                        case CanAppendBuild.Unsupported:
                            break;

                        case CanAppendBuild.Yes:
                            updateExistingBuild = true;
                            break;

                        case CanAppendBuild.No:
                            if (!PickBuildLocation(buildTargetGroup, buildTarget, options.options, out updateExistingBuild))
                            {
                                throw new BuildMethodException();
                            }

                            newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);
                            if (!BuildLocationIsValid(newLocation))
                            {
                                throw new BuildMethodException("Build location for buildTarget " + buildTarget.ToString() + "is not valid.");
                            }

                            break;
                        }
                    }
                }

                if (updateExistingBuild)
                {
                    options.options |= BuildOptions.AcceptExternalModificationsToPlayer;
                }

                options.target                  = buildTarget;
                options.targetGroup             = buildTargetGroup;
                options.locationPathName        = EditorUserBuildSettings.GetBuildLocation(buildTarget);
                options.assetBundleManifestPath = null;

                // Build a list of scenes that are enabled
                ArrayList scenesList = new ArrayList();

                EditorBuildSettingsScene[] editorScenes = EditorBuildSettings.scenes;
                foreach (EditorBuildSettingsScene scene in editorScenes)
                {
                    if (scene.enabled)
                    {
                        scenesList.Add(scene.path);
                    }
                }

                options.scenes = scenesList.ToArray(typeof(string)) as string[];

                return(options);
            }
Exemplo n.º 8
0
        internal static void InstallPlugins(string destPluginFolder, BuildTarget target)
        {
            string str1 = "Assets/Plugins";
            IBuildPostprocessor buildPostProcessor = ModuleManager.GetBuildPostProcessor(target);

            if (buildPostProcessor != null)
            {
                bool     shouldRetainStructure;
                string[] pluginFilesToCopy = buildPostProcessor.FindPluginFilesToCopy(str1, out shouldRetainStructure);
                if (pluginFilesToCopy != null)
                {
                    if (pluginFilesToCopy.Length > 0 && !Directory.Exists(destPluginFolder))
                    {
                        Directory.CreateDirectory(destPluginFolder);
                    }
                    foreach (string str2 in pluginFilesToCopy)
                    {
                        if (Directory.Exists(str2))
                        {
                            string target1 = Path.Combine(destPluginFolder, str2);
                            FileUtil.CopyDirectoryRecursive(str2, target1);
                        }
                        else
                        {
                            string fileName = Path.GetFileName(str2);
                            if (shouldRetainStructure)
                            {
                                string directoryName = Path.GetDirectoryName(str2.Substring(str1.Length + 1));
                                string str3          = Path.Combine(destPluginFolder, directoryName);
                                string to            = Path.Combine(str3, fileName);
                                if (!Directory.Exists(str3))
                                {
                                    Directory.CreateDirectory(str3);
                                }
                                FileUtil.UnityFileCopy(str2, to, true);
                            }
                            else
                            {
                                string to = Path.Combine(destPluginFolder, fileName);
                                FileUtil.UnityFileCopy(str2, to, true);
                            }
                        }
                    }
                    return;
                }
            }
            bool          flag1           = false;
            List <string> subdirs         = new List <string>();
            bool          flag2           = target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal;
            bool          copyDirectories = flag2;
            string        extension       = string.Empty;
            string        debugExtension  = string.Empty;

            if (flag2)
            {
                extension = ".bundle";
                subdirs.Add(string.Empty);
            }
            else if (target == BuildTarget.StandaloneWindows)
            {
                extension      = ".dll";
                debugExtension = ".pdb";
                PostprocessBuildPlayer.AddPluginSubdirIfExists(subdirs, str1, PostprocessBuildPlayer.subDir32Bit);
            }
            else if (target == BuildTarget.StandaloneWindows64)
            {
                extension      = ".dll";
                debugExtension = ".pdb";
                PostprocessBuildPlayer.AddPluginSubdirIfExists(subdirs, str1, PostprocessBuildPlayer.subDir64Bit);
            }
            else if (target == BuildTarget.StandaloneGLESEmu)
            {
                extension      = ".dll";
                debugExtension = ".pdb";
                subdirs.Add(string.Empty);
            }
            else if (target == BuildTarget.StandaloneLinux)
            {
                extension = ".so";
                PostprocessBuildPlayer.AddPluginSubdirIfExists(subdirs, str1, PostprocessBuildPlayer.subDir32Bit);
            }
            else if (target == BuildTarget.StandaloneLinux64)
            {
                extension = ".so";
                PostprocessBuildPlayer.AddPluginSubdirIfExists(subdirs, str1, PostprocessBuildPlayer.subDir64Bit);
            }
            else if (target == BuildTarget.StandaloneLinuxUniversal)
            {
                extension = ".so";
                subdirs.Add(PostprocessBuildPlayer.subDir32Bit);
                subdirs.Add(PostprocessBuildPlayer.subDir64Bit);
                flag1 = true;
            }
            else if (target == BuildTarget.PS3)
            {
                extension = ".sprx";
                subdirs.Add(string.Empty);
            }
            else if (target == BuildTarget.Android)
            {
                extension = ".so";
                subdirs.Add("Android");
            }
            else if (target == BuildTarget.BlackBerry)
            {
                extension = ".so";
                subdirs.Add("BlackBerry");
            }
            using (List <string> .Enumerator enumerator = subdirs.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    if (flag1)
                    {
                        PostprocessBuildPlayer.InstallPluginsByExtension(Path.Combine(str1, current), extension, debugExtension, Path.Combine(destPluginFolder, current), copyDirectories);
                    }
                    else
                    {
                        PostprocessBuildPlayer.InstallPluginsByExtension(Path.Combine(str1, current), extension, debugExtension, destPluginFolder, copyDirectories);
                    }
                }
            }
        }
        void ShowBuildTargetSettings()
        {
            EditorGUIUtility.labelWidth = Mathf.Min(180, (position.width - 265) * 0.47f);

            BuildTarget      buildTarget      = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
            BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
            BuildPlatform    platform         = BuildPlatforms.instance.BuildPlatformFromTargetGroup(buildTargetGroup);
            bool             licensed         = BuildPipeline.LicenseCheck(buildTarget);

            // Draw the group name
            GUILayout.Space(18);

            // Draw icon and text of title separately so we can control the space between them
            Rect r = GUILayoutUtility.GetRect(50, 36);

            r.x += 1;
            GUI.Label(new Rect(r.x + 3, r.y + 3, 32, 32), platform.title.image, GUIStyle.none);
            GUI.Toggle(r, false, platform.title.text, styles.platformSelector);

            GUILayout.Space(10);

            if (platform.targetGroup == BuildTargetGroup.WebGL && !BuildPipeline.IsBuildTargetSupported(platform.targetGroup, buildTarget))
            {
                if (IntPtr.Size == 4)
                {
                    GUILayout.Label("Building for WebGL requires a 64-bit Unity editor.");
                    GUIBuildButtons(false, false, false, platform);
                    return;
                }
            }

            string moduleName = Modules.ModuleManager.GetTargetStringFrom(buildTargetGroup, buildTarget);

            if (IsModuleNotInstalled(buildTargetGroup, buildTarget))
            {
                GUILayout.Label(EditorGUIUtility.TextContent(string.Format(styles.noModuleLoaded, BuildPlatforms.instance.GetModuleDisplayName(buildTargetGroup, buildTarget))));
                if (GUILayout.Button(styles.openDownloadPage, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                {
                    string url = GetPlaybackEngineDownloadURL(moduleName);
                    Help.BrowseURL(url);
                }
                GUIBuildButtons(false, false, false, platform);
                return;
            }
            else if (Application.HasProLicense() && !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(buildTarget))
            {
                // Show copy for using personal edition build targets with pro edition editor
                string infoText = string.Format(styles.infoText,
                                                BuildPlatforms.instance.GetBuildTargetDisplayName(buildTargetGroup, buildTarget));

                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Label(infoText, EditorStyles.wordWrappedMiniLabel);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(styles.eula, EditorStyles.miniButton))
                {
                    Application.OpenURL("http://unity3d.com/legal/eula");
                }
                if (GUILayout.Button(string.Format(styles.addToYourPro, BuildPlatforms.instance.GetBuildTargetDisplayName(buildTargetGroup, buildTarget)), EditorStyles.miniButton))
                {
                    Application.OpenURL("http://unity3d.com/get-unity");
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }

            GUIContent error = styles.GetDownloadErrorForTarget(buildTarget);

            if (error != null)
            {
                GUILayout.Label(error, EditorStyles.wordWrappedLabel);
                GUIBuildButtons(false, false, false, platform);
                return;
            }

            // Draw not licensed buy now UI
            if (!licensed)
            {
                string niceName   = BuildPipeline.GetBuildTargetGroupDisplayName(buildTargetGroup);
                string licenseMsg = "Your license does not cover {0} Publishing.";
                string buttonMsg  = "Go to Our Online Store";
                if (BuildTargetDiscovery.PlatformHasFlag(buildTarget, TargetAttributes.IsConsole))
                {
                    licenseMsg += "Please see the {0} section of the Platform Module Installation documentation for more details.";
                    buttonMsg   = "Platform Module Installation";
                }
                else if (BuildTargetDiscovery.PlatformHasFlag(buildTarget, TargetAttributes.IsStandalonePlatform))
                {
                    buttonMsg = "";
                }

                GUIContent[] notLicensedMessage =
                {
                    EditorGUIUtility.TextContent(string.Format(L10n.Tr(licenseMsg), niceName)),
                    EditorGUIUtility.TextContent(L10n.Tr(buttonMsg)),
                    new GUIContent(styles.shopURL)
                };

                GUILayout.Label(notLicensedMessage[0], EditorStyles.wordWrappedLabel);
                GUILayout.Space(5);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (notLicensedMessage[1].text.Length != 0)
                {
                    if (GUILayout.Button(notLicensedMessage[1]))
                    {
                        Application.OpenURL(notLicensedMessage[2].text);
                    }
                }
                GUILayout.EndHorizontal();
                GUIBuildButtons(false, false, false, platform);
                return;
            }

            // FIXME: WHY IS THIS ALL IN ONE FUNCTION?!
            // Draw the side bar to the right. Different options like specific Standalone player to build, profiling and debugging options, etc.
            string module = ModuleManager.GetTargetStringFrom(platform.targetGroup, buildTarget);
            IBuildWindowExtension buildWindowExtension = ModuleManager.GetBuildWindowExtension(module);

            if (buildWindowExtension != null)
            {
                buildWindowExtension.ShowPlatformBuildOptions();
            }

            GUI.changed = false;
            GUI.enabled = true;

            bool enableBuildButton = buildWindowExtension != null?buildWindowExtension.EnabledBuildButton() : true;

            bool enableBuildAndRunButton = false;

            bool shouldDrawDebuggingToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawScriptDebuggingCheckbox() : true;

            bool shouldDrawExplicitNullChecksToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawExplicitNullCheckbox() : false;

            bool shouldDrawDivideByZeroChecksToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawExplicitDivideByZeroCheckbox() : false;

            bool shouldDrawArrayBoundsChecksToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawExplicitArrayBoundsCheckbox() : false;

            bool shouldDrawDevelopmentPlayerToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawDevelopmentPlayerCheckbox() : true;

            IBuildPostprocessor postprocessor = ModuleManager.GetBuildPostProcessor(buildTargetGroup, buildTarget);
            bool enableBuildScriptsOnly       = (postprocessor != null ? postprocessor.SupportsScriptsOnlyBuild() : false);
            bool canInstallInBuildFolder      = false;

            if (BuildPipeline.IsBuildTargetSupported(buildTargetGroup, buildTarget))
            {
                bool shouldDrawConnectProfilerToggle = buildWindowExtension != null?buildWindowExtension.ShouldDrawProfilerCheckbox() : true;

                GUI.enabled = shouldDrawDevelopmentPlayerToggle;
                if (shouldDrawDevelopmentPlayerToggle)
                {
                    EditorUserBuildSettings.development = EditorGUILayout.Toggle(styles.debugBuild, EditorUserBuildSettings.development);
                }

                bool developmentBuild = EditorUserBuildSettings.development;

                GUI.enabled = developmentBuild;

                if (shouldDrawConnectProfilerToggle)
                {
                    if (!GUI.enabled)
                    {
                        if (!developmentBuild)
                        {
                            styles.profileBuild.tooltip = "Profiling only enabled in Development Player";
                        }
                    }
                    else
                    {
                        styles.profileBuild.tooltip = "";
                    }
                    EditorUserBuildSettings.connectProfiler = EditorGUILayout.Toggle(styles.profileBuild, EditorUserBuildSettings.connectProfiler);
                }

                GUI.enabled = developmentBuild;
                if (shouldDrawDebuggingToggle)
                {
                    using (new EditorGUI.DisabledScope(buildWindowExtension != null ? buildWindowExtension.ShouldDisableManagedDebuggerCheckboxes() : false))
                    {
                        EditorUserBuildSettings.allowDebugging = EditorGUILayout.Toggle(styles.allowDebugging, EditorUserBuildSettings.allowDebugging);

                        // Not all platforms have native dialog implemented in Runtime\Misc\GiveDebuggerChanceToAttachIfRequired.cpp
                        // Display this option only for developer builds
                        bool shouldDrawWaitForManagedDebugger = buildWindowExtension != null?buildWindowExtension.ShouldDrawWaitForManagedDebugger() : false;

                        if (EditorUserBuildSettings.allowDebugging && shouldDrawWaitForManagedDebugger)
                        {
                            var buildTargetName = BuildPipeline.GetBuildTargetName(buildTarget);

                            bool value = EditorGUILayout.Toggle(styles.waitForManagedDebugger, EditorUserBuildSettings.GetPlatformSettings(buildTargetName, kSettingDebuggingWaitForManagedDebugger) == "true");
                            EditorUserBuildSettings.SetPlatformSettings(buildTargetName, kSettingDebuggingWaitForManagedDebugger, value.ToString().ToLower());
                        }
                    }

                    if (EditorUserBuildSettings.allowDebugging && PlayerSettings.GetScriptingBackend(buildTargetGroup) == ScriptingImplementation.IL2CPP)
                    {
                        var  apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);
                        bool isDebuggerUsable      = apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6 || apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0;

                        if (!isDebuggerUsable)
                        {
                            EditorGUILayout.HelpBox("Script debugging is only supported with IL2CPP on .NET 4.x and .NET Standard 2.0 API Compatibility Levels.", MessageType.Warning);
                        }
                    }
                }


                if (shouldDrawExplicitNullChecksToggle)
                {
                    // Force 'ExplicitNullChecks' to true if it's a development build.
                    GUI.enabled = !developmentBuild;
                    if (GUI.enabled == false)
                    {
                        EditorUserBuildSettings.explicitNullChecks = true;
                    }
                    EditorUserBuildSettings.explicitNullChecks = EditorGUILayout.Toggle(styles.explicitNullChecks, EditorUserBuildSettings.explicitNullChecks);
                    // Undo force from above
                    GUI.enabled = developmentBuild;
                }

                if (shouldDrawDivideByZeroChecksToggle)
                {
                    // Force 'explicitDivideByZeroChecks' to true if it's a development build.
                    GUI.enabled = !developmentBuild;
                    if (GUI.enabled == false)
                    {
                        EditorUserBuildSettings.explicitDivideByZeroChecks = true;
                    }
                    EditorUserBuildSettings.explicitDivideByZeroChecks = EditorGUILayout.Toggle(styles.explicitDivideByZeroChecks, EditorUserBuildSettings.explicitDivideByZeroChecks);
                    // Undo force from above
                    GUI.enabled = developmentBuild;
                }

                if (shouldDrawArrayBoundsChecksToggle)
                {
                    // Force 'explicitArrayBoundsChecks' to true if it's a development build.
                    GUI.enabled = !developmentBuild;
                    if (GUI.enabled == false)
                    {
                        EditorUserBuildSettings.explicitArrayBoundsChecks = true;
                    }
                    EditorUserBuildSettings.explicitArrayBoundsChecks = EditorGUILayout.Toggle(styles.explicitArrayBoundsChecks, EditorUserBuildSettings.explicitArrayBoundsChecks);
                    // Undo force from above
                    GUI.enabled = developmentBuild;
                }

                if (buildWindowExtension != null && enableBuildScriptsOnly)
                {
                    buildWindowExtension.DoScriptsOnlyGUI();
                }

                GUI.enabled = true;

                GUILayout.FlexibleSpace();

                if (postprocessor != null && postprocessor.SupportsLz4Compression())
                {
                    var cmpIdx = Array.IndexOf(styles.compressionTypes, EditorUserBuildSettings.GetCompressionType(buildTargetGroup));
                    if (cmpIdx == -1)
                    {
                        cmpIdx = 1; // Lz4 by default.
                    }
                    cmpIdx = EditorGUILayout.Popup(styles.compressionMethod, cmpIdx, styles.compressionStrings);
                    EditorUserBuildSettings.SetCompressionType(buildTargetGroup, styles.compressionTypes[cmpIdx]);
                }

                canInstallInBuildFolder = Unsupported.IsSourceBuild() && PostprocessBuildPlayer.SupportsInstallInBuildFolder(buildTargetGroup, buildTarget);

                if (enableBuildButton)
                {
                    enableBuildAndRunButton = buildWindowExtension != null?buildWindowExtension.EnabledBuildAndRunButton() &&
                                              !(EditorUserBuildSettings.installInBuildFolder) : !(EditorUserBuildSettings.installInBuildFolder);
                }
            }
            else
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

                GUILayout.BeginVertical(GUILayout.ExpandWidth(true));

                GUILayout.Label(string.Format(L10n.Tr("{0} is not supported in this build.\nDownload a build that supports it."), BuildPipeline.GetBuildTargetGroupDisplayName(buildTargetGroup)));

                GUILayout.EndVertical();
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            if (buildTarget == BuildTarget.Android)
            {
                AndroidPublishGUI();
            }

            GUIBuildButtons(buildWindowExtension, enableBuildButton, enableBuildAndRunButton,
                            canInstallInBuildFolder, platform);
        }
Exemplo n.º 10
0
 internal static void InstallStreamingAssets(string stagingAreaDataPath)
 {
     PostprocessBuildPlayer.InstallStreamingAssets(stagingAreaDataPath, null);
 }
        internal static void InstallPlugins(string destPluginFolder, BuildTarget target)
        {
            string text = "Assets/Plugins";
            IBuildPostprocessor buildPostProcessor = ModuleManager.GetBuildPostProcessor(target);

            if (buildPostProcessor != null)
            {
                bool     flag;
                string[] array = buildPostProcessor.FindPluginFilesToCopy(text, out flag);
                if (array != null)
                {
                    if (array.Length > 0 && !Directory.Exists(destPluginFolder))
                    {
                        Directory.CreateDirectory(destPluginFolder);
                    }
                    string[] array2 = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        string text2 = array2[i];
                        if (Directory.Exists(text2))
                        {
                            string target2 = Path.Combine(destPluginFolder, text2);
                            FileUtil.CopyDirectoryRecursive(text2, target2);
                        }
                        else
                        {
                            string fileName = Path.GetFileName(text2);
                            if (flag)
                            {
                                string directoryName = Path.GetDirectoryName(text2.Substring(text.Length + 1));
                                string text3         = Path.Combine(destPluginFolder, directoryName);
                                string to            = Path.Combine(text3, fileName);
                                if (!Directory.Exists(text3))
                                {
                                    Directory.CreateDirectory(text3);
                                }
                                FileUtil.UnityFileCopy(text2, to);
                            }
                            else
                            {
                                string to2 = Path.Combine(destPluginFolder, fileName);
                                FileUtil.UnityFileCopy(text2, to2);
                            }
                        }
                    }
                    return;
                }
            }
            bool          flag2           = false;
            List <string> list            = new List <string>();
            bool          flag3           = target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal;
            bool          copyDirectories = flag3;
            string        extension       = string.Empty;
            string        debugExtension  = string.Empty;

            if (flag3)
            {
                extension = ".bundle";
                list.Add(string.Empty);
            }
            else
            {
                if (target == BuildTarget.StandaloneWindows)
                {
                    extension      = ".dll";
                    debugExtension = ".pdb";
                    PostprocessBuildPlayer.AddPluginSubdirIfExists(list, text, PostprocessBuildPlayer.subDir32Bit);
                }
                else
                {
                    if (target == BuildTarget.StandaloneWindows64)
                    {
                        extension      = ".dll";
                        debugExtension = ".pdb";
                        PostprocessBuildPlayer.AddPluginSubdirIfExists(list, text, PostprocessBuildPlayer.subDir64Bit);
                    }
                    else
                    {
                        if (target == BuildTarget.StandaloneGLESEmu)
                        {
                            extension      = ".dll";
                            debugExtension = ".pdb";
                            list.Add(string.Empty);
                        }
                        else
                        {
                            if (target == BuildTarget.StandaloneLinux)
                            {
                                extension = ".so";
                                PostprocessBuildPlayer.AddPluginSubdirIfExists(list, text, PostprocessBuildPlayer.subDir32Bit);
                            }
                            else
                            {
                                if (target == BuildTarget.StandaloneLinux64)
                                {
                                    extension = ".so";
                                    PostprocessBuildPlayer.AddPluginSubdirIfExists(list, text, PostprocessBuildPlayer.subDir64Bit);
                                }
                                else
                                {
                                    if (target == BuildTarget.StandaloneLinuxUniversal)
                                    {
                                        extension = ".so";
                                        list.Add(PostprocessBuildPlayer.subDir32Bit);
                                        list.Add(PostprocessBuildPlayer.subDir64Bit);
                                        flag2 = true;
                                    }
                                    else
                                    {
                                        if (target == BuildTarget.PS3)
                                        {
                                            extension = ".sprx";
                                            list.Add(string.Empty);
                                        }
                                        else
                                        {
                                            if (target == BuildTarget.Android)
                                            {
                                                extension = ".so";
                                                list.Add("Android");
                                            }
                                            else
                                            {
                                                if (target == BuildTarget.BB10)
                                                {
                                                    extension = ".so";
                                                    list.Add("BlackBerry");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            foreach (string current in list)
            {
                if (flag2)
                {
                    PostprocessBuildPlayer.InstallPluginsByExtension(Path.Combine(text, current), extension, debugExtension, Path.Combine(destPluginFolder, current), copyDirectories);
                }
                else
                {
                    PostprocessBuildPlayer.InstallPluginsByExtension(Path.Combine(text, current), extension, debugExtension, destPluginFolder, copyDirectories);
                }
            }
        }
Exemplo n.º 12
0
            /// <summary>
            /// Default implementation of the build player method.
            /// </summary>
            /// <param name="options"></param>
            public static void BuildPlayer(BuildPlayerOptions options)
            {
                if (!UnityConnect.instance.canBuildWithUPID)
                {
                    if (!EditorUtility.DisplayDialog("Missing Project ID", "Because you are not a member of this project this build will not access Unity services.\nDo you want to continue?", "Yes", "No"))
                    {
                        throw new BuildMethodException();
                    }
                }

                if (!BuildPipeline.IsBuildTargetSupported(options.targetGroup, options.target))
                {
                    throw new BuildMethodException("Build target is not supported.");
                }

                string module = ModuleManager.GetTargetStringFrom(EditorUserBuildSettings.selectedBuildTargetGroup, options.target);
                IBuildWindowExtension buildWindowExtension = ModuleManager.GetBuildWindowExtension(module);

                if (buildWindowExtension != null && (options.options & BuildOptions.AutoRunPlayer) != 0 && !buildWindowExtension.EnabledBuildAndRunButton())
                {
                    throw new BuildMethodException();
                }

                if (Unsupported.IsBleedingEdgeBuild())
                {
                    var sb = new System.Text.StringBuilder();
                    sb.AppendLine("This version of Unity is a BleedingEdge build that has not seen any manual testing.");
                    sb.AppendLine("You should consider this build unstable.");
                    sb.AppendLine("We strongly recommend that you use a normal version of Unity instead.");

                    if (EditorUtility.DisplayDialog("BleedingEdge Build", sb.ToString(), "Cancel", "OK"))
                    {
                        throw new BuildMethodException();
                    }
                }

                // See if we need to switch platforms and delay the build.  We do this whenever
                // we're trying to build for a target different from the active one so as to ensure
                // that the compiled script code we have loaded is built for the same platform we
                // are building for.  As we can't reload while our editor stuff is still executing,
                // we need to defer to after the next script reload then.
                bool delayToAfterScriptReload = false;

                if (EditorUserBuildSettings.activeBuildTarget != options.target ||
                    EditorUserBuildSettings.activeBuildTargetGroup != options.targetGroup)
                {
                    if (!EditorUserBuildSettings.SwitchActiveBuildTargetAsync(options.targetGroup, options.target))
                    {
                        // Switching the build target failed.  No point in trying to continue
                        // with a build.
                        var errStr = string.Format("Could not switch to build target '{0}', '{1}'.",
                                                   BuildPipeline.GetBuildTargetGroupDisplayName(options.targetGroup),
                                                   BuildPlatforms.instance.GetBuildTargetDisplayName(options.targetGroup, options.target, options.subtarget));
                        throw new BuildMethodException(errStr);
                    }

                    if (EditorApplication.isCompiling)
                    {
                        delayToAfterScriptReload = true;
                    }
                }

                bool locationPathExistedBeforeBuild = System.IO.Directory.Exists(options.locationPathName);
                // Trigger build.
                // Note: report will be null, if delayToAfterScriptReload = true
                var report = BuildPipeline.BuildPlayerInternalNoCheck(options.scenes, options.locationPathName, PostprocessBuildPlayer.GetStreamingAssetsBundleManifestPath(), options.targetGroup, options.target, options.subtarget, options.options, options.extraScriptingDefines, delayToAfterScriptReload);

                if (report != null
                    )
                {
                    var resultStr = String.Format("Build completed with a result of '{0}' in {1} seconds ({2} ms)",
                                                  report.summary.result.ToString("g"),
                                                  Convert.ToInt32(report.summary.totalTime.TotalSeconds),
                                                  Convert.ToInt32(report.summary.totalTime.TotalMilliseconds));

                    switch (report.summary.result)
                    {
                    case Build.Reporting.BuildResult.Unknown:
                        Debug.LogWarning(resultStr);
                        break;

                    case Build.Reporting.BuildResult.Failed:
                        //  On some platforms the user creates the build folder, therefore they own the folder and
                        // it should not be automatically deleted by the Unity Editor, even if it is empty (case 1073851)
                        if (options.target != BuildTarget.XboxOne && !locationPathExistedBeforeBuild)
                        {
                            DeleteBuildFolderIfEmpty(report.summary.outputPath);
                        }
                        Debug.LogError(resultStr);
                        throw new BuildMethodException(report.SummarizeErrors());

                    default:
                        Debug.Log(resultStr);
                        break;
                    }

                    buildCompletionHandler?.Invoke(report);
                }
            }