Unity3D一键导出Windows程序

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



 

效果如图

Unity3D一键导出Windows程序

你可能感兴趣的:(windows)