ITeye博客

Unity3D一键导出Windows程序

wgcode · 2015-05-13 14:37 · Unity · 移动开发 · Markdown

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. public class Tools : EditorWindow
  7. {
  8. [MenuItem("Tools/Build for Windows")]
  9. public static void ShowWindow()
  10. {
  11. EditorWindow.GetWindow(typeof(Tools), true, "导出Windows应用程序");
  12. }
  13. static string exePath = "";
  14. static List<string> allSceneName = new List<string>();
  15. void OnGUI()
  16. {
  17. GUILayout.Label("导出路径:", EditorStyles.boldLabel);
  18. GUILayout.Label(exePath, EditorStyles.boldLabel);
  19. if (GUILayout.Button("选择导出路径"))
  20. {
  21. exePath = EditorUtility.SaveFolderPanel("导出路径", "", "");
  22. }
  23. if (GUILayout.Button("扫描场景"))
  24. {
  25. string[] sl = Directory.GetFiles(Application.dataPath + "/Scene/");
  26. foreach (string file in sl)
  27. {
  28. if (!file.Contains(".meta"))
  29. {
  30. string temp = file;
  31. if (!allSceneName.Contains(temp))
  32. {
  33. allSceneName.Add(temp);
  34. }
  35. }
  36. }
  37. }
  38. if (GUILayout.Button("导出程序"))
  39. {
  40. string[] levels = new string[1];
  41. Debug.Log("allSceneName.Count:" + allSceneName.Count);
  42. if (allSceneName.Count > 0)
  43. {
  44. Debug.Log("allSceneName.Count:" + allSceneName.Count);
  45. for (int i = 0; i < allSceneName.Count; i++)
  46. {
  47. levels[0] = allSceneName[i];
  48. string temp = allSceneName[i].Replace(Application.dataPath + "/Scene/", "");
  49. temp = temp.Replace(".unity", "");
  50. string exeName = exePath + "/" + temp + ".exe";
  51. if (File.Exists(exeName))
  52. {
  53. File.Delete(exeName);
  54. Directory.Delete(exePath + "/" + temp + "_Data",true);
  55. }
  56. BuildPipeline.BuildPlayer(levels, exeName, BuildTarget.StandaloneWindows, BuildOptions.None);
  57. }
  58. }
  59. }
  60. }
  61. }

 

效果如图

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。