Skip to content

Commit 297a03b

Browse files
authored
CU-868fbqk0h: Add Auto Resolve button to SceneExportWindow (#25)
Pressing the button and confirming the message that follows will automatically resolve the following issues: - CustomScriptFound by removing the script from the gameobject - CameraFound by deleting camera gameobjects - AudioListenerFound by deleting the AudioListener component - EventSystemFound by deleting event system gameobjects - NoUserAreaProviderFound by creating a new gameobject and attaching MonoCircularUserAreaProvider component to it All the above changes are undoable using Ctrl+Z.
2 parents 390432a + 89b9559 commit 297a03b

File tree

3 files changed

+88
-13
lines changed

3 files changed

+88
-13
lines changed

Assets/MXRUS/Editor/SceneExportValidator.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ private List<SceneExportViolation> GetScriptViolations() {
128128
true,
129129
"Custom scripts/components are not supported. Please remove or disable the gameobjects on the scene referencing them.",
130130
x
131-
)).ToList();
131+
).SetAutoResolver("Custom scripts attached to GameObjects in the scene will be removed.", obj => {
132+
Undo.DestroyObjectImmediate(obj as MonoBehaviour);
133+
}))
134+
.ToList();
132135
}
133136

134137
/// <summary>
@@ -142,7 +145,11 @@ private List<SceneExportViolation> GetCameraViolations() {
142145
true,
143146
"Scene cameras are not supported. Please remove cameras from the scene.",
144147
x
145-
)).ToList();
148+
)
149+
.SetAutoResolver("GameObjects in the scene with Camera component will be destroyed.", obj => {
150+
Undo.DestroyObjectImmediate((obj as Camera).gameObject);
151+
})
152+
).ToList();
146153
}
147154

148155
/// <summary>
@@ -178,7 +185,10 @@ private List<SceneExportViolation> GetAudioListenerViolations() {
178185
"The scene cannot have any AudioListeners. When running in the ManageXR " +
179186
"Homescreen, an AudioListener would already be present.",
180187
x
181-
)).ToList();
188+
).SetAutoResolver("AudioListener components in the scene will be removed from their GameObjects.", obj => {
189+
Undo.DestroyObjectImmediate(obj as AudioListener);
190+
})
191+
).ToList();
182192
}
183193

184194
/// <summary>
@@ -192,7 +202,10 @@ private List<SceneExportViolation> GetEventSystemViolations() {
192202
true,
193203
"There cannot be an EventSystem on the scene. Please remove them from the scene.",
194204
x
195-
)).ToList();
205+
).SetAutoResolver("GameObjects in the scene with EventSystem component will be destroyed.", obj => {
206+
Undo.DestroyObjectImmediate((obj as EventSystem).gameObject);
207+
})
208+
).ToList();
196209
}
197210

198211
/// <summary>
@@ -206,9 +219,15 @@ private List<SceneExportViolation> GetUserAreaViolations() {
206219
new SceneExportViolation (
207220
SceneExportViolation.Types.NoUserAreaProviderFound,
208221
true,
209-
"No MonoUserAreaProvider component found on the scene.",
222+
"No user area provider found on the scene.",
210223
null
211-
)
224+
).SetAutoResolver("A new GameObject will be added to the scene with a user area provider.", obj =>{
225+
var userAreaProvider = new GameObject("User Area Provider");
226+
userAreaProvider.AddComponent<MonoCircularUserAreaProvider>();
227+
Selection.activeGameObject = userAreaProvider;
228+
SceneView.lastActiveSceneView.FrameSelected();
229+
Undo.RegisterCreatedObjectUndo(userAreaProvider, "Created User Area Provider");
230+
})
212231
};
213232
else if (userAreas.Length > 1) {
214233
return userAreas.Select(x => new SceneExportViolation(

Assets/MXRUS/Editor/SceneExportViolation.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using UnityEngine;
1+
using System;
2+
3+
using UnityEngine;
4+
5+
using Object = UnityEngine.Object;
26

37
namespace MXRUS.SDK.Editor {
48
internal class SceneExportViolation {
@@ -72,6 +76,18 @@ public enum Types {
7276
/// </summary>
7377
public bool PreventsExport { get; private set; }
7478

79+
/// <summary>
80+
/// Whether this violation can be automatically resolved
81+
/// by the scene export window
82+
/// </summary>
83+
public bool CanBeAutoResolved { get; private set; }
84+
85+
/// <summary>
86+
/// The confirmation message to be shown when the user
87+
/// attempts to auto resolve this violation.
88+
/// </summary>
89+
public string AutoResolveConfirmationMessage { get; private set; }
90+
7591
/// <summary>
7692
/// Description of the violation
7793
/// </summary>
@@ -82,11 +98,26 @@ public enum Types {
8298
/// </summary>
8399
public Object Object { get; private set; }
84100

101+
private Action<Object> _resolveMethod;
102+
85103
public SceneExportViolation(Types type, bool preventsExport, string description, Object obj = null) {
86104
Type = type;
87105
PreventsExport = preventsExport;
88106
Description = description;
89107
Object = obj;
90108
}
109+
110+
public SceneExportViolation SetAutoResolver(string message, Action<Object> resolveMethod) {
111+
AutoResolveConfirmationMessage = message;
112+
CanBeAutoResolved = true;
113+
_resolveMethod = resolveMethod;
114+
return this;
115+
}
116+
117+
public void AutoResolve() {
118+
if (CanBeAutoResolved) {
119+
_resolveMethod?.Invoke(Object);
120+
}
121+
}
91122
}
92123
}

Assets/MXRUS/Editor/SceneExportWindow.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,38 @@ private void ShowViolationsSummary() {
207207

208208
var preventsExport = first.PreventsExport;
209209
var description = first.Description;
210+
var canBeAutoResolved = first.CanBeAutoResolved;
211+
212+
// Show the violation type with the Auto Resolve button, if applicable for this violation type
213+
EditorGUILayout.BeginHorizontal();
214+
{
215+
_foldoutStates[i] = EditorGUILayout.Foldout(
216+
_foldoutStates[i],
217+
$"{_violationTypes[i]} {(preventsExport ? " (Error)" : " (Warning)")}",
218+
true,
219+
preventsExport ? _errorFoldoutStyle : _warningFoldoutStyle
220+
);
221+
if (canBeAutoResolved) {
222+
GUILayout.Label("");
223+
if (GUILayout.Button("Auto Resolve")) {
224+
var accepted = EditorUtility.DisplayDialog(
225+
"Auto Resolving",
226+
first.AutoResolveConfirmationMessage + "\n\nDo you want to proceed?",
227+
"OK"
228+
);
229+
if (accepted) {
230+
foreach (var violationToResolve in violations) {
231+
violationToResolve.AutoResolve();
232+
}
233+
Validate();
234+
EditorGUILayout.EndHorizontal();
235+
return;
236+
}
237+
}
238+
}
239+
}
240+
EditorGUILayout.EndHorizontal();
210241

211-
_foldoutStates[i] = EditorGUILayout.Foldout(
212-
_foldoutStates[i],
213-
$"{_violationTypes[i]} {(preventsExport ? " (Error)" : " (Warning)")}",
214-
true,
215-
preventsExport ? _errorFoldoutStyle : _warningFoldoutStyle
216-
);
217242
EditorGUILayout.Space(10);
218243

219244
if (!_foldoutStates[i]) continue;

0 commit comments

Comments
 (0)