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 #20 from uurha/dev
Browse files Browse the repository at this point in the history
Resolve #19
  • Loading branch information
uurha committed Oct 16, 2022
1 parent d894a36 commit e113259
Show file tree
Hide file tree
Showing 130 changed files with 625 additions and 277 deletions.
2 changes: 1 addition & 1 deletion Editor.meta

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

2 changes: 1 addition & 1 deletion Editor/BetterAttributes.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "BetterAttributes.Editor",
"rootNamespace": "",
"references": [
"GUID:618e123b521db74429ef44b837b020b0"
"GUID:35101f455c979e94c9a0a4793484b7fd"
],
"includePlatforms": [
"Editor"
Expand Down
2 changes: 1 addition & 1 deletion Editor/BetterAttributes.Editor.asmdef.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/BetterAttributesEditor.cs.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Base.meta

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

62 changes: 62 additions & 0 deletions Editor/EditorAddons/Drawers/Base/Comparers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using UnityEditor;

namespace BetterAttributes.EditorAddons.Drawers.Base
{
public abstract class BaseComparer<T, U> where T : IEqualityComparer<U>, new()
{
public static T Instance { get; } = new T();
}

public class TypeComparer : BaseComparer<TypeComparer, Type>, IEqualityComparer<Type>
{
public bool Equals(Type x, Type y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.IsAssignableFrom(y) || x == y) return true;
return (y.IsInterface || y.IsAbstract) && x == typeof(Type);
}

public int GetHashCode(Type obj)
{
return 0;
}
}

public class AssignableFromComparer : BaseComparer<AssignableFromComparer, Type>, IEqualityComparer<Type>
{
public bool Equals(Type x, Type y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
var isAssignableFrom = x.IsAssignableFrom(y);
return isAssignableFrom || x == y;
}

public int GetHashCode(Type obj)
{
return 0;
}
}

public class SerializedPropertyComparer : BaseComparer<SerializedPropertyComparer, SerializedProperty>, IEqualityComparer<SerializedProperty>
{
public bool Equals(SerializedProperty x, SerializedProperty y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.propertyPath == y.propertyPath;
}

public int GetHashCode(SerializedProperty obj)
{
return (obj.propertyPath != null ? obj.propertyPath.GetHashCode() : 0);
}
}
}
3 changes: 3 additions & 0 deletions Editor/EditorAddons/Drawers/Base/Comparers.cs.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Base/FieldDrawer.cs.meta

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

12 changes: 9 additions & 3 deletions Editor/EditorAddons/Drawers/Base/MultiFieldDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BetterAttributes.EditorAddons.Drawers.Utilities;
using System;
using BetterAttributes.EditorAddons.Drawers.Utilities;
using UnityEditor;
using UnityEngine;

Expand All @@ -16,9 +17,14 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
base.OnGUI(position, property, label);
}

private protected virtual Type GetFieldType()
{
return fieldInfo.FieldType;
}

private protected bool ValidateCachedProperties<THandler>(SerializedProperty property, BaseUtility<THandler> handler) where THandler : new()
{
var fieldType = fieldInfo.FieldType;
var fieldType = GetFieldType();
var contains = _wrappers.ContainsKey(property);
if (contains)
{
Expand All @@ -27,7 +33,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
else
{
var gizmoWrapper = handler.GetUtilityWrapper<T>(fieldType, attribute.GetType());
_wrappers.Add(property, (gizmoWrapper, fieldType));
_wrappers.Add(property, new WrapperCollectionValue<T>(gizmoWrapper, fieldType));
}

return contains;
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Base/MultiFieldDrawer.cs.meta

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

29 changes: 12 additions & 17 deletions Editor/EditorAddons/Drawers/Base/WrapperCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@

namespace BetterAttributes.EditorAddons.Drawers.Base
{
public class WrapperCollection<T> : Dictionary<SerializedProperty, (T, Type)> where T : UtilityWrapper
public class WrapperCollectionValue<T> where T : UtilityWrapper
{
private class SerializedPropertyComparer : IEqualityComparer<SerializedProperty>
public WrapperCollectionValue(T wrapper, Type type)
{
public bool Equals(SerializedProperty x, SerializedProperty y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.propertyPath == y.propertyPath;
}

public int GetHashCode(SerializedProperty obj)
{
return (obj.propertyPath != null ? obj.propertyPath.GetHashCode() : 0);
}
Wrapper = wrapper;
Type = type;
}

public WrapperCollection() : base(new SerializedPropertyComparer())
public T Wrapper { get; }
public Type Type { get; }
}

public class WrapperCollection<T> : Dictionary<SerializedProperty, WrapperCollectionValue<T>> where T : UtilityWrapper
{
public WrapperCollection() : base(SerializedPropertyComparer.Instance)
{
}

public void Deconstruct()
{
foreach (var gizmo in Values)
{
gizmo.Item1.Deconstruct();
gizmo.Wrapper.Deconstruct();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Base/WrapperCollection.cs.meta

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

10 changes: 9 additions & 1 deletion Editor/EditorAddons/Drawers/Base/WrappersTypeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ namespace BetterAttributes.EditorAddons.Drawers.Base
{
public class WrappersTypeCollection : Dictionary<Type, Dictionary<Type, Type>>
{

public WrappersTypeCollection() : base()
{

}

public WrappersTypeCollection(IEqualityComparer<Type> equalityComparer) : base(equalityComparer)
{

}
}
}

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Decorators.meta

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

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

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

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

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Gizmo.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Gizmo/BaseWrappers.meta

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

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

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

6 changes: 3 additions & 3 deletions Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace BetterAttributes.EditorAddons.Drawers.Gizmo
[CustomPropertyDrawer(typeof(GizmoLocalAttribute))]
public class GizmoDrawer : MultiFieldDrawer<GizmoWrapper>
{
private WrapperCollections.GizmoWrappers Collection
private GizmoWrappers Collection
{
get
{
_wrappers ??= GenerateCollection();
return _wrappers as WrapperCollections.GizmoWrappers;
return _wrappers as GizmoWrappers;
}
}

Expand Down Expand Up @@ -59,7 +59,7 @@ private protected override void PostDraw(Rect position, SerializedProperty prope

private protected override WrapperCollection<GizmoWrapper> GenerateCollection()
{
return new WrapperCollections.GizmoWrappers();
return new GizmoWrappers();
}

private protected override bool PreDraw(ref Rect position, SerializedProperty property, GUIContent label)
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs.meta

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

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Gizmo/LocalWrappers.meta

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

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

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

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

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Gizmo/WorldWrappers.meta

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

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

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

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

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Preview.meta

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

2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Preview/BaseWrappers.meta

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

Loading

0 comments on commit e113259

Please sign in to comment.