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

194 lines
6.0 KiB
C#

using System;
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>();
#if USE_ADDRESSABLES
private AddressableAssetSettings settings;
#endif
[MenuItem("Tools/打包工具")]
public static void ShowWindow()
{
thisWindow = GetWindow<BuildWindow>();
thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(600, 300);
#if USE_ADDRESSABLES
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);
}
#endif
}
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"));
}
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";
}
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;
[VerticalGroup("developmentBuild")]
[LabelText("developmentBuild"), LabelWidth(100)]
public bool developmentBuild = true;
[VerticalGroup("WorkSpace")]
[LabelText("WorkSpace"), LabelWidth(100)]
public string WorkSpace = "WorkSpace";
[VerticalGroup("GroupParam")]
[LabelText("单独打包组"), LabelWidth(100)]
public bool isSeparatePackage;
#if USE_ADDRESSABLES
[VerticalGroup("GroupParam")]
[ShowIf("isSeparatePackage")]
[LabelText("选择组")]
public List<AddressableAssetGroup> separateGroup;
#endif
[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();
}
#if USE_ADDRESSABLES
[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
[PropertySpace(50)]
[HorizontalGroup("package")]
[Button("Build Addressables and Player")]
private void BuildAddressablesandPlayer()
{
BuildLauncher.BuildAddressablesAndPlayer(buildtarget, profileName, version, WorkSpace, ignoreHotUpdateDll, needClearCache,developmentBuild);
}
[PropertySpace(10)]
[HorizontalGroup("package2")]
[Button("Update a Previous Build")]
private void UpdatePreviousBuild()
{
BuildLauncher.UpdatePreviousBuild(profileName, ignoreHotUpdateDll, buildtarget, WorkSpace);
}
[PropertySpace(10)]
[HorizontalGroup("package2")]
[Button("Only build Player")]
private void OnBuildPlayer()
{
BuildLauncher.BuildPlayer(buildtarget,developmentBuild);
}
[PropertySpace(10)]
[HorizontalGroup("Clean")]
[Button("还原设置")]
private void RevertSettings()
{
buildtarget = BuildTarget.Android;
profileName = "Debug";
version = PlayerSettings.bundleVersion;
WorkSpace = "WorkSpace";
isSeparatePackage = false;
needClearCache = false;
ignoreHotUpdateDll = false;
developmentBuild = true;
}
}