Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
uurha committed Jul 22, 2023
1 parent 7be31ca commit c8bb568
Show file tree
Hide file tree
Showing 80 changed files with 698 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/ValidationDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Better.EditorTools.Helpers.Caching;
using Better.Tools.Runtime.Attributes;
using Better.Validation.EditorAddons.Utilities;
using Better.Validation.EditorAddons.ValidationWrappers;
using Better.Validation.EditorAddons.Wrappers;
using Better.Validation.Runtime.Attributes;
using UnityEditor;
using UnityEngine;
Expand Down
3 changes: 3 additions & 0 deletions Editor/EditorAddons/Iteration.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using UnityEditor;
using UnityEngine;

namespace Better.Validation.EditorAddons.Utilities
namespace Better.Validation.EditorAddons.Iteration
{
public class IterationData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Better.Validation.EditorAddons.ContextResolver;
using Better.Validation.EditorAddons.ValidationWrappers;
using Better.Validation.EditorAddons.Utilities;
using Better.Validation.EditorAddons.Wrappers;
using UnityEditor;
using UnityEngine;

namespace Better.Validation.EditorAddons.Utilities
namespace Better.Validation.EditorAddons.Iteration
{
public static class Iterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Helpers.Caching;
using Better.Extensions.Runtime;
using Better.Validation.EditorAddons.ValidationWrappers;
using Better.Validation.EditorAddons.Utilities;
using Better.Validation.EditorAddons.Wrappers;
using Better.Validation.Runtime.Attributes;

namespace Better.Validation.EditorAddons.Utilities
namespace Better.Validation.EditorAddons.Iteration
{
public static class IteratorFilter
{
Expand Down
3 changes: 3 additions & 0 deletions Editor/EditorAddons/PreBuildValidation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/EditorAddons/PreBuildValidation/Interfaces.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Better.Validation.EditorAddons.PreBuildValidation.Interfaces
{
public interface IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/EditorAddons/PreBuildValidation/Models.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Better.Validation.EditorAddons.PreBuildValidation.Interfaces;

namespace Better.Validation.EditorAddons.PreBuildValidation.Models
{
[Serializable]
public class ProjectValidationStep : IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData()
{
var commands = new ValidatorCommands();
return commands.ValidateAttributesInProject();
}
}

[Serializable]
public class AllSceneValidationStep : IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData()
{
var commands = new ValidatorCommands();
return commands.ValidateAttributesInAllScenes();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace Better.Validation.EditorAddons.Utilities
namespace Better.Validation.EditorAddons.PreBuildValidation
{
public class ValidationBuildProcess : IPreprocessBuildWithReport
{
private readonly BetterValidationSettings _settings;
private readonly ValidationSettings _settings;
public int callbackOrder { get; }

public ValidationBuildProcess()
{
_settings = Resources.Load<BetterValidationSettings>(nameof(BetterValidationSettings));
_settings = Resources.Load<ValidationSettings>(nameof(ValidationSettings));
}

public void OnPreprocessBuild(BuildReport report)
{
if(_settings.DisableBuildValidation) return;
var commands = new ValidatorCommands();
var commandDatas = new List<ValidationCommandData>();
commandDatas.AddRange(commands.ValidateAttributesInProject());
commandDatas.AddRange(commands.ValidateAttributesInAllScenes());

var validationSteps = _settings.GetSteps();
foreach (var buildValidationStep in validationSteps)
{
commandDatas.AddRange(buildValidationStep.GatherValidationData());
}

commandDatas = commandDatas.Where(x => x.Type >= _settings.BuildLoggingLevel).ToList();
if (!commandDatas.Any()) return;
Expand All @@ -50,7 +53,7 @@ public void OnPreprocessBuild(BuildReport report)
str.AppendLine("Do you want to ignore those issues?");
str.Append(Environment.NewLine);
str.Append(Environment.NewLine);
str.AppendFormat("(You can disable validation in Edit > Project Settings > {0} > {1})", ProjectSettingsRegisterer.BetterPrefix, ValidationSettingsTool.SettingMenuItem);
str.AppendFormat("(You can disable validation in Edit > Project Settings > {0} > {1})", ProjectSettingsRegisterer.BetterPrefix, ProjectSettingsToolsContainer<ValidationSettingsTool>.Instance.NamespacePrefix);
EditorApplication.Beep();
if (!EditorUtility.DisplayDialog("Validation failed", str.ToString(), "Ignore", "Resolve"))
{
Expand Down
16 changes: 0 additions & 16 deletions Editor/EditorAddons/Settings/BetterValidationSettings.cs

This file was deleted.

136 changes: 136 additions & 0 deletions Editor/EditorAddons/Settings/BuildValidationStepsDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using Better.EditorTools;
using Better.EditorTools.Helpers;
using Better.EditorTools.Helpers.DropDown;
using Better.Extensions.Runtime;
using Better.Validation.EditorAddons.PreBuildValidation.Interfaces;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

namespace Better.Validation.EditorAddons.Settings
{
internal class BuildValidationStepsDrawer
{
private readonly Type[] _types;
private readonly ReorderableList _reorderableList;
private readonly SerializedProperty _stepsProperty;
private readonly GUIContent _popupHeader = new GUIContent("Build Steps");
private readonly GUIContent _validationStepsLabel = new GUIContent("Validation Steps");
private readonly GUIContent _rootContent = new GUIContent("Root");
private const string NullName = "null";

public BuildValidationStepsDrawer(SerializedObject settingsObject, SerializedProperty stepsProperty)
{
_types = typeof(IBuildValidationStep).GetAllInheritedType();
_stepsProperty = stepsProperty;

_reorderableList = new ReorderableList(settingsObject, _stepsProperty, true, true, true, true)
{
drawElementCallback = DrawElementCallback,
drawHeaderCallback = HeaderCallback,
elementHeightCallback = ElementHeightCallback
};
}

private float ElementHeightCallback(int index)
{
var property = _stepsProperty.GetArrayElementAtIndex(index);
return EditorGUI.GetPropertyHeight(property, true);
}

private void HeaderCallback(Rect rect)
{
EditorGUI.LabelField(rect, _validationStepsLabel);
}

private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
{

var property = _stepsProperty.GetArrayElementAtIndex(index);

var type = property.GetManagedType();
DrawButton(rect, property, type);
var label = new GUIContent(L10n.Tr($"Element {index.ToString()}"));
EditorGUI.PropertyField(rect, property, label, true);
}

private void DrawButton(Rect rect, SerializedProperty serializedProperty, Type currentValue)
{
var typeName = currentValue == null ? NullName : currentValue.Name;
var content = DrawersHelper.GetIconGUIContent(IconType.GrayDropdown);
content.text = typeName;
var buttonPosition = GetPopupPosition(rect);
if (GUI.Button(buttonPosition, content, Styles.Button))
{
ShowDropDown(buttonPosition, serializedProperty, currentValue);
}
}

private void ShowDropDown(Rect popupPosition, SerializedProperty serializedProperty, Type currentValue)
{
var copy = popupPosition;
copy.y += EditorGUIUtility.singleLineHeight;

var popup = DropdownWindow.ShowWindow(GUIUtility.GUIToScreenRect(copy), _popupHeader);
var items = GenerateItemsTree(serializedProperty, currentValue);

popup.SetItems(items);
}

private DropdownCollection GenerateItemsTree(SerializedProperty serializedProperty, Type currentValue)
{
var collection = new DropdownCollection(new DropdownSubTree(_rootContent));
foreach (var type in _types)
{
var typeName = type == null ? NullName : type.Name;
var guiContent = new GUIContent(typeName);
if (guiContent.image == null && type == currentValue)
{
guiContent.image = DrawersHelper.GetIcon(IconType.Checkmark);
}

var item = new DropdownItem(guiContent, OnSelectItem, new Tuple<SerializedProperty, Type>(serializedProperty, type));
collection.AddChild(item);
}

return collection;
}

private static void OnSelectItem(object obj)
{
if (obj is Tuple<SerializedProperty, Type>(var serializedProperty, var type))
{
if (!serializedProperty.Verify()) return;
serializedProperty.managedReferenceValue = type == null ? null : Activator.CreateInstance(type);

var serializedObject = serializedProperty.serializedObject;
EditorUtility.SetDirty(serializedObject.targetObject);
serializedObject.ApplyModifiedProperties();
}
}

private static Rect GetPopupPosition(Rect currentPosition)
{
var popupPosition = new Rect(currentPosition);
popupPosition.width -= EditorGUIUtility.labelWidth;
popupPosition.x += EditorGUIUtility.labelWidth;
popupPosition.height = EditorGUIUtility.singleLineHeight;
return popupPosition;
}

public void DoLayoutList()
{
using (var scope = new EditorGUI.ChangeCheckScope())
{
_reorderableList.DoLayoutList();
if (scope.changed)
{
var serializedObject = _stepsProperty.serializedObject;
EditorUtility.SetDirty(serializedObject.targetObject);
serializedObject.ApplyModifiedProperties();
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Editor/EditorAddons/Settings/ValidationSettingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Better.Validation.EditorAddons.Settings
{
internal class ValidationSettingProvider : ProjectSettingsProvider<BetterValidationSettings>
internal class ValidationSettingProvider : ProjectSettingsProvider<ValidationSettings>
{
private readonly Editor _editor;

public ValidationSettingProvider() : base(ProjectSettingsToolsContainer<ValidationSettingsTool>.Instance, SettingsScope.Project)
{
keywords = new HashSet<string>(new[] { "Better", "Validation", "Warnings", "Ignore" });
_editor = Editor.CreateEditor(_settings);
}

[MenuItem(ValidationSettingsTool.MenuItemPrefix + "/" + ProjectSettingsRegisterer.HighlightPrefix, false, 999)]
Expand All @@ -19,8 +22,7 @@ private static void Highlight()

protected override void DrawGUI()
{
EditorGUILayout.PropertyField(_settingsObject.FindProperty("disableBuildValidation"));
EditorGUILayout.PropertyField(_settingsObject.FindProperty("buildLoggingLevel"));
_editor.OnInspectorGUI();
}
}
}
27 changes: 27 additions & 0 deletions Editor/EditorAddons/Settings/ValidationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using Better.Tools.Runtime.Settings;
using Better.Validation.EditorAddons.PreBuildValidation.Interfaces;
using Better.Validation.EditorAddons.PreBuildValidation.Models;
using Better.Validation.Runtime.Attributes;
using UnityEngine;

namespace Better.Validation.EditorAddons.Settings
{
public class ValidationSettings : ProjectSettings
{
[SerializeField] private bool disableBuildValidation;
[SerializeField] private ValidationType buildLoggingLevel = ValidationType.Warning;

[SerializeReference] private IBuildValidationStep[] validationSteps = new IBuildValidationStep[]
{ new ProjectValidationStep(), new AllSceneValidationStep() };

public ValidationType BuildLoggingLevel => buildLoggingLevel;

public bool DisableBuildValidation => disableBuildValidation;

public List<IBuildValidationStep> GetSteps()
{
return new List<IBuildValidationStep>(validationSteps);
}
}
}
Loading

0 comments on commit c8bb568

Please sign in to comment.