コード例 #1
0
        bool BuildPlatform(Platform p)
        {
            var progress = new EditorProgressBar(null, p.targets.Length * 2);

            foreach (var target in p.targets)
            {
                progress.description = "Building " + p.name + " - [" + target + "]";

                var buildPath = Platform.GetTargetPath(target);

                try {
                    RecursiveDeleteDirectory(buildPath);
                } catch (Exception e) {
                    if (!(e is DirectoryNotFoundException))
                    {
                        Debug.LogException(e);
                        EditorUtility.DisplayDialog("Error", "Unable to clean build path: '" + buildPath + "' for " + p.name, "OK");
                        progress.Close();
                        return(false);
                    }
                }

                try {
                    Directory.CreateDirectory(buildPath);
                } catch (Exception e) {
                    Debug.LogException(e);
                    EditorUtility.DisplayDialog("Error", "Unable to create build path: '" + buildPath + "' for " + p.name, "OK");
                    progress.Close();
                    return(false);
                }

                List <string> levels = new List <string>();
                for (int i = 0; i < STATIC_LEVELS.Length; ++i)
                {
                    levels.Add(STATIC_LEVELS[i]);
                }

                for (int i = 0; i < GameManager.LEVELS.Count; ++i)
                {
                    var level = GameManager.LEVELS[i];

                    levels.Add("Assets/Scenes/" + level.name + "/" + level.name + ".unity");

                    for (int k = 0; k < level.sublevels.Length; ++k)
                    {
                        levels.Add("Assets/Scenes/" + level.name + "/" + level.sublevels[k] + ".unity");
                    }
                }

                BuildOptions options = BuildOptions.ForceEnableAssertions;

                var buildFlags = scriptFlags;

                if (buildFlags.Contains("PROFILING"))
                {
                    options |= BuildOptions.Development;
                }
                if (p.deployment == EDeploymentType.BackendServer)
                {
                    options |= BuildOptions.EnableHeadlessMode;

                    buildFlags = BuildOptionsWindow.AddDefine(buildFlags, "DEDICATED_SERVER");
                    buildFlags = BuildOptionsWindow.AddDefine(buildFlags, "BACKEND_SERVER");
                    buildFlags = BuildOptionsWindow.RemoveDefine(buildFlags, "LOGIN_SERVER");
                    buildFlags = BuildOptionsWindow.RemoveDefine(buildFlags, "STEAM_API");
                }

                if (buildFlags != PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone))
                {
                    PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, buildFlags);
                }

                var report = BuildPipeline.BuildPlayer(levels.ToArray(), Platform.GetAppPath(target), target, options);

                // TODO:

                //if (!string.IsNullOrEmpty(err)) {
                //	EditorUtility.DisplayDialog("Error", err, "OK");
                //	progress.Close();
                //	return false;
                //}

                if (p.deployment == EDeploymentType.BackendServer)
                {
                    if (!CopyTelemetry(buildPath))
                    {
                        EditorUtility.DisplayDialog("Error", "Failed to copy telemetry.", "OK");
                        progress.Close();
                        return(false);
                    }
                }

                RecursiveClearReadonlyState(buildPath);

                if (target == BuildTarget.StandaloneWindows)
                {
                    // need to copy steam over...
                    try {
                        File.Move(Path.Combine(Platform.GetTargetPath(target), "Deadhold_Data/Plugins/steam_api.dll"), Path.Combine(Platform.GetTargetPath(target), "steam_api.dll"));
                    } catch (Exception) { }
                }

                progress.Step(null);
                if (BuildOptionsWindow.IsDefined(buildFlags, "SHIP"))
                {
                    progress.description = "Obfuscating " + p.name + " [" + target + "]";
                    if (!ObfuscateAssembly(Platform.GetAssemblyPath(target)))
                    {
                        progress.Close();
                        return(false);
                    }
                }

                progress.Step(null);
            }

            return(true);
        }
