Skip to content

Commit 3e08b48

Browse files
Hd/fix undo environmentlibrary lookdev (#490)
* fix undo redo for environment library * Update CHANGELOG.md Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent b8ee34d commit 3e08b48

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

com.unity.render-pipelines.core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4242
- Fixed issue with the shader TransformWorldToHClipDir function computing the wrong result.
4343
- Fixed division by zero in `V_SmithJointGGX` function.
4444
- Fixed null reference exception in LookDev when setting the SRP to one not implementing LookDev (case 1245086)
45+
- Fix LookDev's undo/redo on EnvironmentLibrary (case 1234725)
4546

4647
### Changed
4748
- Restored usage of ENABLE_VR to fix compilation errors on some platforms.

com.unity.render-pipelines.core/Editor/LookDev/Context.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ internal bool HasLibraryAssetChanged(EnvironmentLibrary environmentLibrary)
264264

265265
return m_EnvironmentLibraryGUID != AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(environmentLibrary));
266266
}
267+
268+
internal void FullReimportEnvironmentLibrary()
269+
{
270+
if (environmentLibrary == null)
271+
return;
272+
273+
// refresh AssetDatabase in case of undo/redo creating/destructing environment subasset
274+
string libraryPath = AssetDatabase.GetAssetPath(environmentLibrary);
275+
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(environmentLibrary), ImportAssetOptions.DontDownloadFromCacheServer | ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive);
276+
UpdateEnvironmentLibrary(AssetDatabase.LoadAssetAtPath<EnvironmentLibrary>(libraryPath));
277+
EditorUtility.SetDirty(environmentLibrary);
278+
}
267279
}
268280

269281
/// <summary>

com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.EnvironmentLibrarySidePanel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,5 +463,13 @@ void OnFocus()
463463
((IEnvironmentDisplayer)this).Repaint();
464464
}
465465
}
466+
467+
void FullRefreshEnvironmentList()
468+
{
469+
if (LookDev.currentContext.environmentLibrary != null)
470+
LookDev.currentContext.FullReimportEnvironmentLibrary();
471+
472+
((IEnvironmentDisplayer)this).Repaint();
473+
}
466474
}
467475
}

com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ void OnEnable()
259259

260260
ApplyLayout(viewLayout);
261261
ApplySidePanelChange(layout.showedSidePanel);
262+
263+
Undo.undoRedoPerformed += FullRefreshEnvironmentList;
262264
}
263265

264-
void OnDisable() => OnClosedInternal?.Invoke();
266+
void OnDisable()
267+
{
268+
Undo.undoRedoPerformed -= FullRefreshEnvironmentList;
269+
OnClosedInternal?.Invoke();
270+
}
265271

266272
void CreateToolbar()
267273
{

com.unity.render-pipelines.core/Editor/LookDev/EnvironmentLibrary.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ public class EnvironmentLibrary : ScriptableObject
3232
/// <returns>The created Environment</returns>
3333
public Environment Add()
3434
{
35+
Undo.SetCurrentGroupName("Add Environment");
36+
int group = Undo.GetCurrentGroup();
37+
3538
Environment environment = ScriptableObject.CreateInstance<Environment>();
3639
environment.name = "New Environment";
3740
Undo.RegisterCreatedObjectUndo(environment, "Add Environment");
3841

42+
Undo.RecordObject(this, "Add Environment");
3943
environments.Add(environment);
4044

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

48+
Undo.CollapseUndoOperations(group);
49+
4450
// Force save / refresh. Important to do this last because SaveAssets can cause effect to become null!
4551
EditorUtility.SetDirty(this);
4652
AssetDatabase.SaveAssets();
@@ -54,11 +60,16 @@ public Environment Add()
5460
/// <param name="index">Index where to remove Environment</param>
5561
public void Remove(int index)
5662
{
63+
Undo.SetCurrentGroupName("Remove Environment");
64+
int group = Undo.GetCurrentGroup();
65+
5766
Environment environment = environments[index];
5867
Undo.RecordObject(this, "Remove Environment");
5968
environments.RemoveAt(index);
6069
Undo.DestroyObjectImmediate(environment);
6170

71+
Undo.CollapseUndoOperations(group);
72+
6273
// Force save / refresh
6374
EditorUtility.SetDirty(this);
6475
AssetDatabase.SaveAssets();

0 commit comments

Comments
 (0)