- using UnityEngine;
- using System.Collections;
- using UnityEditor;
- using System.Collections.Generic;
- using System.IO;
- public class Tools : EditorWindow
- {
- [MenuItem("Tools/Build for Windows")]
- public static void ShowWindow()
- {
- EditorWindow.GetWindow(typeof(Tools), true, "导出Windows应用程序");
- }
- static string exePath = "";
- static List<string> allSceneName = new List<string>();
- void OnGUI()
- {
- GUILayout.Label("导出路径:", EditorStyles.boldLabel);
- GUILayout.Label(exePath, EditorStyles.boldLabel);
- if (GUILayout.Button("选择导出路径"))
- {
- exePath = EditorUtility.SaveFolderPanel("导出路径", "", "");
- }
- if (GUILayout.Button("扫描场景"))
- {
- string[] sl = Directory.GetFiles(Application.dataPath + "/Scene/");
- foreach (string file in sl)
- {
- if (!file.Contains(".meta"))
- {
- string temp = file;
- if (!allSceneName.Contains(temp))
- {
- allSceneName.Add(temp);
- }
- }
- }
- }
- if (GUILayout.Button("导出程序"))
- {
- string[] levels = new string[1];
- Debug.Log("allSceneName.Count:" + allSceneName.Count);
- if (allSceneName.Count > 0)
- {
- Debug.Log("allSceneName.Count:" + allSceneName.Count);
- for (int i = 0; i < allSceneName.Count; i++)
- {
- levels[0] = allSceneName[i];
- string temp = allSceneName[i].Replace(Application.dataPath + "/Scene/", "");
- temp = temp.Replace(".unity", "");
- string exeName = exePath + "/" + temp + ".exe";
- if (File.Exists(exeName))
- {
- File.Delete(exeName);
- Directory.Delete(exePath + "/" + temp + "_Data",true);
- }
- BuildPipeline.BuildPlayer(levels, exeName, BuildTarget.StandaloneWindows, BuildOptions.None);
- }
- }
- }
- }
- }
效果如图