Skip to content

Commit

Permalink
style(editor): DisabledGroup scoping
Browse files Browse the repository at this point in the history
Code between calls EditorGUI.BeginDisabledGroup and EditorGUI.EndDisabledGroup scoped for clarity.
  • Loading branch information
scoan-sd committed Jul 23, 2022
1 parent 7bf06ba commit e721567
Showing 1 changed file with 66 additions and 55 deletions.
121 changes: 66 additions & 55 deletions Editor/LODGeneratorHelperEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,28 @@ private void DrawGeneratedView()
private void DrawNotGeneratedView()
{
EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == true);
EditorGUILayout.ObjectField(lodGeneratorPresetProperty, typeof(LODGeneratorPreset));
{
EditorGUILayout.ObjectField(lodGeneratorPresetProperty, typeof(LODGeneratorPreset));
}
EditorGUI.EndDisabledGroup();

EditorGUILayout.PropertyField(customizeSettingsProperty);

EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == false);
EditorGUILayout.PropertyField(fadeModeProperty);
{
EditorGUILayout.PropertyField(fadeModeProperty);
}
EditorGUI.EndDisabledGroup();
var fadeMode = (LODFadeMode)fadeModeProperty.intValue;

bool hasCrossFade = (fadeMode == LODFadeMode.CrossFade || fadeMode == LODFadeMode.SpeedTree);

EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == false);
if (hasCrossFade)
{
EditorGUILayout.PropertyField(animateCrossFadingProperty);
if (hasCrossFade)
{
EditorGUILayout.PropertyField(animateCrossFadingProperty);
}
}
EditorGUI.EndDisabledGroup();

Expand Down Expand Up @@ -196,9 +202,11 @@ private void DrawNotGeneratedView()
}

EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == false);
if (GUILayout.Button(createLevelButtonContent))
{
CreateLevel();
if (GUILayout.Button(createLevelButtonContent))
{
CreateLevel();
}
}
EditorGUI.EndDisabledGroup();

Expand Down Expand Up @@ -231,72 +239,75 @@ private void DrawSimplificationOptions()

private void DrawLevel(int index, SerializedProperty levelProperty, bool hasCrossFade)
{
EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == false);
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
GUILayout.Label(string.Format("Level {0}", index + 1), EditorStyles.boldLabel);
var renderersProperty = levelProperty.FindPropertyRelative(LevelRenderersFieldName);

var previousBackgroundColor = GUI.backgroundColor;
GUI.backgroundColor = removeColor;
if (GUILayout.Button(deleteLevelButtonContent, GUILayout.Width(RemoveLevelButtonSize)))
EditorGUI.BeginDisabledGroup(customizeSettingsProperty.boolValue == false);
{
DeleteLevel(index);
}
GUI.backgroundColor = previousBackgroundColor;
EditorGUILayout.EndHorizontal();

++EditorGUI.indentLevel;

var screenRelativeHeightProperty = levelProperty.FindPropertyRelative(LevelScreenRelativeHeightFieldName);
EditorGUILayout.PropertyField(screenRelativeHeightProperty);
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
GUILayout.Label(string.Format("Level {0}", index + 1), EditorStyles.boldLabel);

var qualityProperty = levelProperty.FindPropertyRelative(LevelQualityFieldName);
EditorGUILayout.PropertyField(qualityProperty);
var previousBackgroundColor = GUI.backgroundColor;
GUI.backgroundColor = removeColor;
if (GUILayout.Button(deleteLevelButtonContent, GUILayout.Width(RemoveLevelButtonSize)))
{
DeleteLevel(index);
}
GUI.backgroundColor = previousBackgroundColor;
EditorGUILayout.EndHorizontal();

