50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Ether
|
|
{
|
|
public class BuildEditor
|
|
{
|
|
[MenuItem("打包/windows")]
|
|
public static void BuildWindows()
|
|
{
|
|
List<string> sceneList = new List<string>();
|
|
|
|
for (int i = 0; i < EditorSceneManager.sceneCountInBuildSettings; i++)
|
|
{
|
|
string scenePath = SceneUtility.GetScenePathByBuildIndex(i);
|
|
if (!string.IsNullOrEmpty(scenePath))
|
|
{
|
|
Debug.Log($"添加场景:{scenePath}");
|
|
sceneList.Add(scenePath);
|
|
}
|
|
}
|
|
|
|
|
|
string projectRootPath = new DirectoryInfo(Application.dataPath).Parent.FullName;
|
|
|
|
if (Directory.Exists($"{projectRootPath}/Build/Windows/"))
|
|
{
|
|
Directory.Delete($"{projectRootPath}/Build/Windows/", true);
|
|
}
|
|
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
|
{
|
|
scenes = sceneList.ToArray(),
|
|
target = BuildTarget.StandaloneWindows64,
|
|
subtarget = (int)StandaloneBuildSubtarget.Player,
|
|
locationPathName = $"{projectRootPath}/Build/Windows/client.exe",
|
|
};
|
|
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|
Application.OpenURL($"{projectRootPath}/Build/Windows");
|
|
Debug.Log("打包windows成功");
|
|
}
|
|
}
|
|
}
|