Add better error handling to particle system creation. Add skinned model -> animation graph workflow, though a bit hacky.

This commit is contained in:
Menotdan
2024-04-10 16:26:29 -04:00
parent ad8bec40bb
commit 48400ff5ce
3 changed files with 68 additions and 0 deletions

View File

@@ -91,6 +91,10 @@ namespace FlaxEditor.Content
}
ParticleEmitter emitter = FlaxEngine.Content.LoadAsync<ParticleEmitter>(particleItem.ID);
if (emitter == null || emitter.WaitForLoaded())
{
Editor.LogError("Failed to load base particle emitter.");
}
ParticleSystemPreview tempPreview = new ParticleSystemPreview(false);
ParticleSystemTimeline timeline = new ParticleSystemTimeline(tempPreview);

View File

@@ -2,6 +2,10 @@
using System;
using FlaxEditor.Content.Thumbnails;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Docking;
using FlaxEditor.Options;
using FlaxEditor.Surface;
using FlaxEditor.Viewport.Previews;
using FlaxEditor.Windows;
using FlaxEditor.Windows.Assets;
@@ -39,6 +43,57 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override Type AssetType => typeof(SkinnedModel);
/// <inheritdoc />
public override void OnContentWindowContextMenu(ContextMenu menu, ContentItem item)
{
base.OnContentWindowContextMenu(menu, item);
if (item is BinaryAssetItem binaryAssetItem)
{
var button = menu.AddButton("Create Animation Graph", CreateAnimationGraphClicked);
button.Tag = binaryAssetItem;
}
}
private void CreateAnimationGraphClicked(ContextMenuButton obj)
{
var binaryAssetItem = (BinaryAssetItem)obj.Tag;
CreateAnimationGraph(binaryAssetItem);
}
/// <summary>
/// Creates the animation graph from the given particle emitter.
/// </summary>
/// <param name="skinnedModelItem">The skinned model item to use as the base model for the animation graph.</param>
public static void CreateAnimationGraph(BinaryAssetItem skinnedModelItem)
{
var animationGraphName = skinnedModelItem.ShortName + " Graph";
var animationGraphProxy = Editor.Instance.ContentDatabase.GetProxy<AnimationGraph>();
Editor.Instance.Windows.ContentWin.NewItem(animationGraphProxy, null, item => OnAnimationGraphCreated(item, skinnedModelItem), animationGraphName);
}
private static void OnAnimationGraphCreated(ContentItem item, BinaryAssetItem skinnedModelItem)
{
var skinnedModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(skinnedModelItem.ID);
if (skinnedModel == null || skinnedModel.WaitForLoaded())
{
Editor.LogError("Failed to load base skinned model.");
}
// Hack the animation graph window to modify the base model of the animation graph.
AnimationGraphWindow win = new AnimationGraphWindow(Editor.Instance, item as AssetItem);
win.Show();
// Ensure the window knows the asset is loaded so we can save it later.
win.Asset.WaitForLoaded();
win.Update(0); // Call Update() to refresh the loaded flag.
win.SetBaseModel(skinnedModel);
win.Surface.MarkAsEdited();
win.Save();
win.Close();
}
/// <inheritdoc />
public override void OnThumbnailDrawPrepare(ThumbnailRequest request)
{

View File

@@ -295,6 +295,15 @@ namespace FlaxEditor.Windows.Assets
base.SetParameter(index, value);
}
/// <summary>
/// Sets the base model of the animation graph this window is editing.
/// </summary>
/// <param name="baseModel">The new base model.</param>
public void SetBaseModel(SkinnedModel baseModel)
{
_properties.BaseModel = baseModel;
}
/// <inheritdoc />
protected override void UnlinkItem()
{