Fix materials parameters display issues after editing

This commit is contained in:
Wojtek Figat
2021-08-18 22:55:31 +02:00
parent 540643972a
commit fff2c3e038
5 changed files with 43 additions and 31 deletions

View File

@@ -604,7 +604,7 @@ namespace FlaxEditor.Surface
Parent = this Parent = this
}; };
Presenter = new CustomEditorPresenter(undo); Presenter = new CustomEditorPresenter(undo, "Loading...");
Presenter.Panel.Parent = scrollPanel; Presenter.Panel.Parent = scrollPanel;
} }
@@ -744,7 +744,7 @@ namespace FlaxEditor.Surface
} }
else else
{ {
_propertiesEditor = new CustomEditorPresenter(_undo); _propertiesEditor = new CustomEditorPresenter(_undo, "Loading...");
_propertiesEditor.Panel.Parent = _split2.Panel2; _propertiesEditor.Panel.Parent = _split2.Panel2;
} }
_propertiesEditor.Modified += OnPropertyEdited; _propertiesEditor.Modified += OnPropertyEdited;
@@ -896,6 +896,16 @@ namespace FlaxEditor.Surface
Close(); Close();
} }
/// <summary>
/// Called when surface gets loaded and user can edit it.
/// </summary>
protected virtual void OnSurfaceEditingStart()
{
_undo.Clear();
_surface.Enabled = true;
_propertiesEditor.BuildLayout();
}
/// <summary> /// <summary>
/// Loads the surface from the asset. Called during <see cref="Update"/> when asset is loaded and surface is missing. /// Loads the surface from the asset. Called during <see cref="Update"/> when asset is loaded and surface is missing.
/// </summary> /// </summary>
@@ -939,10 +949,7 @@ namespace FlaxEditor.Surface
return; return;
} }
// Setup OnSurfaceEditingStart();
_undo.Clear();
_surface.Enabled = true;
_propertiesEditor.BuildLayout();
ClearEditedFlag(); ClearEditedFlag();
if (_showWholeGraphOnLoad) if (_showWholeGraphOnLoad)
{ {

View File

@@ -186,7 +186,6 @@ namespace FlaxEditor.Windows.Assets
// Asset properties proxy // Asset properties proxy
_properties = new PropertiesProxy(); _properties = new PropertiesProxy();
_propertiesEditor.Select(_properties);
// Preview properties editor // Preview properties editor
_previewTab = new Tab("Preview"); _previewTab = new Tab("Preview");
@@ -322,22 +321,17 @@ namespace FlaxEditor.Windows.Assets
{ {
if (value == null) if (value == null)
{ {
// Error
Editor.LogError("Failed to save animation graph surface"); Editor.LogError("Failed to save animation graph surface");
return; return;
} }
// Save data to the temporary asset
if (_asset.SaveSurface(value)) if (_asset.SaveSurface(value))
{ {
// Error
_surface.MarkAsEdited(); _surface.MarkAsEdited();
Editor.LogError("Failed to save animation graph surface data"); Editor.LogError("Failed to save animation graph surface data");
return; return;
} }
_asset.Reload(); _asset.Reload();
_asset.WaitForLoaded();
// Reset any root motion
_preview.PreviewActor.ResetLocalTransform(); _preview.PreviewActor.ResetLocalTransform();
_previewTab.Presenter.BuildLayoutOnUpdate(); _previewTab.Presenter.BuildLayoutOnUpdate();
} }
@@ -376,6 +370,14 @@ namespace FlaxEditor.Windows.Assets
return false; return false;
} }
/// <inheritdoc />
protected override void OnSurfaceEditingStart()
{
_propertiesEditor.Select(_properties);
base.OnSurfaceEditingStart();
}
/// <inheritdoc /> /// <inheritdoc />
protected override void PerformLayoutBeforeChildren() protected override void PerformLayoutBeforeChildren()
{ {

View File

@@ -229,7 +229,7 @@ namespace FlaxEditor.Windows.Assets
layout.Label("No parameters"); layout.Label("No parameters");
return; return;
} }
if (!materialInstance.IsLoaded || materialInstance.BaseMaterial && !materialInstance.BaseMaterial.IsLoaded) if (!materialInstance.IsLoaded || (materialInstance.BaseMaterial && !materialInstance.BaseMaterial.IsLoaded))
{ {
layout.Label("Loading..."); layout.Label("Loading...");
return; return;
@@ -352,10 +352,9 @@ namespace FlaxEditor.Windows.Assets
}; };
// Material properties editor // Material properties editor
_editor = new CustomEditorPresenter(_undo); _editor = new CustomEditorPresenter(_undo, "Loading...");
_editor.Panel.Parent = _split.Panel2; _editor.Panel.Parent = _split.Panel2;
_properties = new PropertiesProxy(); _properties = new PropertiesProxy();
_editor.Select(_properties);
_editor.Modified += OnMaterialPropertyEdited; _editor.Modified += OnMaterialPropertyEdited;
// Setup input actions // Setup input actions
@@ -479,16 +478,11 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc /> /// <inheritdoc />
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
// Check if need to load
if (_isWaitingForLoad && _asset.IsLoaded && (_asset.BaseMaterial == null || _asset.BaseMaterial.IsLoaded)) if (_isWaitingForLoad && _asset.IsLoaded && (_asset.BaseMaterial == null || _asset.BaseMaterial.IsLoaded))
{ {
// Clear flag
_isWaitingForLoad = false; _isWaitingForLoad = false;
// Init material properties and parameters proxy
_properties.OnLoad(this); _properties.OnLoad(this);
_editor.Select(_properties);
// Setup
ClearEditedFlag(); ClearEditedFlag();
_undo.Clear(); _undo.Clear();
_editor.BuildLayout(); _editor.BuildLayout();

View File

@@ -222,7 +222,6 @@ namespace FlaxEditor.Windows.Assets
// Asset properties proxy // Asset properties proxy
_properties = new PropertiesProxy(); _properties = new PropertiesProxy();
_propertiesEditor.Select(_properties);
// Surface // Surface
_surface = new MaterialSurface(this, Save, _undo) _surface = new MaterialSurface(this, Save, _undo)
@@ -324,17 +323,14 @@ namespace FlaxEditor.Windows.Assets
get => _asset.LoadSurface(true); get => _asset.LoadSurface(true);
set set
{ {
// Create material info
FillMaterialInfo(out var info); FillMaterialInfo(out var info);
// Save data to the temporary material
if (_asset.SaveSurface(value, info)) if (_asset.SaveSurface(value, info))
{ {
// Error
_surface.MarkAsEdited(); _surface.MarkAsEdited();
Editor.LogError("Failed to save material surface data"); Editor.LogError("Failed to save material surface data");
} }
_asset.Reload(); _asset.Reload();
_asset.WaitForLoaded();
} }
} }
@@ -347,7 +343,6 @@ namespace FlaxEditor.Windows.Assets
// Load surface graph // Load surface graph
if (_surface.Load()) if (_surface.Load())
{ {
// Error
Editor.LogError("Failed to load material surface."); Editor.LogError("Failed to load material surface.");
return true; return true;
} }
@@ -362,6 +357,14 @@ namespace FlaxEditor.Windows.Assets
return false; return false;
} }
/// <inheritdoc />
protected override void OnSurfaceEditingStart()
{
_propertiesEditor.Select(_properties);
base.OnSurfaceEditingStart();
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool CanEditSurfaceOnAssetLoadError => true; protected override bool CanEditSurfaceOnAssetLoadError => true;

View File

@@ -120,7 +120,6 @@ namespace FlaxEditor.Windows.Assets
// Asset properties proxy // Asset properties proxy
_properties = new PropertiesProxy(); _properties = new PropertiesProxy();
_propertiesEditor.Select(_properties);
// Preview properties editor // Preview properties editor
_previewTab = new Tab("Preview"); _previewTab = new Tab("Preview");
@@ -217,14 +216,13 @@ namespace FlaxEditor.Windows.Assets
get => _asset.LoadSurface(true); get => _asset.LoadSurface(true);
set set
{ {
// Save data to the temporary asset
if (_asset.SaveSurface(value)) if (_asset.SaveSurface(value))
{ {
// Error
_surface.MarkAsEdited(); _surface.MarkAsEdited();
Editor.LogError("Failed to save Particle Emitter surface data"); Editor.LogError("Failed to save Particle Emitter surface data");
} }
_asset.Reload(); _asset.Reload();
_asset.WaitForLoaded();
_preview.PreviewActor.ResetSimulation(); _preview.PreviewActor.ResetSimulation();
_previewTab.Presenter.BuildLayoutOnUpdate(); _previewTab.Presenter.BuildLayoutOnUpdate();
} }
@@ -255,6 +253,14 @@ namespace FlaxEditor.Windows.Assets
return false; return false;
} }
/// <inheritdoc />
protected override void OnSurfaceEditingStart()
{
_propertiesEditor.Select(_properties);
base.OnSurfaceEditingStart();
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool SaveToOriginal() protected override bool SaveToOriginal()
{ {