update libs
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using AssetStoreTools.Previews.UI.Data;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class AssetPreviewElement : VisualElement
|
||||
{
|
||||
// Data
|
||||
private IAssetPreview _assetPreview;
|
||||
|
||||
// UI
|
||||
private Image _image;
|
||||
private Label _label;
|
||||
|
||||
public AssetPreviewElement()
|
||||
{
|
||||
AddToClassList("preview-list-image");
|
||||
|
||||
Create();
|
||||
|
||||
RegisterCallback<MouseDownEvent>(OnImageClicked);
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
CreateFiller();
|
||||
CreateImage();
|
||||
CreateLabel();
|
||||
}
|
||||
|
||||
private void CreateImage()
|
||||
{
|
||||
_image = new Image();
|
||||
Add(_image);
|
||||
}
|
||||
|
||||
private void CreateFiller()
|
||||
{
|
||||
var filler = new VisualElement() { name = "Filler" };
|
||||
Add(filler);
|
||||
}
|
||||
|
||||
private void CreateLabel()
|
||||
{
|
||||
_label = new Label();
|
||||
Add(_label);
|
||||
}
|
||||
|
||||
private void SetImage(Texture2D texture)
|
||||
{
|
||||
_image.style.width = texture.width < 128 ? texture.width : 128;
|
||||
_image.style.height = texture.height < 128 ? texture.height : 128;
|
||||
_image.style.backgroundImage = texture;
|
||||
}
|
||||
|
||||
private void OnImageClicked(MouseDownEvent _)
|
||||
{
|
||||
EditorGUIUtility.PingObject(_assetPreview.Asset);
|
||||
}
|
||||
|
||||
public void SetSource(IAssetPreview assetPreview)
|
||||
{
|
||||
_assetPreview = assetPreview;
|
||||
_assetPreview.LoadImage(SetImage);
|
||||
|
||||
var assetPath = _assetPreview.GetAssetPath();
|
||||
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
_label.text = "[Missing]";
|
||||
tooltip = "This asset has been deleted";
|
||||
return;
|
||||
}
|
||||
|
||||
var assetNameWithExtension = assetPath.Split('/').Last();
|
||||
_label.text = assetNameWithExtension;
|
||||
tooltip = assetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28891b8cff841a44eb508494d62c190c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/AssetPreviewElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class GridListElement : VisualElement
|
||||
{
|
||||
public int ElementWidth;
|
||||
public int ElementHeight;
|
||||
private int _visibilityHeadroom => ElementHeight;
|
||||
|
||||
public IList ItemSource;
|
||||
public Func<VisualElement> MakeItem;
|
||||
public Action<VisualElement, int> BindItem;
|
||||
|
||||
private ScrollView _scrollView;
|
||||
|
||||
public GridListElement()
|
||||
{
|
||||
style.flexGrow = 1;
|
||||
|
||||
Create();
|
||||
|
||||
_scrollView.contentViewport.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
_scrollView.verticalScroller.valueChanged += OnVerticalScroll;
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
_scrollView.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
#else
|
||||
_scrollView.showHorizontal = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
_scrollView = new ScrollView();
|
||||
Add(_scrollView);
|
||||
}
|
||||
|
||||
private void OnGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
Redraw();
|
||||
}
|
||||
|
||||
private void OnVerticalScroll(float value)
|
||||
{
|
||||
Redraw();
|
||||
}
|
||||
|
||||
public void Redraw()
|
||||
{
|
||||
if (ElementWidth == 0
|
||||
|| ElementHeight == 0
|
||||
|| ItemSource == null
|
||||
|| MakeItem == null
|
||||
|| BindItem == null)
|
||||
return;
|
||||
|
||||
_scrollView.Clear();
|
||||
|
||||
var rowCapacity = Mathf.FloorToInt(_scrollView.contentContainer.worldBound.width / ElementWidth);
|
||||
if (rowCapacity == 0)
|
||||
rowCapacity = 1;
|
||||
|
||||
var totalRequiredRows = ItemSource.Count / rowCapacity;
|
||||
if (ItemSource.Count % rowCapacity != 0)
|
||||
totalRequiredRows++;
|
||||
|
||||
_scrollView.contentContainer.style.height = totalRequiredRows * ElementHeight;
|
||||
|
||||
var visibleRows = new List<int>();
|
||||
for (int i = 0; i < totalRequiredRows; i++)
|
||||
{
|
||||
var visible = IsRowVisible(i);
|
||||
if (!visible)
|
||||
continue;
|
||||
|
||||
var rowElement = CreateRow(i);
|
||||
|
||||
for (int j = 0; j < rowCapacity; j++)
|
||||
{
|
||||
var elementIndex = i * rowCapacity + j;
|
||||
if (elementIndex >= ItemSource.Count)
|
||||
{
|
||||
rowElement.Add(CreateFillerElement());
|
||||
continue;
|
||||
}
|
||||
|
||||
var element = MakeItem?.Invoke();
|
||||
BindItem?.Invoke(element, elementIndex);
|
||||
|
||||
rowElement.Add(element);
|
||||
}
|
||||
|
||||
_scrollView.Add(rowElement);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsRowVisible(int rowIndex)
|
||||
{
|
||||
var contentStartY = _scrollView.contentContainer.worldBound.yMin;
|
||||
var visibleContentMinY = _scrollView.contentViewport.worldBound.yMin - _visibilityHeadroom;
|
||||
var visibleContentMaxY = _scrollView.contentViewport.worldBound.yMax + _visibilityHeadroom;
|
||||
if (_scrollView.contentViewport.worldBound.height == 0)
|
||||
visibleContentMaxY = this.worldBound.yMax;
|
||||
|
||||
var rowMinY = (rowIndex * ElementHeight) + contentStartY;
|
||||
var rowMaxY = (rowIndex * ElementHeight) + ElementHeight + contentStartY;
|
||||
|
||||
var fullyVisible = rowMinY >= visibleContentMinY && rowMaxY <= visibleContentMaxY;
|
||||
var partiallyAbove = rowMinY < visibleContentMinY && rowMaxY > visibleContentMinY;
|
||||
var partiallyBelow = rowMaxY > visibleContentMaxY && rowMinY < visibleContentMaxY;
|
||||
|
||||
return fullyVisible || partiallyAbove || partiallyBelow;
|
||||
}
|
||||
|
||||
private VisualElement CreateRow(int rowIndex)
|
||||
{
|
||||
var rowElement = new VisualElement() { name = $"Row {rowIndex}" };
|
||||
rowElement.style.flexDirection = FlexDirection.Row;
|
||||
rowElement.style.position = Position.Absolute;
|
||||
rowElement.style.top = ElementHeight * rowIndex;
|
||||
rowElement.style.width = _scrollView.contentViewport.worldBound.width;
|
||||
rowElement.style.justifyContent = Justify.SpaceAround;
|
||||
|
||||
return rowElement;
|
||||
}
|
||||
|
||||
private VisualElement CreateFillerElement()
|
||||
{
|
||||
var element = new VisualElement();
|
||||
element.style.width = ElementWidth;
|
||||
element.style.height = ElementHeight;
|
||||
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81d9f779e8c2a464cbdc1e39a4864803
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/GridListElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,116 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using AssetStoreTools.Previews.UI.Data;
|
||||
using System.Linq;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class PreviewCollectionElement : VisualElement
|
||||
{
|
||||
// Data
|
||||
private IAssetPreviewCollection _collection;
|
||||
|
||||
// UI
|
||||
private Label _previewCountLabel;
|
||||
private GridListElement _gridListElement;
|
||||
|
||||
public PreviewCollectionElement(IAssetPreviewCollection collection)
|
||||
{
|
||||
AddToClassList("preview-list");
|
||||
|
||||
_collection = collection;
|
||||
_collection.OnCollectionChanged += RefreshList;
|
||||
|
||||
Create();
|
||||
RefreshList();
|
||||
|
||||
SubscribeToSceneChanges();
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
CreateLabel();
|
||||
CreateGridListElement();
|
||||
}
|
||||
|
||||
private void CreateLabel()
|
||||
{
|
||||
_previewCountLabel = new Label();
|
||||
_previewCountLabel.style.display = DisplayStyle.None;
|
||||
Add(_previewCountLabel);
|
||||
}
|
||||
|
||||
private void CreateGridListElement()
|
||||
{
|
||||
_gridListElement = new GridListElement();
|
||||
_gridListElement.MakeItem = CreatePreview;
|
||||
_gridListElement.BindItem = BindPreview;
|
||||
_gridListElement.ElementWidth = 140 + 10; // Accounting for margin style
|
||||
_gridListElement.ElementHeight = 160 + 10; // Accounting for margin style
|
||||
Add(_gridListElement);
|
||||
}
|
||||
|
||||
private VisualElement CreatePreview()
|
||||
{
|
||||
var preview = new AssetPreviewElement();
|
||||
return preview;
|
||||
}
|
||||
|
||||
private void BindPreview(VisualElement element, int index)
|
||||
{
|
||||
var previewElement = (AssetPreviewElement)element;
|
||||
var preview = _collection.GetPreviews().ToList()[index];
|
||||
previewElement.SetSource(preview);
|
||||
}
|
||||
|
||||
private void RefreshList()
|
||||
{
|
||||
var type = _collection.GetGenerationType();
|
||||
var items = _collection.GetPreviews().ToList();
|
||||
_previewCountLabel.text = $"Displaying {items.Count} {ConvertGenerationTypeName(type)} previews";
|
||||
_previewCountLabel.style.display = DisplayStyle.Flex;
|
||||
_previewCountLabel.style.alignSelf = Align.Center;
|
||||
_previewCountLabel.style.marginBottom = 10;
|
||||
_previewCountLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
|
||||
_gridListElement.ItemSource = items;
|
||||
_gridListElement.Redraw();
|
||||
}
|
||||
|
||||
private string ConvertGenerationTypeName(GenerationType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GenerationType.Custom:
|
||||
return "high resolution";
|
||||
default:
|
||||
return type.ToString().ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
private void SubscribeToSceneChanges()
|
||||
{
|
||||
var windowToSubscribeTo = Resources.FindObjectsOfTypeAll<PreviewGeneratorWindow>().FirstOrDefault();
|
||||
UnityAction<Scene, Scene> sceneChanged = null;
|
||||
sceneChanged = new UnityAction<Scene, Scene>((_, __) => RefreshObjects(windowToSubscribeTo));
|
||||
EditorSceneManager.activeSceneChangedInEditMode += sceneChanged;
|
||||
|
||||
void RefreshObjects(PreviewGeneratorWindow subscribedWindow)
|
||||
{
|
||||
// Remove callback if preview generator window instance changed
|
||||
var activeWindow = Resources.FindObjectsOfTypeAll<PreviewGeneratorWindow>().FirstOrDefault();
|
||||
if (subscribedWindow == null || subscribedWindow != activeWindow)
|
||||
{
|
||||
EditorSceneManager.activeSceneChangedInEditMode -= sceneChanged;
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 842a11e046ca5284d9de9f4a05b1fa26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/PreviewCollectionElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,50 @@
|
||||
using AssetStoreTools.Previews.UI.Data;
|
||||
using System;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class PreviewGenerateButtonElement : VisualElement
|
||||
{
|
||||
// Data
|
||||
private IPreviewGeneratorSettings _settings;
|
||||
|
||||
// UI
|
||||
private Button _generateButton;
|
||||
|
||||
public event Action OnGenerate;
|
||||
|
||||
public PreviewGenerateButtonElement(IPreviewGeneratorSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_settings.OnGenerationPathsChanged += GenerationPathsChanged;
|
||||
|
||||
Create();
|
||||
Deserialize();
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
_generateButton = new Button(Validate) { text = "Generate" };
|
||||
_generateButton.AddToClassList("preview-generate-button");
|
||||
|
||||
Add(_generateButton);
|
||||
}
|
||||
|
||||
private void Validate()
|
||||
{
|
||||
OnGenerate?.Invoke();
|
||||
}
|
||||
|
||||
private void GenerationPathsChanged()
|
||||
{
|
||||
var inputPathsPresent = _settings.GetGenerationPaths().Count > 0;
|
||||
_generateButton.SetEnabled(inputPathsPresent);
|
||||
}
|
||||
|
||||
private void Deserialize()
|
||||
{
|
||||
GenerationPathsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c8fbb0b13ba7d3479c0867c440821e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/PreviewGenerateButtonElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,122 @@
|
||||
using AssetStoreTools.Previews.UI.Data;
|
||||
using AssetStoreTools.Utility;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Validator.UI.Elements
|
||||
{
|
||||
internal class PreviewGeneratorPathsElement : VisualElement
|
||||
{
|
||||
// Data
|
||||
private IPreviewGeneratorSettings _settings;
|
||||
|
||||
// UI
|
||||
private ScrollView _pathBoxScrollView;
|
||||
|
||||
public PreviewGeneratorPathsElement(IPreviewGeneratorSettings settings)
|
||||
{
|
||||
AddToClassList("preview-paths");
|
||||
|
||||
_settings = settings;
|
||||
_settings.OnGenerationPathsChanged += InputPathsChanged;
|
||||
|
||||
Create();
|
||||
Deserialize();
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
var pathSelectionRow = new VisualElement();
|
||||
pathSelectionRow.AddToClassList("preview-settings-selection-row");
|
||||
|
||||
VisualElement labelHelpRow = new VisualElement();
|
||||
labelHelpRow.AddToClassList("preview-settings-selection-label-help-row");
|
||||
labelHelpRow.style.alignSelf = Align.FlexStart;
|
||||
|
||||
Label pathLabel = new Label { text = "Input paths" };
|
||||
Image pathLabelTooltip = new Image
|
||||
{
|
||||
tooltip = "Select the folder (or multiple folders) to generate asset previews for."
|
||||
};
|
||||
|
||||
labelHelpRow.Add(pathLabel);
|
||||
labelHelpRow.Add(pathLabelTooltip);
|
||||
|
||||
var fullPathBox = new VisualElement() { name = "PreviewPaths" };
|
||||
fullPathBox.AddToClassList("preview-paths-box");
|
||||
|
||||
_pathBoxScrollView = new ScrollView { name = "PreviewPathsScrollView" };
|
||||
_pathBoxScrollView.AddToClassList("preview-paths-scroll-view");
|
||||
|
||||
VisualElement scrollViewBottomRow = new VisualElement();
|
||||
scrollViewBottomRow.AddToClassList("preview-paths-scroll-view-bottom-row");
|
||||
|
||||
var addExtraPathsButton = new Button(BrowsePath) { text = "Add a path" };
|
||||
addExtraPathsButton.AddToClassList("preview-paths-add-button");
|
||||
scrollViewBottomRow.Add(addExtraPathsButton);
|
||||
|
||||
fullPathBox.Add(_pathBoxScrollView);
|
||||
fullPathBox.Add(scrollViewBottomRow);
|
||||
|
||||
pathSelectionRow.Add(labelHelpRow);
|
||||
pathSelectionRow.Add(fullPathBox);
|
||||
|
||||
Add(pathSelectionRow);
|
||||
}
|
||||
|
||||
private VisualElement CreateSinglePathElement(string path)
|
||||
{
|
||||
var validationPath = new VisualElement();
|
||||
validationPath.AddToClassList("preview-paths-path-row");
|
||||
|
||||
var folderPathLabel = new Label(path);
|
||||
folderPathLabel.AddToClassList("preview-paths-path-row-input-field");
|
||||
|
||||
var removeButton = new Button(() =>
|
||||
{
|
||||
_settings.RemoveGenerationPath(path);
|
||||
});
|
||||
removeButton.text = "X";
|
||||
removeButton.AddToClassList("preview-paths-path-row-remove-button");
|
||||
|
||||
validationPath.Add(folderPathLabel);
|
||||
validationPath.Add(removeButton);
|
||||
|
||||
return validationPath;
|
||||
}
|
||||
|
||||
private void BrowsePath()
|
||||
{
|
||||
string absolutePath = EditorUtility.OpenFolderPanel("Select a directory", "Assets", "");
|
||||
|
||||
if (string.IsNullOrEmpty(absolutePath))
|
||||
return;
|
||||
|
||||
var relativePath = FileUtility.AbsolutePathToRelativePath(absolutePath, ASToolsPreferences.Instance.EnableSymlinkSupport);
|
||||
|
||||
if (!_settings.IsGenerationPathValid(relativePath, out var error))
|
||||
{
|
||||
EditorUtility.DisplayDialog("Invalid path", error, "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
_settings.AddGenerationPath(relativePath);
|
||||
}
|
||||
|
||||
private void InputPathsChanged()
|
||||
{
|
||||
var inputPaths = _settings.GetGenerationPaths();
|
||||
|
||||
_pathBoxScrollView.Clear();
|
||||
foreach (var path in inputPaths)
|
||||
{
|
||||
_pathBoxScrollView.Add(CreateSinglePathElement(path));
|
||||
}
|
||||
}
|
||||
|
||||
private void Deserialize()
|
||||
{
|
||||
InputPathsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd3e3f7fbfc5f1e46835438be2756746
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/PreviewGeneratorPathsElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,99 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using AssetStoreTools.Previews.UI.Data;
|
||||
using AssetStoreTools.Validator.UI.Elements;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class PreviewGeneratorSettingsElement : VisualElement
|
||||
{
|
||||
// Data
|
||||
private IPreviewGeneratorSettings _settings;
|
||||
|
||||
// UI
|
||||
private PreviewGeneratorPathsElement _previewPathsElement;
|
||||
private ToolbarMenu _generationTypeMenu;
|
||||
|
||||
public PreviewGeneratorSettingsElement(IPreviewGeneratorSettings settings)
|
||||
{
|
||||
AddToClassList("preview-settings");
|
||||
|
||||
_settings = settings;
|
||||
_settings.OnGenerationTypeChanged += GenerationTypeChanged;
|
||||
|
||||
Create();
|
||||
Deserialize();
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
CreateGenerationType();
|
||||
CreateInputPathsElement();
|
||||
}
|
||||
|
||||
private void CreateInputPathsElement()
|
||||
{
|
||||
_previewPathsElement = new PreviewGeneratorPathsElement(_settings);
|
||||
Add(_previewPathsElement);
|
||||
}
|
||||
|
||||
private void CreateGenerationType()
|
||||
{
|
||||
var typeSelectionBox = new VisualElement();
|
||||
typeSelectionBox.AddToClassList("preview-settings-selection-row");
|
||||
|
||||
VisualElement labelHelpRow = new VisualElement();
|
||||
labelHelpRow.AddToClassList("preview-settings-selection-label-help-row");
|
||||
|
||||
Label generationTypeLabel = new Label { text = "Generation type" };
|
||||
Image categoryLabelTooltip = new Image
|
||||
{
|
||||
tooltip = "Choose the generation type for your previews.\n\n" +
|
||||
"- Native: retrieve previews from the Asset Database which are generated by Unity Editor internally\n" +
|
||||
"- High Resolution (experimental): generate previews using a custom implementation. Resulting previews are of higher resolution " +
|
||||
"than those generated by Unity Editor. Note that they may look slightly different from native previews"
|
||||
};
|
||||
|
||||
labelHelpRow.Add(generationTypeLabel);
|
||||
labelHelpRow.Add(categoryLabelTooltip);
|
||||
|
||||
_generationTypeMenu = new ToolbarMenu { name = "GenerationTypeMenu" };
|
||||
_generationTypeMenu.AddToClassList("preview-settings-selection-dropdown");
|
||||
|
||||
typeSelectionBox.Add(labelHelpRow);
|
||||
typeSelectionBox.Add(_generationTypeMenu);
|
||||
|
||||
// Append available categories
|
||||
var types = _settings.GetAvailableGenerationTypes();
|
||||
foreach (var t in types)
|
||||
{
|
||||
_generationTypeMenu.menu.AppendAction(ConvertGenerationTypeName(t), _ => _settings.SetGenerationType(t));
|
||||
}
|
||||
|
||||
Add(typeSelectionBox);
|
||||
}
|
||||
|
||||
private string ConvertGenerationTypeName(GenerationType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GenerationType.Custom:
|
||||
return "High Resolution (experimental)";
|
||||
default:
|
||||
return type.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerationTypeChanged()
|
||||
{
|
||||
var t = _settings.GetGenerationType();
|
||||
_generationTypeMenu.text = ConvertGenerationTypeName(t);
|
||||
}
|
||||
|
||||
private void Deserialize()
|
||||
{
|
||||
GenerationTypeChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f38de8a438b8c94a81fe5f2cc45c110
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/PreviewGeneratorSettingsElement.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,87 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AssetStoreTools.Previews.UI.Elements
|
||||
{
|
||||
internal class PreviewWindowDescriptionElement : VisualElement
|
||||
{
|
||||
private const string DescriptionFoldoutText = "Generate and inspect asset preview images to be displayed in your package listing page on the Asset Store.";
|
||||
private const string DescriptionFoldoutContentText = "Images generated in this window will be reused when exporting a package. Any missing images generated during the package export process will also appear here.\n\n" +
|
||||
"Preview images are displayed on the Asset Store under the 'Package Content' section of the package listing. " +
|
||||
"They are also displayed in the package importer window that appears during the package import process. " +
|
||||
"Note that these images will not replace the images used for the assets in the Project window after the package gets imported.";
|
||||
|
||||
private VisualElement _descriptionSimpleContainer;
|
||||
private Button _showMoreButton;
|
||||
|
||||
private VisualElement _descriptionFullContainer;
|
||||
private Button _showLessButton;
|
||||
|
||||
public PreviewWindowDescriptionElement()
|
||||
{
|
||||
AddToClassList("asset-preview-description");
|
||||
Create();
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
CreateSimpleDescription();
|
||||
CreateFullDescription();
|
||||
}
|
||||
|
||||
private void CreateSimpleDescription()
|
||||
{
|
||||
_descriptionSimpleContainer = new VisualElement();
|
||||
_descriptionSimpleContainer.AddToClassList("asset-preview-description-simple-container");
|
||||
|
||||
var simpleDescription = new Label(DescriptionFoldoutText);
|
||||
simpleDescription.AddToClassList("asset-preview-description-simple-label");
|
||||
|
||||
_showMoreButton = new Button(ToggleFullDescription) { text = "Show more..." };
|
||||
_showMoreButton.AddToClassList("asset-preview-description-hyperlink-button");
|
||||
_showMoreButton.AddToClassList("asset-preview-description-show-button");
|
||||
|
||||
_descriptionSimpleContainer.Add(simpleDescription);
|
||||
_descriptionSimpleContainer.Add(_showMoreButton);
|
||||
|
||||
Add(_descriptionSimpleContainer);
|
||||
}
|
||||
|
||||
private void CreateFullDescription()
|
||||
{
|
||||
_descriptionFullContainer = new VisualElement();
|
||||
_descriptionFullContainer.AddToClassList("asset-preview-description-full-container");
|
||||
|
||||
var validatorDescription = new Label()
|
||||
{
|
||||
text = DescriptionFoldoutContentText
|
||||
};
|
||||
validatorDescription.AddToClassList("asset-preview-description-full-label");
|
||||
|
||||
_showLessButton = new Button(ToggleFullDescription) { text = "Show less..." };
|
||||
_showLessButton.AddToClassList("asset-preview-description-hide-button");
|
||||
_showLessButton.AddToClassList("asset-preview-description-hyperlink-button");
|
||||
|
||||
_descriptionFullContainer.Add(validatorDescription);
|
||||
_descriptionFullContainer.Add(_showLessButton);
|
||||
|
||||
_descriptionFullContainer.style.display = DisplayStyle.None;
|
||||
Add(_descriptionFullContainer);
|
||||
}
|
||||
|
||||
private void ToggleFullDescription()
|
||||
{
|
||||
var displayFullDescription = _descriptionFullContainer.style.display == DisplayStyle.None;
|
||||
|
||||
if (displayFullDescription)
|
||||
{
|
||||
_showMoreButton.style.display = DisplayStyle.None;
|
||||
_descriptionFullContainer.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
else
|
||||
{
|
||||
_showMoreButton.style.display = DisplayStyle.Flex;
|
||||
_descriptionFullContainer.style.display = DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cab289a87b0ba74f89cb458ff6d44f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/UI/Elements/PreviewWindowDescriptionElement.cs
|
||||
uploadId: 724584
|
||||
Reference in New Issue
Block a user