Added GenerateMask to AssetsHelpers;
This commit is contained in:
@@ -12,16 +12,16 @@
|
||||
<engine:VisualElement name="content-after-list" />
|
||||
<engine:EnumField label="Output Directory" value="Center" type="Misaki.ArtToolEditor.OutputDirectoryType, Misaki.ArtTool.Editor" name="directory-type-enum">
|
||||
<Bindings>
|
||||
<engine:DataBinding property="value" data-source-path="_outputOptions.outputDirectoryType" binding-mode="TwoWay" />
|
||||
<engine:DataBinding property="value" data-source-path="_outputDirectoryType" binding-mode="TwoWay" />
|
||||
</Bindings>
|
||||
</engine:EnumField>
|
||||
<engine:TextField label="Custom Path" placeholder-text="path" name="custom-path-input" tooltip="Support absolute and relative path">
|
||||
<engine:TextField label="Custom Path" placeholder-text="path" name="custom-path-input" tooltip="Support absolute and relative path" style="display: none;">
|
||||
<Bindings>
|
||||
<engine:DataBinding property="value" data-source-path="_outputOptions.customPath" binding-mode="TwoWay" />
|
||||
<engine:DataBinding property="value" data-source-path="_customPath" binding-mode="TwoWay" />
|
||||
</Bindings>
|
||||
</engine:TextField>
|
||||
<engine:VisualElement name="content-before-button" />
|
||||
<engine:Button text="Output" name="output-button" />
|
||||
<engine:Button text="Execute" name="output-button" />
|
||||
<engine:VisualElement name="content-on-bottom" />
|
||||
</engine:ScrollView>
|
||||
</engine:VisualElement>
|
||||
|
||||
@@ -10,18 +10,16 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace Misaki.ArtToolEditor
|
||||
{
|
||||
public struct OutputOptions
|
||||
{
|
||||
public OutputDirectoryType outputDirectoryType;
|
||||
public string customPath;
|
||||
}
|
||||
|
||||
public class OutputOptionsWindow : EditorWindow
|
||||
{
|
||||
private readonly AssetsProcessContext _context = new();
|
||||
|
||||
[SerializeField]
|
||||
private VisualTreeAsset _visualTreeAsset = default;
|
||||
[SerializeField]
|
||||
private OutputOptions _outputOptions;
|
||||
private OutputDirectoryType _outputDirectoryType;
|
||||
[SerializeField]
|
||||
private string _customPath;
|
||||
[SerializeField]
|
||||
private IEnumerable<Object> _sourceObjects;
|
||||
|
||||
@@ -30,60 +28,16 @@ namespace Misaki.ArtToolEditor
|
||||
private VisualElement _contentBeforeButton;
|
||||
private VisualElement _contentOnBottom;
|
||||
|
||||
private Func<Object, string, string> onOutput;
|
||||
private Action<string> postOutput;
|
||||
private OptionsVisualProvider _visualProvider;
|
||||
private IAssetsProcessor _processor;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the source objects for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="source"> The source objects to process. </param>
|
||||
public void WithSource(IEnumerable<Object> source) => _sourceObjects = source;
|
||||
public void WithItemSource(IEnumerable<Object> source) => _sourceObjects = source;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the output options for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="content"> The output options to set. </param>
|
||||
public void WithContentOnTop(Func<VisualElement> content) => _contentOnTop.Add(content());
|
||||
/// <summary>
|
||||
/// Sets the output options for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="content"> The output options to set. </param>
|
||||
public void WithContentAfterList(Func<VisualElement> content) => _contentAfterList.Add(content());
|
||||
/// <summary>
|
||||
/// Sets the output options for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="content"> The output options to set. </param>
|
||||
public void WithContentBeforeButton(Func<VisualElement> content) => _contentBeforeButton.Add(content());
|
||||
/// <summary>
|
||||
/// Sets the output options for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="content"> The output options to set. </param>
|
||||
public void WithContentOnBottom(Func<VisualElement> content) => _contentOnBottom.Add(content());
|
||||
public void RegisterVisualProvider<T>() where T : OptionsVisualProvider => _visualProvider = Activator.CreateInstance<T>();
|
||||
public void RegisterVisualProvider<T>(T visualProvider) where T : OptionsVisualProvider => _visualProvider = visualProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the output action for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="outputAction"> The output action to set.
|
||||
/// <para>The parameters of the Func are:</para>
|
||||
/// <para>- Object: The object to process.</para>
|
||||
/// <para>- string: The output directory.</para>
|
||||
/// The Func returns the path of the asset, which will be use later in the post output.</param>
|
||||
public void WithOutput(Func<Object, string, string> outputAction) => onOutput = outputAction;
|
||||
/// <summary>
|
||||
/// Sets the post output action for the output options window.
|
||||
/// </summary>
|
||||
/// <param name="postOutputAction"> The post output action to set. </param>
|
||||
public void WithPostOutput(Action<string> postOutputAction) => postOutput = postOutputAction;
|
||||
|
||||
public static OutputOptionsWindow ShowWindow(string title, IEnumerable<Object> source, Func<Object, string, string> outputAction)
|
||||
{
|
||||
var window = GetWindow<OutputOptionsWindow>(true, title);
|
||||
window.WithSource(source);
|
||||
window.WithOutput(outputAction);
|
||||
window.ShowUtility();
|
||||
|
||||
return window;
|
||||
}
|
||||
public void RegisterProcessor<T>() where T : IAssetsProcessor => _processor = Activator.CreateInstance<T>();
|
||||
public void RegisterProcessor<T>(T processor) where T : IAssetsProcessor => _processor = processor;
|
||||
|
||||
private void CreateGUI()
|
||||
{
|
||||
@@ -117,12 +71,19 @@ namespace Misaki.ArtToolEditor
|
||||
var outputButton = outPutOptions.Q<Button>("output-button");
|
||||
outputButton.clickable.clicked += () =>
|
||||
{
|
||||
if (_processor == null)
|
||||
{
|
||||
Debug.LogError("No processor has been registered");
|
||||
Close();
|
||||
}
|
||||
|
||||
if (_sourceObjects == null)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
var assetsToReload = new HashSet<string>();
|
||||
_processor.OnPreProcess(_context);
|
||||
|
||||
foreach (var obj in _sourceObjects)
|
||||
{
|
||||
var objectPath = AssetDatabase.GetAssetPath(obj);
|
||||
@@ -132,13 +93,10 @@ namespace Misaki.ArtToolEditor
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
}
|
||||
|
||||
assetsToReload.Add(onOutput?.Invoke(obj, outputDirectory));
|
||||
_processor.OnProcess(obj, outputDirectory, _context);
|
||||
}
|
||||
|
||||
foreach (var assetPath in assetsToReload)
|
||||
{
|
||||
postOutput?.Invoke(assetPath);
|
||||
}
|
||||
_processor.OnPostProcess(_context);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.SaveAssets();
|
||||
@@ -152,9 +110,39 @@ namespace Misaki.ArtToolEditor
|
||||
_contentOnBottom = outPutOptions.Q<VisualElement>("content-on-bottom");
|
||||
}
|
||||
|
||||
public void InitializeAndShow()
|
||||
{
|
||||
RecreateCustomOptions(_processor);
|
||||
ShowUtility();
|
||||
}
|
||||
|
||||
private void RecreateCustomOptions(object dataSource)
|
||||
{
|
||||
if (_visualProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_contentOnTop.Clear();
|
||||
_contentAfterList.Clear();
|
||||
_contentBeforeButton.Clear();
|
||||
_contentOnBottom.Clear();
|
||||
|
||||
_visualProvider.dataSource = dataSource;
|
||||
_contentOnTop.Add(_visualProvider.ContentOnTop());
|
||||
_contentAfterList.Add(_visualProvider.ContentAfterList());
|
||||
_contentBeforeButton.Add(_visualProvider.ContentBeforeButton());
|
||||
_contentOnBottom.Add(_visualProvider.ContentOnBottom());
|
||||
|
||||
_contentOnTop.dataSource = dataSource;
|
||||
_contentAfterList.dataSource = dataSource;
|
||||
_contentBeforeButton.dataSource = dataSource;
|
||||
_contentOnBottom.dataSource = dataSource;
|
||||
}
|
||||
|
||||
private string GetOutputDirectory(string inputDirectory)
|
||||
{
|
||||
switch (_outputOptions.outputDirectoryType)
|
||||
switch (_outputDirectoryType)
|
||||
{
|
||||
case OutputDirectoryType.CurrentDirectory:
|
||||
return inputDirectory;
|
||||
@@ -163,13 +151,13 @@ namespace Misaki.ArtToolEditor
|
||||
case OutputDirectoryType.AssetsDirectory:
|
||||
return "Assets";
|
||||
case OutputDirectoryType.Custom:
|
||||
if (Path.IsPathRooted(_outputOptions.customPath))
|
||||
if (Path.IsPathRooted(_customPath))
|
||||
{
|
||||
return _outputOptions.customPath;
|
||||
return _customPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(inputDirectory, _outputOptions.customPath);
|
||||
return Path.Combine(inputDirectory, _customPath);
|
||||
}
|
||||
default:
|
||||
return inputDirectory;
|
||||
|
||||
Reference in New Issue
Block a user