public void LegacyIconSectionGUI() { // Both default icon and Legacy icons are serialized to the same map // That's why m_LegacyPlatformIcons can be excluded in two places (other place in IconSectionGUI()) using (var vertical = new EditorGUILayout.VerticalScope()) using (new EditorGUI.PropertyScope(vertical.rect, GUIContent.none, m_LegacyPlatformIcons)) { // Get icons and icon sizes for selected platform (or default) EditorGUI.BeginChangeCheck(); string platformName = ""; Texture2D[] icons = PlayerSettings.GetPlatformIconsForTargetIcons(platformName, IconKind.Any, m_AllLegacyIcons); int[] widths = PlayerSettings.GetIconWidthsForPlatform(platformName, IconKind.Any); // Ensure the default icon list is always populated correctly if (icons.Length != widths.Length) { icons = new Texture2D[widths.Length]; } icons[0] = (Texture2D)EditorGUILayout.ObjectField(SettingsContent.defaultIcon, icons[0], typeof(Texture2D), false); // Save changes if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(m_Owner.targets, SettingsContent.undoChangedIconString); SetLegacyPlatformIcons(platformName, icons, IconKind.Any, ref m_AllLegacyIcons); } } }
static void ImportLegacyIcons(string platform, PlatformIconKind kind, PlatformIcon[] platformIcons, LegacyBuildTargetIcons[] allLegacyIcons) { if (!Enum.IsDefined(typeof(IconKind), kind.kind)) { return; } var iconKind = (IconKind)kind.kind; var legacyIcons = PlayerSettings.GetPlatformIconsForTargetIcons(platform, iconKind, allLegacyIcons); var legacyIconWidths = PlayerSettings.GetIconWidthsForPlatform(platform, iconKind); var legacyIconHeights = PlayerSettings.GetIconHeightsForPlatform(platform, iconKind); for (var i = 0; i < legacyIcons.Length; i++) { var selectedIcons = new List <PlatformIcon>(); foreach (var icon in platformIcons) { if (icon.width == legacyIconWidths[i] && icon.height == legacyIconHeights[i]) { selectedIcons.Add(icon); } } foreach (var selectedIcon in selectedIcons) { selectedIcon.SetTextures(legacyIcons[i]); } } }
public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex) { m_SelectedPlatform = platformID; if (!m_Owner.BeginSettingsBox(sectionIndex, SettingsContent.iconTitle)) { m_Owner.EndSettingsBox(); return; } var platformUsesStandardIcons = true; if (settingsExtension != null) { platformUsesStandardIcons = settingsExtension.UsesStandardIcons(); } if (platformUsesStandardIcons) { var selectedDefault = (m_SelectedPlatform < 0); // Set default platform variables BuildPlatform platform = null; namedBuildTarget = NamedBuildTarget.Standalone; var platformName = ""; // Override if a platform is selected if (!selectedDefault) { platform = m_ValidPlatforms[m_SelectedPlatform]; namedBuildTarget = platform.namedBuildTarget; platformName = platform.name; } if (namedBuildTarget == NamedBuildTarget.WebGL || namedBuildTarget == NamedBuildTarget.Server) { PlayerSettingsEditor.ShowNoSettings(); EditorGUILayout.Space(); } else if (namedBuildTarget != NamedBuildTarget.WindowsStoreApps) // UWP does this in its editor extension { // Both default icon and Legacy icons are serialized to the same map // That's why m_LegacyPlatformIcons can be excluded in two places (other place in CommonSettings()) using (var vertical = new EditorGUILayout.VerticalScope()) using (new EditorGUI.PropertyScope(vertical.rect, GUIContent.none, m_LegacyPlatformIcons)) { // Get icons and icon sizes for selected platform (or default) var icons = PlayerSettings.GetPlatformIconsForTargetIcons(platformName, IconKind.Any, m_AllLegacyIcons); var widths = PlayerSettings.GetIconWidthsForPlatform(platformName, IconKind.Any); var heights = PlayerSettings.GetIconHeightsForPlatform(platformName, IconKind.Any); var kinds = PlayerSettings.GetIconKindsForPlatform(platformName); var overrideIcons = true; if (!selectedDefault) { // If the list of icons for this platform is not empty (and has the correct size), // consider the icon overridden for this platform EditorGUI.BeginChangeCheck(); overrideIcons = (icons.Length == widths.Length); overrideIcons = GUILayout.Toggle(overrideIcons, string.Format(L10n.Tr("Override for {0}"), platform.title.text)); EditorGUI.BeginDisabled(!overrideIcons); var changed = EditorGUI.EndChangeCheck(); if (changed || (!overrideIcons && icons.Length > 0)) { // Set the list of icons to correct length if overridden, otherwise to an empty list if (overrideIcons) { icons = new Texture2D[widths.Length]; } else { icons = new Texture2D[0]; } if (changed) { SetLegacyPlatformIcons(platformName, icons, IconKind.Any, ref m_AllLegacyIcons); } } } // Show the icons for this platform (or default) EditorGUI.BeginChangeCheck(); for (int i = 0; i < widths.Length; i++) { var previewWidth = Mathf.Min(kMaxPreviewSize, widths[i]); var previewHeight = (int)((float)heights[i] * previewWidth / widths[i]); // take into account the aspect ratio if (namedBuildTarget == NamedBuildTarget.iOS) { // Spotlight icons begin with 120 but there are two in the list. // So check if the next one is 80. if (kinds[i] == IconKind.Spotlight && kinds[i - 1] != IconKind.Spotlight) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Spotlight icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Settings && kinds[i - 1] != IconKind.Settings) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Settings icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Notification && kinds[i - 1] != IconKind.Notification) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Notification icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Store && kinds[i - 1] != IconKind.Store) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "App Store icons", EditorStyles.boldLabel); } } var rect = GUILayoutUtility.GetRect(kSlotSize, Mathf.Max(kSlotSize, previewHeight) + kIconSpacing); var width = Mathf.Min(rect.width, EditorGUIUtility.labelWidth + 4 + kSlotSize + kIconSpacing + kMaxPreviewSize); // Label var label = widths[i] + "x" + heights[i]; GUI.Label(new Rect(rect.x, rect.y, width - kMaxPreviewSize - kSlotSize - 2 * kIconSpacing, 20), label); // Texture slot if (overrideIcons) { var slotWidth = kSlotSize; var slotHeight = (int)((float)heights[i] / widths[i] * kSlotSize); // take into account the aspect ratio icons[i] = (Texture2D)EditorGUI.ObjectField( new Rect(rect.x + width - kMaxPreviewSize - kSlotSize - kIconSpacing, rect.y, slotWidth, slotHeight), icons[i], typeof(Texture2D), false); } // Preview var previewRect = new Rect(rect.x + width - kMaxPreviewSize, rect.y, previewWidth, previewHeight); var closestIcon = PlayerSettings.GetPlatformIconForSizeForTargetIcons(platformName, widths[i], heights[i], kinds[i], m_AllLegacyIcons); if (closestIcon != null) { GUI.DrawTexture(previewRect, closestIcon); } else { GUI.Box(previewRect, ""); } } // Save changes if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(m_Owner.targets, SettingsContent.undoChangedIconString); SetLegacyPlatformIcons(platformName, icons, IconKind.Any, ref m_AllLegacyIcons); } EditorGUI.EndDisabled(); if (namedBuildTarget == NamedBuildTarget.iOS || namedBuildTarget == NamedBuildTarget.tvOS) { EditorGUILayout.PropertyField(m_UIPrerenderedIcon, SettingsContent.UIPrerenderedIcon); EditorGUILayout.Space(); } } } } if (settingsExtension != null) { settingsExtension.IconSectionGUI(); } m_Owner.EndSettingsBox(); }