|
5 | 5 | using System;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.Linq;
|
| 8 | +using UnityEditor.Profiling; |
8 | 9 | using UnityEngine;
|
9 | 10 | using UnityEngine.Scripting;
|
10 | 11 | using UnityEngine.UIElements;
|
@@ -83,6 +84,23 @@ protected override void OnEnable()
|
83 | 84 |
|
84 | 85 | EditorApplication.projectWasLoaded += OnProjectWasLoaded;
|
85 | 86 | Selection.selectionChanged += OnSelectionChanged;
|
| 87 | + AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload; |
| 88 | + } |
| 89 | + |
| 90 | + private void OnAfterAssemblyReload() |
| 91 | + { |
| 92 | + // Case 1348788: After reloading the assemblies after a script compilation, |
| 93 | + // active editors are not rebuilt automatically. If a custom editor changed |
| 94 | + // the way it handles multi object editing you won't see the effect in the inspector unless |
| 95 | + // you change the selection. It is a minor issue. But this call makes sure to rebuild the active |
| 96 | + // editors if necessary. |
| 97 | + // Note: This is only a problem when adding the attribute CanEditMultipleObjects. When the attribute is not |
| 98 | + // there, the editor used for multi editing is the generic inspector. If you add the CanEditMultipleObjects attribute, |
| 99 | + // a refresh is triggered and we check if the editor instance is still valid, which is the case for the generic inspector |
| 100 | + // so we don't rebuild it. When removing the CanEditMultipleObjects, the refresh sees that the editor was the custom inspector |
| 101 | + // but its instance is no longer valid, so it rebuilds the inspector. |
| 102 | + if (EditorsForMultiEditingChanged()) |
| 103 | + tracker.ForceRebuild(); |
86 | 104 | }
|
87 | 105 |
|
88 | 106 | private void OnProjectWasLoaded()
|
@@ -127,6 +145,7 @@ protected override void OnDisable()
|
127 | 145 |
|
128 | 146 | EditorApplication.projectWasLoaded -= OnProjectWasLoaded;
|
129 | 147 | Selection.selectionChanged -= OnSelectionChanged;
|
| 148 | + AssemblyReloadEvents.afterAssemblyReload -= OnAfterAssemblyReload; |
130 | 149 | }
|
131 | 150 |
|
132 | 151 | static internal void RepaintAllInspectors()
|
@@ -438,5 +457,30 @@ internal Object[] GetInspectedObjects()
|
438 | 457 | return null;
|
439 | 458 | return editor.targets;
|
440 | 459 | }
|
| 460 | + |
| 461 | + private bool EditorsForMultiEditingChanged() |
| 462 | + { |
| 463 | + foreach (var editor in tracker.activeEditors) |
| 464 | + { |
| 465 | + if (EditorForMultiEditingChanged(editor, editor.target)) |
| 466 | + return true; |
| 467 | + } |
| 468 | + |
| 469 | + return false; |
| 470 | + } |
| 471 | + |
| 472 | + private static bool EditorForMultiEditingChanged(Editor editor, Object target) |
| 473 | + { |
| 474 | + if (editor.targets.Length <= 1) |
| 475 | + return false; |
| 476 | + |
| 477 | + var currentEditorType = editor.GetType(); |
| 478 | + var expectedEditorType = CustomEditorAttributes.FindCustomEditorType(target, true); |
| 479 | + |
| 480 | + // Going from generic to generic inspector for multi editing is correctly handled. |
| 481 | + if (editor is GenericInspector && expectedEditorType == null) |
| 482 | + return false; |
| 483 | + return currentEditorType != expectedEditorType; |
| 484 | + } |
441 | 485 | }
|
442 | 486 | }
|
0 commit comments