2023-11-08 17:33:46 +08:00
|
|
|
using System;
|
2023-10-19 15:00:19 +08:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
|
|
|
|
using Sirenix.Utilities;
|
|
|
|
|
using Sirenix.Utilities.Editor;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class BuildWindow : OdinEditorWindow
|
|
|
|
|
{
|
|
|
|
|
private static BuildWindow thisWindow;
|
|
|
|
|
private List<string> profileList = new List<string>();
|
2024-02-27 15:07:59 +08:00
|
|
|
|
|
|
|
|
#if USE_ADDRESSABLES
|
2023-10-19 15:00:19 +08:00
|
|
|
private AddressableAssetSettings settings;
|
2024-02-27 15:07:59 +08:00
|
|
|
#endif
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
[MenuItem("Tools/打包工具")]
|
|
|
|
|
public static void ShowWindow()
|
|
|
|
|
{
|
|
|
|
|
thisWindow = GetWindow<BuildWindow>();
|
|
|
|
|
thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(600, 300);
|
2024-02-27 15:07:59 +08:00
|
|
|
#if USE_ADDRESSABLES
|
2023-10-19 15:00:19 +08:00
|
|
|
thisWindow.settings
|
|
|
|
|
= AssetDatabase.LoadAssetAtPath<ScriptableObject>(
|
|
|
|
|
"Assets/AddressableAssetsData/AddressableAssetSettings.asset")
|
|
|
|
|
as AddressableAssetSettings;
|
|
|
|
|
foreach (var profileName in thisWindow.settings.profileSettings.GetAllProfileNames())
|
|
|
|
|
{
|
|
|
|
|
thisWindow.profileList.Add(profileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thisWindow.separateGroup = new List<AddressableAssetGroup>();
|
|
|
|
|
foreach (var group in thisWindow.settings.groups)
|
|
|
|
|
{
|
|
|
|
|
thisWindow.separateGroup.Add(group);
|
|
|
|
|
}
|
2024-02-27 15:07:59 +08:00
|
|
|
#endif
|
2023-11-08 17:33:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
string buildTargetString = PlayerPrefs.GetString("BuildTarget");
|
|
|
|
|
if (Enum.TryParse<BuildTarget>(buildTargetString, out BuildTarget parsedBuildTarget))
|
|
|
|
|
{
|
|
|
|
|
buildtarget = parsedBuildTarget;
|
|
|
|
|
}
|
|
|
|
|
profileName = PlayerPrefs.GetString("Profile");
|
|
|
|
|
version = PlayerPrefs.GetString("Version");
|
|
|
|
|
WorkSpace = PlayerPrefs.GetString("WorkSpace");
|
|
|
|
|
isSeparatePackage = ConvertBool(PlayerPrefs.GetString("IsSeparatePackage"));
|
|
|
|
|
needClearCache = ConvertBool(PlayerPrefs.GetString("ClearCache"));
|
|
|
|
|
ignoreHotUpdateDll = ConvertBool(PlayerPrefs.GetString("IgnoreHotUpdateDll"));
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
2023-11-08 17:33:46 +08:00
|
|
|
protected override void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetString("BuildTarget", buildtarget.ToString());
|
|
|
|
|
PlayerPrefs.SetString("Profile", profileName);
|
|
|
|
|
PlayerPrefs.SetString("Version", version);
|
|
|
|
|
PlayerPrefs.SetString("WorkSpace", WorkSpace);
|
|
|
|
|
PlayerPrefs.SetString("IsSeparatePackage", isSeparatePackage.ToString());
|
|
|
|
|
PlayerPrefs.SetString("ClearCache", needClearCache.ToString());
|
|
|
|
|
PlayerPrefs.SetString("IgnoreHotUpdateDll", ignoreHotUpdateDll.ToString());
|
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool ConvertBool(string value)
|
|
|
|
|
{
|
|
|
|
|
return value == "True";
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable GetAllProfiles()
|
|
|
|
|
{
|
|
|
|
|
var list = new ValueDropdownList<string>();
|
|
|
|
|
for (var i = 0; i < thisWindow.profileList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
list.Add(thisWindow.profileList[i], thisWindow.profileList[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[VerticalGroup("TargetParam")]
|
|
|
|
|
[LabelText("打包平台"), LabelWidth(100)]
|
|
|
|
|
public BuildTarget buildtarget = BuildTarget.Android;
|
|
|
|
|
|
|
|
|
|
[VerticalGroup("ProfileParam")]
|
|
|
|
|
[ValueDropdown("GetAllProfiles")]
|
|
|
|
|
[LabelText("Profile"), LabelWidth(100)]
|
|
|
|
|
public string profileName;
|
|
|
|
|
|
|
|
|
|
[VerticalGroup("Version")]
|
|
|
|
|
[LabelText("版本号"), LabelWidth(100)]
|
|
|
|
|
public string version;
|
|
|
|
|
|
2023-12-19 12:31:48 +08:00
|
|
|
[VerticalGroup("developmentBuild")]
|
|
|
|
|
[LabelText("developmentBuild"), LabelWidth(100)]
|
|
|
|
|
public bool developmentBuild = true;
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
[VerticalGroup("WorkSpace")]
|
|
|
|
|
[LabelText("WorkSpace"), LabelWidth(100)]
|
|
|
|
|
public string WorkSpace = "WorkSpace";
|
|
|
|
|
|
|
|
|
|
[VerticalGroup("GroupParam")]
|
|
|
|
|
[LabelText("单独打包组"), LabelWidth(100)]
|
|
|
|
|
public bool isSeparatePackage;
|
|
|
|
|
|
2024-02-27 15:07:59 +08:00
|
|
|
#if USE_ADDRESSABLES
|
2023-10-19 15:00:19 +08:00
|
|
|
[VerticalGroup("GroupParam")]
|
|
|
|
|
[ShowIf("isSeparatePackage")]
|
|
|
|
|
[LabelText("选择组")]
|
|
|
|
|
public List<AddressableAssetGroup> separateGroup;
|
2024-02-27 15:07:59 +08:00
|
|
|
#endif
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
[VerticalGroup("ClearCache")]
|
|
|
|
|
[LabelText("清除缓存"), LabelWidth(100)]
|
|
|
|
|
public bool needClearCache;
|
|
|
|
|
|
|
|
|
|
[VerticalGroup("Hotuptdae")]
|
|
|
|
|
[LabelText("忽略热更新"), LabelWidth(100)]
|
|
|
|
|
public bool ignoreHotUpdateDll;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HorizontalGroup("package")]
|
|
|
|
|
[PropertySpace(50)]
|
|
|
|
|
[Button("Build HotUpdate Dlls")]
|
|
|
|
|
private void BuildHotUpdateDlls()
|
|
|
|
|
{
|
|
|
|
|
BuildLauncher.BuildHotUpdateDlls();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 15:07:59 +08:00
|
|
|
#if USE_ADDRESSABLES
|
2023-10-19 15:00:19 +08:00
|
|
|
[HorizontalGroup("package")]
|
|
|
|
|
[PropertySpace(50)]
|
|
|
|
|
[Button("Only Build Addressables")]
|
|
|
|
|
private void OnlyBuildAddressables()
|
|
|
|
|
{
|
|
|
|
|
if (isSeparatePackage)
|
|
|
|
|
{
|
|
|
|
|
BuildLauncher.BuildAddressables(buildtarget, profileName, version, WorkSpace, ignoreHotUpdateDll,
|
|
|
|
|
needClearCache, separateGroup);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BuildLauncher.BuildAddressables(buildtarget, profileName, version, WorkSpace, ignoreHotUpdateDll,
|
2023-12-19 12:31:48 +08:00
|
|
|
needClearCache);
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-02-27 15:07:59 +08:00
|
|
|
#endif
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
[PropertySpace(50)]
|
|
|
|
|
[HorizontalGroup("package")]
|
|
|
|
|
[Button("Build Addressables and Player")]
|
|
|
|
|
private void BuildAddressablesandPlayer()
|
|
|
|
|
{
|
2024-01-22 17:51:43 +08:00
|
|
|
BuildLauncher.BuildAddressablesAndPlayer(buildtarget, profileName, version, WorkSpace, ignoreHotUpdateDll, needClearCache,developmentBuild);
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-11-08 17:33:46 +08:00
|
|
|
[PropertySpace(10)]
|
|
|
|
|
[HorizontalGroup("package2")]
|
2023-10-19 15:00:19 +08:00
|
|
|
[Button("Update a Previous Build")]
|
|
|
|
|
private void UpdatePreviousBuild()
|
|
|
|
|
{
|
|
|
|
|
BuildLauncher.UpdatePreviousBuild(profileName, ignoreHotUpdateDll, buildtarget, WorkSpace);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 17:33:46 +08:00
|
|
|
[PropertySpace(10)]
|
|
|
|
|
[HorizontalGroup("package2")]
|
2023-10-19 15:00:19 +08:00
|
|
|
[Button("Only build Player")]
|
|
|
|
|
private void OnBuildPlayer()
|
|
|
|
|
{
|
2024-01-22 17:51:43 +08:00
|
|
|
BuildLauncher.BuildPlayer(buildtarget,developmentBuild);
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
2023-11-08 17:33:46 +08:00
|
|
|
|
|
|
|
|
[PropertySpace(10)]
|
|
|
|
|
[HorizontalGroup("Clean")]
|
|
|
|
|
[Button("还原设置")]
|
|
|
|
|
private void RevertSettings()
|
|
|
|
|
{
|
|
|
|
|
buildtarget = BuildTarget.Android;
|
|
|
|
|
profileName = "Debug";
|
|
|
|
|
version = PlayerSettings.bundleVersion;
|
|
|
|
|
WorkSpace = "WorkSpace";
|
|
|
|
|
isSeparatePackage = false;
|
|
|
|
|
needClearCache = false;
|
|
|
|
|
ignoreHotUpdateDll = false;
|
2024-01-22 17:51:43 +08:00
|
|
|
developmentBuild = true;
|
2023-11-08 17:33:46 +08:00
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
|