Fix errors in Editor when editing particle emitter if effect that uses it is selected

This commit is contained in:
Wojtek Figat
2022-07-24 11:55:00 +02:00
parent 74e3d1ad8f
commit 2dfd676c5e
3 changed files with 32 additions and 11 deletions

View File

@@ -241,7 +241,7 @@ namespace FlaxEditor.CustomEditors
} }
} }
internal void RefreshRootChild() internal virtual void RefreshRootChild()
{ {
Refresh(); Refresh();

View File

@@ -14,6 +14,8 @@ namespace FlaxEditor.CustomEditors.Dedicated
public class ParticleEffectEditor : ActorEditor public class ParticleEffectEditor : ActorEditor
{ {
private bool _isValid; private bool _isValid;
private bool _isActive;
private uint _parametersVersion;
private bool IsValid private bool IsValid
{ {
@@ -54,18 +56,20 @@ namespace FlaxEditor.CustomEditors.Dedicated
_isValid = IsValid; _isValid = IsValid;
if (!_isValid) if (!_isValid)
return; return;
var effect = (ParticleEffect)Values[0];
_parametersVersion = effect.ParametersVersion;
_isActive = effect.IsActive;
// Show all effect parameters grouped by the emitter track name // Show all effect parameters grouped by the emitter track name
var effect = (ParticleEffect)Values[0];
var groups = layout.Group("Parameters"); var groups = layout.Group("Parameters");
groups.Panel.Open(false); groups.Panel.Open();
var parameters = effect.Parameters; var parameters = effect.Parameters;
var parametersGroups = parameters.GroupBy(x => x.EmitterIndex); var parametersGroups = parameters.GroupBy(x => x.EmitterIndex);
foreach (var parametersGroup in parametersGroups) foreach (var parametersGroup in parametersGroups)
{ {
var trackName = parametersGroup.First().TrackName; var trackName = parametersGroup.First().TrackName;
var group = groups.Group(trackName); var group = groups.Group(trackName);
group.Panel.Open(false); group.Panel.Open();
var data = SurfaceUtils.InitGraphParameters(parametersGroup); var data = SurfaceUtils.InitGraphParameters(parametersGroup);
SurfaceUtils.DisplayGraphParameters(group, data, ParameterGet, ParameterSet, Values, ParameterDefaultValue); SurfaceUtils.DisplayGraphParameters(group, data, ParameterGet, ParameterSet, Values, ParameterDefaultValue);
@@ -73,15 +77,32 @@ namespace FlaxEditor.CustomEditors.Dedicated
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Refresh() internal override void RefreshRootChild()
{ {
var effect = (ParticleEffect)Values[0];
if (effect == null)
{
base.RefreshRootChild();
return;
}
// Custom refreshing that handles particle effect parameters list editing during refresh (eg. effect gets disabled)
if (_isValid != IsValid) if (_isValid != IsValid)
{ {
RebuildLayout(); RebuildLayout();
return; return;
} }
Refresh();
base.Refresh(); var parameters = effect.Parameters;
for (int i = 0; i < ChildrenEditors.Count; i++)
{
if (_isActive != effect.IsActive || _parametersVersion != effect.ParametersVersion)
{
RebuildLayout();
return;
}
ChildrenEditors[i].RefreshInternal();
}
} }
} }
} }

View File

@@ -241,7 +241,7 @@ namespace FlaxEngine.GUI
/// Opens the group. /// Opens the group.
/// </summary> /// </summary>
/// <param name="animate">Enable/disable animation feature.</param> /// <param name="animate">Enable/disable animation feature.</param>
public void Open(bool animate = true) public void Open(bool animate = false)
{ {
// Check if state will change // Check if state will change
if (_isClosed) if (_isClosed)
@@ -265,7 +265,7 @@ namespace FlaxEngine.GUI
/// Closes the group. /// Closes the group.
/// </summary> /// </summary>
/// <param name="animate">Enable/disable animation feature.</param> /// <param name="animate">Enable/disable animation feature.</param>
public void Close(bool animate = true) public void Close(bool animate = false)
{ {
// Check if state will change // Check if state will change
if (!_isClosed) if (!_isClosed)
@@ -291,9 +291,9 @@ namespace FlaxEngine.GUI
public void Toggle() public void Toggle()
{ {
if (_isClosed) if (_isClosed)
Open(); Open(true);
else else
Close(); Close(true);
} }
/// <inheritdoc /> /// <inheritdoc />