bool animateCrossFading = (hasCrossFade ? animateCrossFadingProperty.boolValue : false);
settingsExpanded[index] = EditorGUILayout.Foldout(settingsExpanded[index], settingsContent);
if (settingsExpanded[index])
{
++EditorGUI.indentLevel;

var combineMeshesProperty = levelProperty.FindPropertyRelative(LevelCombineMeshesFieldName);
EditorGUILayout.PropertyField(combineMeshesProperty);
var screenRelativeHeightProperty = levelProperty.FindPropertyRelative(LevelScreenRelativeHeightFieldName);
EditorGUILayout.PropertyField(screenRelativeHeightProperty);

if (combineMeshesProperty.boolValue)
{
var combineSubMeshesProperty = levelProperty.FindPropertyRelative(LevelCombineSubMeshesFieldName);
EditorGUILayout.PropertyField(combineSubMeshesProperty);
}
var qualityProperty = levelProperty.FindPropertyRelative(LevelQualityFieldName);
EditorGUILayout.PropertyField(qualityProperty);

var childProperties = levelProperty.GetChildProperties();
foreach (var childProperty in childProperties)
bool animateCrossFading = (hasCrossFade ? animateCrossFadingProperty.boolValue : false);
settingsExpanded[index] = EditorGUILayout.Foldout(settingsExpanded[index], settingsContent);
if (settingsExpanded[index])
{
if (string.Equals(childProperty.name, LevelScreenRelativeHeightFieldName) || string.Equals(childProperty.name, LevelQualityFieldName) ||
string.Equals(childProperty.name, LevelCombineMeshesFieldName) || string.Equals(childProperty.name, LevelCombineSubMeshesFieldName) ||
string.Equals(childProperty.name, LevelRenderersFieldName))
++EditorGUI.indentLevel;

var combineMeshesProperty = levelProperty.FindPropertyRelative(LevelCombineMeshesFieldName);
EditorGUILayout.PropertyField(combineMeshesProperty);

if (combineMeshesProperty.boolValue)
{
continue;
var combineSubMeshesProperty = levelProperty.FindPropertyRelative(LevelCombineSubMeshesFieldName);
EditorGUILayout.PropertyField(combineSubMeshesProperty);
}
else if ((!hasCrossFade || !animateCrossFading) && string.Equals(childProperty.name, LevelFadeTransitionWidthFieldName))

var childProperties = levelProperty.GetChildProperties();
foreach (var childProperty in childProperties)
{
continue;
if (string.Equals(childProperty.name, LevelScreenRelativeHeightFieldName) || string.Equals(childProperty.name, LevelQualityFieldName) ||
string.Equals(childProperty.name, LevelCombineMeshesFieldName) || string.Equals(childProperty.name, LevelCombineSubMeshesFieldName) ||
string.Equals(childProperty.name, LevelRenderersFieldName))
{
continue;
}
else if ((!hasCrossFade || !animateCrossFading) && string.Equals(childProperty.name, LevelFadeTransitionWidthFieldName))
{
continue;
}

EditorGUILayout.PropertyField(childProperty, true);
}

EditorGUILayout.PropertyField(childProperty, true);
--EditorGUI.indentLevel;
}

--EditorGUI.indentLevel;
}

// Remove any null renderers
var renderersProperty = levelProperty.FindPropertyRelative(LevelRenderersFieldName);
for (int rendererIndex = renderersProperty.arraySize - 1; rendererIndex >= 0; rendererIndex--)
{
var rendererProperty = renderersProperty.GetArrayElementAtIndex(rendererIndex);
var renderer = rendererProperty.objectReferenceValue as Renderer;
if (renderer == null)
// Remove any null renderers
for (int rendererIndex = renderersProperty.arraySize - 1; rendererIndex >= 0; rendererIndex--)
{
renderersProperty.DeleteArrayElementAtIndex(rendererIndex);
var rendererProperty = renderersProperty.GetArrayElementAtIndex(rendererIndex);
var renderer = rendererProperty.objectReferenceValue as Renderer;
if (renderer == null)
{
renderersProperty.DeleteArrayElementAtIndex(rendererIndex);
}
}
}
EditorGUI.EndDisabledGroup();
Expand Down

0 comments on commit e721567

Please sign in to comment.