コード例 #2
0
        void OnGUI()
        {
            EditorGUILayout.BeginVertical();

            GUILayoutHelpers.HorzLine();

            {
                var s = BuildOptionsWindow.OnGUI_ScriptFlags(scriptFlags, true);
                if (s != scriptFlags)
                {
                    EditorPrefs.SetString("steamscriptflags", s);
                    scriptFlags = s;
                }
            }

            GUILayoutHelpers.HorzLine();

            OnGUI_BuildPlatforms();

            GUILayoutHelpers.HorzLine();

#if PERFORCE
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            GUILayoutHelpers.CenterLabel("Perforce");
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            {
                var s = EditorGUILayout.TextField("P4 Directory", p4path);
                if (s != p4path)
                {
                    EditorPrefs.SetString("p4path", s);
                    p4path = s;
                }

                s = EditorGUILayout.TextField("P4 Server", p4server);
                if (s != p4server)
                {
                    EditorPrefs.SetString("p4server", s);
                    p4server = s;
                }

                s = EditorGUILayout.TextField("P4 User", p4user);
                if (s != p4user)
                {
                    EditorPrefs.SetString("p4user", s);
                    p4user = s;
                }

                s = EditorGUILayout.PasswordField("P4 Password", p4pass);
                if (s != p4pass)
                {
                    EditorPrefs.SetString("p4pass", s);
                    p4pass = s;
                }

                s = EditorGUILayout.TextField("P4 Workspace", p4client);
                if (s != p4client)
                {
                    EditorPrefs.SetString("p4client", s);
                    p4client = s;
                }
            }

            GUILayoutHelpers.HorzLine();
#endif

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            GUILayoutHelpers.CenterLabel("Steam");
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            {
                var i = 0;
                while ((branch != BRANCHES[i]) && (i < BRANCHES.Length))
                {
                    ++i;
                }

                if (i >= BRANCHES.Length)
                {
                    i = 0;
                }

                var s = EditorGUILayout.Popup("Set Live", i, BRANCHES);
                if (s != i)
                {
                    branch = BRANCHES[s];
                    EditorPrefs.SetString("steambranch", branch);
                }
            }

            {
                var s = EditorGUILayout.TextField("Steam Login", steamLogin);
                if (s != steamLogin)
                {
                    EditorPrefs.SetString("steamlogin", s);
                    steamLogin = s;
                }
            }

            {
                var s = EditorGUILayout.PasswordField("Steam Password", steamPassword);
                if (s != steamPassword)
                {
                    EditorPrefs.SetString("steampass", s);
                    steamPassword = s;
                }
            }

            GUILayoutHelpers.HorzLine();

            bool build = false;

            if (GUILayout.Button("Build (testing only!)..."))
            {
                build = true;
            }

            bool publish = false;

            if (GUILayout.Button("Build and Publish..."))
            {
                publish = true;
                build   = true;
            }

            //if (GUILayout.Button("Retry Publish (careful!)...")) {
            //	publish = true;
            //}

            EditorGUILayout.EndVertical();

            string oldScriptFlags = null;

            if (build || publish)
            {
#if PERFORCE
                if (string.IsNullOrEmpty(p4path) || string.IsNullOrEmpty(p4server) || string.IsNullOrEmpty(p4user) || string.IsNullOrEmpty(p4pass) || string.IsNullOrEmpty(p4client))
                {
                    EditorUtility.DisplayDialog("Error", "Please fill in the perforce fields to build for Steam.", "OK");
                    return;
                }
#endif
                oldScriptFlags = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
            }

            if (build && publish)
            {
                var progress = new EditorProgressBar("Building...", 2);
                var r        = CheckForPrereqs() && Build();
                if (r)
                {
                    progress.Step("Publishing...");
                    r = Publish();
                    progress.Step(null);
                }
                else
                {
                    progress.Close();
                }

                if (r)
                {
                    EditorUtility.DisplayDialog("Success", "Build and publish completed successfully.", "OK");
                }
                else
                {
                    EditorUtility.DisplayDialog("Error", "Build failed.", "OK");
                }
            }
            else if (build)
            {
                var progress = new EditorProgressBar("Building...", 1);
                var r        = CheckForPrereqs() && Build();
                progress.Step(null);
                if (r)
                {
                    EditorUtility.DisplayDialog("Success", "Build completed successfully.", "OK");
                }
                else
                {
                    EditorUtility.DisplayDialog("Error", "Build failed.", "OK");
                }
            }
            else if (publish)
            {
                var progress = new EditorProgressBar("Publishing...", 1);
                var r        = CheckForPrereqs();
                if (r)
                {
                    progress.Step("Publishing...");
                    r = Publish();
                    progress.Step(null);
                }
                else
                {
                    progress.Close();
                }

                if (r)
                {
                    EditorUtility.DisplayDialog("Success", "Publish completed successfully.", "OK");
                }
                else
                {
                    EditorUtility.DisplayDialog("Error", "Publish failed.", "OK");
                }
            }

            if (build || publish)
            {
                if (oldScriptFlags != PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone))
                {
                    PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, oldScriptFlags);
                }
            }
        }