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

Commit

Permalink
Fix for 2020
Browse files Browse the repository at this point in the history
  • Loading branch information
uurha committed Oct 7, 2023
1 parent 72b24c4 commit 99764f9
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Better.Validation.EditorAddons.Drawers
[MultiCustomPropertyDrawer(typeof(ValidationAttribute))]
public class ValidationDrawer : MultiFieldDrawer<PropertyValidationWrapper>
{
private Cache<BetterTuple<string, ValidationType>> _validationResult = new Cache<BetterTuple<string, ValidationType>>();
private Cache<MutableTuple<string, ValidationType>> _validationResult = new Cache<MutableTuple<string, ValidationType>>();

public ValidationDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute)
{
Expand All @@ -39,7 +39,7 @@ protected override bool PreDraw(ref Rect position, SerializedProperty property,
if (wrapper.IsSupported())
{
var validation = wrapper.Validate();
_validationResult.Set(validation.IsValid, new BetterTuple<string, ValidationType>(validation.Value, wrapper.Type));
_validationResult.Set(validation.IsValid, new MutableTuple<string, ValidationType>(validation.Value, wrapper.Type));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public static List<ValidationCommandData> ObjectIteration(Object go, OnPropertyI

var so = new SerializedObject(obj);
CacheData.SetContext(so);
so.forceChildVisibility = true;
//so.forceChildVisibility = true;
so.Update();
var sp = so.GetIterator();

var copy = sp.Copy();
if (copy.NextVisible(true))
if (copy.Next(true))
{
var count = copy.CountInProperty();
while (sp.NextVisible(true))
while (sp.Next(true))
{
var remainingCopy = sp.Copy();
EditorUtility.DisplayProgressBar("Validating property...", $"Validating {sp.propertyPath}...",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Better.Validation.EditorAddons
{
public class BetterTuple<T1, T2>
public class MutableTuple<T1, T2>
{
public BetterTuple(T1 item1, T2 item2)
public MutableTuple(T1 item1, T2 item2)
{
Item1 = item1;
Item2 = item2;
}

public BetterTuple()
public MutableTuple()
{
Item1 = default;
Item2 = default;
Expand Down

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 @@ -33,36 +33,13 @@ public static class ToolsGUIUtility
margin = new RectOffset()
};

public static GUIStyle _overridesHoverHighlight = "HoverHighlight";
public static GUIStyle _hoveredItemBackgroundStyle = "WhiteBackground";

public static int Toolbar(int groupID, string[] groupNames, out bool changed)
{
var id = GUILayout.Toolbar(groupID, groupNames);
changed = id != groupID;
return id;
}

public static void DrawHorizontalLine(Color color, int thickness = 2, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
r.height = thickness;
r.y += padding / 2f;
r.x -= 2;
r.width += 6;
EditorGUI.DrawRect(r, color);
}

public static void DrawVerticalLine(Color color, int thickness = 1, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Width(padding + thickness));
r.width = thickness;
r.x += padding / 2f;
r.y -= 2;
r.height += 6f;
EditorGUI.DrawRect(r, color);
}

private static void DrawVerticalLineFull(Color color, int thickness = 1, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Width(padding + thickness));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using Better.EditorTools.Helpers;
using Better.Validation.Runtime.Attributes;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Linq;
using Better.Extensions.Runtime;

#if !UNITY_2021_2_OR_NEWER
using UnityEditor.Experimental.SceneManagement;
#endif


namespace Better.Validation.EditorAddons.Utilities
{
Expand All @@ -30,9 +37,20 @@ public static void OpenReference(UnityEngine.Object reference)
var transform = component.transform;
if (PrefabUtility.IsPartOfPrefabAsset(reference))
{
var stage = PrefabStageUtility.OpenPrefab(AssetDatabase.GetAssetPath(reference));
var assetPath = AssetDatabase.GetAssetPath(reference);
Transform prefabRootTransform = null;
#if !UNITY_2021_2_OR_NEWER
var obj = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
AssetDatabase.OpenAsset(obj);
var stage = PrefabStageUtility.GetCurrentPrefabStage();
prefabRootTransform = stage.prefabContentsRoot.transform;
#else
var stage = PrefabStageUtility.OpenPrefab(assetPath);
prefabRootTransform = stage.prefabContentsRoot.transform;
#endif
var indexes = GetParentIndices(transform);
transform = GetChildBySiblingIndices(stage.prefabContentsRoot.transform, indexes);

transform = GetChildBySiblingIndices(prefabRootTransform, indexes);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ protected virtual void DrawLabel(ValidationCommandData data)
{
var reference = data.Target;

var icon = EditorGUIUtility.GetIconForObject(reference);
var csIcon = EditorGUIUtility.IconContent("cs Script Icon");
csIcon.text = reference.GetType().Name;
#if UNITY_2021_2_OR_NEWER
var icon = EditorGUIUtility.GetIconForObject(reference);
if (icon)
{
csIcon.image = icon;
}

#endif
EditorGUILayout.LabelField(csIcon);
EditorGUILayout.Space(DrawersHelper.SpaceHeight);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Better.Validation.EditorAddons.WindowModule.CollectionDrawing
{
public abstract class GroupDictionaryDrawer<TKey, TDictionary> : CollectionDrawer where TDictionary: class, IDictionary<TKey, BetterTuple<bool, List<ValidationCommandData>>>
public abstract class GroupDictionaryDrawer<TKey, TDictionary> : CollectionDrawer where TDictionary: class, IDictionary<TKey, MutableTuple<bool, List<ValidationCommandData>>>
{
protected TDictionary _dataDictionary = null;
protected int _count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Better.Validation.EditorAddons.WindowModule.CollectionDrawing
{
public class ObjectGroupDrawer : GroupDictionaryDrawer<Object, Dictionary<Object, BetterTuple<bool, List<ValidationCommandData>>>>
public class ObjectGroupDrawer : GroupDictionaryDrawer<Object, Dictionary<Object, MutableTuple<bool, List<ValidationCommandData>>>>
{
public override int Order { get; } = 2;

Expand All @@ -15,12 +15,12 @@ public override string GetOptionName()

public override CollectionDrawer Initialize(List<ValidationCommandData> data)
{
_dataDictionary = new Dictionary<Object, BetterTuple<bool, List<ValidationCommandData>>>(GameObjectGroupingComparer.Instance);
_dataDictionary = new Dictionary<Object, MutableTuple<bool, List<ValidationCommandData>>>(GameObjectGroupingComparer.Instance);
foreach (var commandData in data)
{
if (!_dataDictionary.TryGetValue(commandData.Target, out var list))
{
list = new BetterTuple<bool, List<ValidationCommandData>>(true, new List<ValidationCommandData>());
list = new MutableTuple<bool, List<ValidationCommandData>>(true, new List<ValidationCommandData>());
_dataDictionary.Add(commandData.Target, list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Better.Validation.EditorAddons.WindowModule.CollectionDrawing
{
public class TypeGroupDrawer : GroupDictionaryDrawer<ValidationType, SortedDictionary<ValidationType, BetterTuple<bool, List<ValidationCommandData>>>>
public class TypeGroupDrawer : GroupDictionaryDrawer<ValidationType, SortedDictionary<ValidationType, MutableTuple<bool, List<ValidationCommandData>>>>
{
public override int Order { get; } = 1;

Expand All @@ -16,13 +16,13 @@ public override string GetOptionName()
public override CollectionDrawer Initialize(List<ValidationCommandData> data)
{
_dataDictionary =
new SortedDictionary<ValidationType, BetterTuple<bool, List<ValidationCommandData>>>(Comparer<ValidationType>.Create((x, y) => y.CompareTo(x)));
new SortedDictionary<ValidationType, MutableTuple<bool, List<ValidationCommandData>>>(Comparer<ValidationType>.Create((x, y) => y.CompareTo(x)));
foreach (var commandData in data)
{
var iconType = commandData.Type;
if (!_dataDictionary.TryGetValue(iconType, out var list))
{
list = new BetterTuple<bool, List<ValidationCommandData>>(iconType == ValidationType.Error || commandData == _currentItem,
list = new MutableTuple<bool, List<ValidationCommandData>>(iconType == ValidationType.Error || commandData == _currentItem,
new List<ValidationCommandData>());
_dataDictionary.Add(iconType, list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using UnityEngine;
using UnityEngine.SceneManagement;

#if !UNITY_2021_1_OR_NEWER
using UnityEditor.Experimental.SceneManagement;
#endif

namespace Better.Validation.EditorAddons.WindowModule.Pages
{
public class ResultPage : IWindowPage
Expand Down
2 changes: 1 addition & 1 deletion Assets/BetterValidation/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.uurha.bettervalidation",
"displayName": "Better Validation",
"version": "1.0.53",
"version": "1.0.54",
"unity": "2020.1",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit 99764f9

Please sign in to comment.