using System; using UnityEditor; using UnityEngine; using Sirenix.Utilities; using Sirenix.OdinInspector; using Sirenix.Utilities.Editor; using UnityEngine.Serialization; using Sirenix.OdinInspector.Editor; #if USE_ADDRESSABLES using System.Collections; using System.Collections.Generic; #endif public class BuildWindow : OdinEditorWindow { private static BuildWindow thisWindow; #if USE_ADDRESSABLES private List profileList = new List(); private AddressableAssetSettings settings; #endif [MenuItem("Tools/打包工具")] public static void ShowWindow() { thisWindow = GetWindow(); thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(600, 300); #if USE_ADDRESSABLES thisWindow.settings = AssetDatabase.LoadAssetAtPath( "Assets/AddressableAssetsData/AddressableAssetSettings.asset") as AddressableAssetSettings; foreach (var profileName in thisWindow.settings.profileSettings.GetAllProfileNames()) { thisWindow.profileList.Add(profileName); } thisWindow.separateGroup = new List(); foreach (var group in thisWindow.settings.groups) { thisWindow.separateGroup.Add(group); } #endif } protected override void OnEnable() { string buildTargetString = PlayerPrefs.GetString("BuildTarget"); if (Enum.TryParse(buildTargetString, out BuildTarget parsedBuildTarget)) { buildTarget = parsedBuildTarget; } version = PlayerPrefs.GetString("Version"); workSpace = PlayerPrefs.GetString("WorkSpace"); #if USE_ADDRESSABLES profileName = PlayerPrefs.GetString("Profile"); isSeparatePackage = ConvertBool(PlayerPrefs.GetString("IsSeparatePackage")); needClearCache = ConvertBool(PlayerPrefs.GetString("ClearCache")); #endif enableHotUpdateDll = ConvertBool(PlayerPrefs.GetString("IgnoreHotUpdateDll")); } protected override void OnDisable() { PlayerPrefs.SetString("BuildTarget", buildTarget.ToString()); PlayerPrefs.SetString("Version", version); PlayerPrefs.SetString("WorkSpace", workSpace); #if USE_ADDRESSABLES PlayerPrefs.SetString("Profile", profileName); PlayerPrefs.SetString("IsSeparatePackage", isSeparatePackage.ToString()); PlayerPrefs.SetString("ClearCache", needClearCache.ToString()); #endif PlayerPrefs.SetString("IgnoreHotUpdateDll", enableHotUpdateDll.ToString()); PlayerPrefs.Save(); } private static bool ConvertBool(string value) { return value == "True"; } [VerticalGroup("TargetParam")] [LabelText("打包平台"), LabelWidth(150)] public BuildTarget buildTarget = BuildTarget.Android; [VerticalGroup("Version")] [LabelText("版本号"), LabelWidth(150)] public string version; [VerticalGroup("WorkSpace")] [LabelText("WorkSpace"), LabelWidth(150)] public string workSpace = "WorkSpace"; [VerticalGroup("ProfileName")] [LabelText("打包模式"), LabelWidth(150)] [InfoBox("AllLocal本地包, 其余都为远程包")] public string profileName = "AllLocal"; [VerticalGroup("developmentBuild")] [LabelText("developmentBuild"), LabelWidth(150)] public bool developmentBuild = true; [FormerlySerializedAs("ignoreHotUpdateDll")] [VerticalGroup("Hotuptdae")] [LabelText("开启热更新"), LabelWidth(150)] public bool enableHotUpdateDll; [HorizontalGroup("package")] [PropertySpace(50)] [Button("Build HotUpdate Dlls")] private void BuildHotUpdateDlls() { BuildLauncher.BuildHotUpdateDlls(); } [HorizontalGroup("package")] [PropertySpace(50)] [Button("构建资源")] private void BuildResource() { BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll); BuildLauncher.BuildHotUpdateDlls(); } /// /// 构建资源和Player /// [PropertySpace(50)] [HorizontalGroup("package")] [Button("构建资源和Player")] private void BuildResourceAndPlayer() { BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll); BuildLauncher.BuildResource(); } [PropertySpace(10)] [HorizontalGroup("package2")] [Button("热更")] private void UpdatePreviousBuild() { BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll); BuildLauncher.UpdatePreviousBuild(workSpace, version, buildTarget); } [PropertySpace(10)] [HorizontalGroup("package2")] [Button("Only build Player")] private void OnBuildPlayer() { BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll); BuildLauncher.BuildPlayer(buildTarget, developmentBuild); } [PropertySpace(10)] [HorizontalGroup("Clean")] [Button("还原设置")] private void RevertSettings() { buildTarget = BuildTarget.Android; version = PlayerSettings.bundleVersion; workSpace = "WorkSpace"; #if USE_ADDRESSABLES isSeparatePackage = false; profileName = "Debug"; needClearCache = false; #endif enableHotUpdateDll = false; developmentBuild = true; } #if USE_ADDRESSABLES private static IEnumerable GetAllProfiles() { var list = new ValueDropdownList(); 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; [VerticalGroup("GroupParam")] [LabelText("单独打包组"), LabelWidth(100)] public bool isSeparatePackage; [VerticalGroup("GroupParam")] [ShowIf("isSeparatePackage")] [LabelText("选择组")] public List 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 }