Skip to content

Hd/fix undo environmentlibrary lookdev #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with the shader TransformWorldToHClipDir function computing the wrong result.
- Fixed division by zero in `V_SmithJointGGX` function.
- Fixed null reference exception in LookDev when setting the SRP to one not implementing LookDev (case 1245086)
- Fix LookDev's undo/redo on EnvironmentLibrary (case 1234725)

### Changed
- Restored usage of ENABLE_VR to fix compilation errors on some platforms.
Expand Down
12 changes: 12 additions & 0 deletions com.unity.render-pipelines.core/Editor/LookDev/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ internal bool HasLibraryAssetChanged(EnvironmentLibrary environmentLibrary)

return m_EnvironmentLibraryGUID != AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(environmentLibrary));
}

internal void FullReimportEnvironmentLibrary()
{
if (environmentLibrary == null)
return;

// refresh AssetDatabase in case of undo/redo creating/destructing environment subasset
string libraryPath = AssetDatabase.GetAssetPath(environmentLibrary);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(environmentLibrary), ImportAssetOptions.DontDownloadFromCacheServer | ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive);
UpdateEnvironmentLibrary(AssetDatabase.LoadAssetAtPath<EnvironmentLibrary>(libraryPath));
EditorUtility.SetDirty(environmentLibrary);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,13 @@ void OnFocus()
((IEnvironmentDisplayer)this).Repaint();
}
}

void FullRefreshEnvironmentList()
{
if (LookDev.currentContext.environmentLibrary != null)
LookDev.currentContext.FullReimportEnvironmentLibrary();

((IEnvironmentDisplayer)this).Repaint();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,15 @@ void OnEnable()

ApplyLayout(viewLayout);
ApplySidePanelChange(layout.showedSidePanel);

Undo.undoRedoPerformed += FullRefreshEnvironmentList;
}

void OnDisable() => OnClosedInternal?.Invoke();
void OnDisable()
{
Undo.undoRedoPerformed -= FullRefreshEnvironmentList;
OnClosedInternal?.Invoke();
}

void CreateToolbar()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ public class EnvironmentLibrary : ScriptableObject
/// <returns>The created Environment</returns>
public Environment Add()
{
Undo.SetCurrentGroupName("Add Environment");
int group = Undo.GetCurrentGroup();

Environment environment = ScriptableObject.CreateInstance<Environment>();
environment.name = "New Environment";
Undo.RegisterCreatedObjectUndo(environment, "Add Environment");

Undo.RecordObject(this, "Add Environment");
environments.Add(environment);

// Store this new environment as a subasset so we can reference it safely afterwards.
AssetDatabase.AddObjectToAsset(environment, this);

Undo.CollapseUndoOperations(group);

// Force save / refresh. Important to do this last because SaveAssets can cause effect to become null!
EditorUtility.SetDirty(this);
AssetDatabase.SaveAssets();
Expand All @@ -54,11 +60,16 @@ public Environment Add()
/// <param name="index">Index where to remove Environment</param>
public void Remove(int index)
{
Undo.SetCurrentGroupName("Remove Environment");
int group = Undo.GetCurrentGroup();

Environment environment = environments[index];
Undo.RecordObject(this, "Remove Environment");
environments.RemoveAt(index);
Undo.DestroyObjectImmediate(environment);

Undo.CollapseUndoOperations(group);

// Force save / refresh
EditorUtility.SetDirty(this);
AssetDatabase.SaveAssets();
Expand Down