using UnityEngine; using UnityEditor.U2D.Common; using UnityEngine.UIElements; using UnityEditor.UIElements; using System.Collections.Generic; using Object = UnityEngine.Object; namespace UnityEditor.U2D.Animation.Upgrading { internal class AssetUpgraderWindow : EditorWindow { static class ElementIds { public const string ModeSelector = "ModeSelector"; public const string ToolDescription = "ToolDescription"; public const string WarningImage = "WarningImage"; public const string WarningCount = "WarningCount"; public const string ErrorImage = "ErrorImage"; public const string ErrorCount = "ErrorCount"; public const string SuccessImage = "SuccessImage"; public const string SuccessCount = "SuccessCount"; public const string CenterInfo = "CenterInfo"; public const string ListHeader = "ListHeader"; public const string SelectAll = "SelectAll"; public const string AssetHeader = "AssetHeader"; public const string AssetList = "AssetList"; public const string ListFooter = "ListFooter"; public const string InfoContainer = "InfoContainer"; public const string InfoBox = "InfoBox"; public const string Scan = "Scan"; public const string UpgradeSelected = "UpgradeSelected"; public const string OpenLog = "OpenLog"; public const string AssetRow = "AssetRow"; public const string ObjectToggle = "ObjectToggle"; public const string ObjectImage = "ObjectImage"; public const string AssetCheckbox = "AssetCheckbox"; public const string AssetElement = "AssetElement"; public const string DarkArea = "DarkArea"; public const string AssetImage = "AssetImage"; } static class Contents { public static readonly string WindowTitle = L10n.Tr("2D Anim Asset Upgrader"); public static readonly string UnsupportedSerializeMode = L10n.Tr("The project's serialization mode is set to {0}. This upgrading tool only supports ForceText. Update the project's serialization mode under `Edit > Project Settings > Editor > Asset Serialization` to use the upgrading tool."); public static readonly string SpriteLibDesc = L10n.Tr("Use this tool to replace runtime Sprite Library Assets (.asset) with Sprite Library Source Assets (.spriteLib) for increased tooling support. Once replaced, this tool also makes sure all Sprite Library references in Scenes and Prefabs are maintained."); public static readonly string AnimClipDesc = L10n.Tr("Use this tool to upgrade animation clips with older Sprite Resolver data format to the latest Sprite Resolver data format."); public static readonly string ScanToBegin = L10n.Tr("Press Scan Project to see which assets require upgrading."); public static readonly string NoAssetsRequireUpgrade = L10n.Tr("No assets require upgrading."); public static readonly string UpgradeDialogTitle = L10n.Tr("Upgrade Assets"); public static readonly string UpgradeDialogMessage = L10n.Tr("The upgrade cannot be reverted and AssetBundles would have to be rebuilt but you will get to enjoy the new improvements.\n\nAlternatively, you may choose not to upgrade for now and continue to use the existing assets.\n\nAre you sure you want to upgrade the selected assets?"); public static readonly string UpgradeDialogYes = L10n.Tr("Yes"); public static readonly string UpgradeDialogNo = L10n.Tr("No"); public static readonly string SpriteLibraries = L10n.Tr("Sprite Libraries"); public static readonly string AnimationClips = L10n.Tr("Animation Clips"); } const string k_UiUxml = "AssetUpgrader/AssetUpgrader.uxml"; const string k_UiUss = "AssetUpgrader/AssetUpgrader.uss"; const string k_IconWarningId = "WarningIcon_Small"; const string k_IconFailId = "ErrorIcon_Small"; const string k_IconSuccessId = "GreenCheck"; Texture2D m_IconWarn; Texture2D m_IconFail; Texture2D m_IconSuccess; ButtonStripField m_ModeSelector; Label m_DescriptionLabel; Label m_WarningCountLabel; Label m_ErrorCountLabel; Label m_SuccessCountLabel; Label m_CenterInfo; VisualElement m_ListHeaderContainer; Toggle m_SelectAllToggle; Label m_AssetHeader; ListView m_AssetListView; VisualElement m_ListFooterContainer; VisualElement m_InfoContainer; HelpBox m_InfoBox; Button m_UpgradeSelectedBtn; Button m_OpenLogBtn; UpgradeMode m_SelectedMode = UpgradeMode.SpriteLibrary; List m_AssetList = new List(); List m_UpgradeResultList = new List(); List m_UpgradeTooltips = new List(); HashSet m_SelectedObjs = new HashSet(); string m_UpgradeLogPath; [MenuItem("Window/2D/2D Animation Asset Upgrader")] internal static void OpenWindow() { var window = GetWindowWithRect(new Rect(0, 0, 532, 512)); window.titleContent = new GUIContent(Contents.WindowTitle); window.Show(); } public void CreateGUI() { var treeAsset = ResourceLoader.Load(k_UiUxml); rootVisualElement.Add(treeAsset.CloneTree()); rootVisualElement.styleSheets.Add(ResourceLoader.Load(k_UiUss)); LoadIconTextures(); SetupUI(); OnChangeUpgradeMode(); } void LoadIconTextures() { m_IconWarn = EditorIconUtility.LoadIconResource(k_IconWarningId, EditorIconUtility.LightIconPath, EditorIconUtility.DarkIconPath); m_IconFail = EditorIconUtility.LoadIconResource(k_IconFailId, EditorIconUtility.LightIconPath, EditorIconUtility.DarkIconPath); m_IconSuccess = EditorIconUtility.LoadIconResource(k_IconSuccessId, EditorIconUtility.LightIconPath, EditorIconUtility.DarkIconPath); } void SetupUI() { SetupTopContainer(); SetupConversionResultContainer(); SetupCenterContainer(); SetupInfoContainer(); SetupBottomContainer(); } void SetupTopContainer() { m_ModeSelector = rootVisualElement.Q(ElementIds.ModeSelector); m_ModeSelector.focusable = false; m_ModeSelector.AddButton(Contents.SpriteLibraries); m_ModeSelector.AddButton(Contents.AnimationClips); m_ModeSelector.SetValueWithoutNotify((int)m_SelectedMode); m_ModeSelector.RegisterValueChangedCallback(_ => OnChangeUpgradeMode()); m_DescriptionLabel = rootVisualElement.Q