NLDClient-yudde/ProjectNLD/Assets/Editor/Common/BuildWindow.cs

211 lines
6.7 KiB
C#
Raw Normal View History

2023-11-08 17:33:46 +08:00
using System;
2024-05-15 17:15:25 +08:00
using UnityEditor;
using UnityEngine;
2023-10-19 15:00:19 +08:00
using Sirenix.Utilities;
2024-05-15 17:15:25 +08:00
using Sirenix.OdinInspector;
2023-10-19 15:00:19 +08:00
using Sirenix.Utilities.Editor;
2024-05-15 17:15:25 +08:00
using UnityEngine.Serialization;
using Sirenix.OdinInspector.Editor;
#if USE_ADDRESSABLES
2023-10-19 15:00:19 +08:00
using System.Collections;
using System.Collections.Generic;
2024-05-15 17:15:25 +08:00
#endif
2023-10-19 15:00:19 +08:00
public class BuildWindow : OdinEditorWindow
{
private static BuildWindow thisWindow;
2024-05-15 17:15:25 +08:00
#if USE_ADDRESSABLES
2023-10-19 15:00:19 +08:00
private List<string> profileList = new List<string>();
private AddressableAssetSettings settings;
2024-05-15 17:15:25 +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-05-15 17:15:25 +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-05-15 17:15:25 +08:00
#endif
2023-11-08 17:33:46 +08:00
}
2024-05-15 17:15:25 +08:00
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))
{
2024-05-15 17:15:25 +08:00
buildTarget = parsedBuildTarget;
2023-11-08 17:33:46 +08:00
}
2024-05-15 17:15:25 +08:00
2023-11-08 17:33:46 +08:00
version = PlayerPrefs.GetString("Version");
2024-05-15 17:15:25 +08:00
workSpace = PlayerPrefs.GetString("WorkSpace");
#if USE_ADDRESSABLES
profileName = PlayerPrefs.GetString("Profile");
2023-11-08 17:33:46 +08:00
isSeparatePackage = ConvertBool(PlayerPrefs.GetString("IsSeparatePackage"));
needClearCache = ConvertBool(PlayerPrefs.GetString("ClearCache"));
2024-05-15 17:15:25 +08:00
#endif
enableHotUpdateDll = ConvertBool(PlayerPrefs.GetString("IgnoreHotUpdateDll"));
2023-11-08 17:33:46 +08:00
}
2023-10-19 15:00:19 +08:00
2023-11-08 17:33:46 +08:00
protected override void OnDisable()
{
2024-05-15 17:15:25 +08:00
PlayerPrefs.SetString("BuildTarget", buildTarget.ToString());
2023-11-08 17:33:46 +08:00
PlayerPrefs.SetString("Version", version);
2024-05-15 17:15:25 +08:00
PlayerPrefs.SetString("WorkSpace", workSpace);
#if USE_ADDRESSABLES
PlayerPrefs.SetString("Profile", profileName);
2023-11-08 17:33:46 +08:00
PlayerPrefs.SetString("IsSeparatePackage", isSeparatePackage.ToString());
PlayerPrefs.SetString("ClearCache", needClearCache.ToString());
2024-05-15 17:15:25 +08:00
#endif
PlayerPrefs.SetString("IgnoreHotUpdateDll", enableHotUpdateDll.ToString());
2023-11-08 17:33:46 +08:00
PlayerPrefs.Save();
}
2024-05-15 17:15:25 +08:00
2023-11-08 17:33:46 +08:00
private static bool ConvertBool(string value)
{
return value == "True";
2023-10-19 15:00:19 +08:00
}
2024-05-15 17:15:25 +08:00
[VerticalGroup("TargetParam")] [LabelText("打包平台"), LabelWidth(150)]
public BuildTarget buildTarget = BuildTarget.Android;
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[VerticalGroup("Version")] [LabelText("版本号"), LabelWidth(150)]
2023-10-19 15:00:19 +08:00
public string version;
2024-05-15 17:15:25 +08:00
[VerticalGroup("WorkSpace")] [LabelText("WorkSpace"), LabelWidth(150)]
public string workSpace = "WorkSpace";
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[VerticalGroup("ProfileName")] [LabelText("打包模式"), LabelWidth(150)] [InfoBox("AllLocal本地包, 其余都为远程包")]
public string profileName = "AllLocal";
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[VerticalGroup("developmentBuild")] [LabelText("developmentBuild"), LabelWidth(150)]
public bool developmentBuild = true;
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[FormerlySerializedAs("ignoreHotUpdateDll")] [VerticalGroup("Hotuptdae")] [LabelText("开启热更新"), LabelWidth(150)]
public bool enableHotUpdateDll;
2023-10-19 15:00:19 +08:00
[HorizontalGroup("package")]
[PropertySpace(50)]
[Button("Build HotUpdate Dlls")]
private void BuildHotUpdateDlls()
{
BuildLauncher.BuildHotUpdateDlls();
}
2024-05-21 17:04:32 +08:00
[HorizontalGroup("package")]
[PropertySpace(50)]
[Button("构建资源")]
private void BuildResource()
{
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
BuildLauncher.BuildHotUpdateDlls();
}
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
/// <summary>
/// 构建资源和Player
/// </summary>
2023-10-19 15:00:19 +08:00
[PropertySpace(50)]
[HorizontalGroup("package")]
2024-05-15 17:15:25 +08:00
[Button("构建资源和Player")]
private void BuildResourceAndPlayer()
2023-10-19 15:00:19 +08:00
{
2024-05-15 17:15:25 +08:00
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
2024-05-21 17:04:32 +08:00
BuildLauncher.BuildResource();
2023-10-19 15:00:19 +08:00
}
2024-05-15 18:38:52 +08:00
[PropertySpace(10)]
2023-11-08 17:33:46 +08:00
[HorizontalGroup("package2")]
2024-05-15 18:38:52 +08:00
[Button("热更")]
2023-10-19 15:00:19 +08:00
private void UpdatePreviousBuild()
{
2024-05-21 17:04:32 +08:00
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
2024-05-15 18:38:52 +08:00
BuildLauncher.UpdatePreviousBuild(workSpace, version, buildTarget);
}
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("Only build Player")]
private void OnBuildPlayer()
{
2024-05-15 17:15:25 +08:00
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
BuildLauncher.BuildPlayer(buildTarget, developmentBuild);
2023-10-19 15:00:19 +08:00
}
2024-05-15 17:15:25 +08:00
2023-11-08 17:33:46 +08:00
[PropertySpace(10)]
[HorizontalGroup("Clean")]
[Button("还原设置")]
private void RevertSettings()
{
2024-05-15 17:15:25 +08:00
buildTarget = BuildTarget.Android;
2023-11-08 17:33:46 +08:00
version = PlayerSettings.bundleVersion;
2024-05-15 17:15:25 +08:00
workSpace = "WorkSpace";
#if USE_ADDRESSABLES
2023-11-08 17:33:46 +08:00
isSeparatePackage = false;
2024-05-15 17:15:25 +08:00
profileName = "Debug";
2023-11-08 17:33:46 +08:00
needClearCache = false;
2024-05-15 17:15:25 +08:00
#endif
enableHotUpdateDll = false;
2024-01-22 17:51:43 +08:00
developmentBuild = true;
2023-11-08 17:33:46 +08:00
}
2024-05-15 18:38:52 +08:00
2024-05-15 17:15:25 +08:00
#if USE_ADDRESSABLES
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("ProfileParam")] [ValueDropdown("GetAllProfiles")] [LabelText("Profile"), LabelWidth(100)]
public string profileName;
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[VerticalGroup("GroupParam")]
[LabelText("单独打包组"), LabelWidth(100)]
public bool isSeparatePackage;
[VerticalGroup("GroupParam")]
[ShowIf("isSeparatePackage")]
[LabelText("选择组")]
public List<AddressableAssetGroup> separateGroup;
[VerticalGroup("ClearCache")] [LabelText("清除缓存"), LabelWidth(100)]
public bool needClearCache;
[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,
needClearCache);
}
}
#endif
}