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

Commit

Permalink
Merge pull request #72 from techno-dwarf-works/feature/clean-up
Browse files Browse the repository at this point in the history
Clean Up
  • Loading branch information
uurha authored Mar 2, 2024
2 parents 342226f + 6c387fa commit 59f46cd
Show file tree
Hide file tree
Showing 53 changed files with 412 additions and 1,151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"GUID:443314a5a4e67c14a88ae223776b6554",
"GUID:28da8d3b12e3efa47928e0c9070f853d",
"GUID:a59e3daedde9ca94bba45364d4ead25f",
"GUID:01df13aca8d01e24a911bcc3e8277031"
"GUID:01df13aca8d01e24a911bcc3e8277031",
"GUID:1ac867a6259e45a1856740fe8f7623aa"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Better.Extensions.EditorAddons;
using UnityEditor;

namespace Better.EditorTools.Comparers
Expand Down
20 changes: 0 additions & 20 deletions Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Better.EditorTools.CustomEditors
Expand Down Expand Up @@ -56,7 +56,7 @@ bool WherePredicate((Type type, MultiEditorAttribute attribute) x)
return att.EditorFor == targetType;
}

return typeof(EditorExtension).GetAllInheritedType().Select(type => (type, type.GetCustomAttribute<MultiEditorAttribute>()))
return typeof(EditorExtension).GetAllInheritedTypesWithoutUnityObject().Select(type => (type, type.GetCustomAttribute<MultiEditorAttribute>()))
.Where(WherePredicate).OrderBy(x => x.Item2.Order).ToArray();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,10 @@
using System.Reflection;
using Better.EditorTools.Helpers.Caching;
using Better.Tools.Runtime.Attributes;
using UnityEditor;
using UnityEngine;

namespace Better.EditorTools.Drawers.Base
{
public class HeightCache : Cache<float>
{
public bool Forced { get; private set; }

public HeightCache(bool additional, float height)
{
IsValid = additional;
Value = height;
}

public HeightCache()
{

}

public HeightCache Force()
{
Forced = true;
return this;
}

public static HeightCache GetAdditive(float height)
{
var cache = new HeightCache(true, height);
return cache;
}

public static HeightCache GetFull(float height)
{
var cache = new HeightCache(false, height);
return cache;
}

public static HeightCache operator +(HeightCache left, HeightCache right)
{
if (left.Forced)
{
return left;
}

if (right.Forced)
{
return right;
}

if (!left.IsValid && !right.IsValid)
{
return GetFull(Mathf.Max(left.Value, right.Value));
}

if ((!left.IsValid && right.IsValid) || (left.IsValid && !right.IsValid))
{
return GetFull(left.Value + right.Value);
}

if (left.IsValid && right.IsValid)
{
return GetAdditive(left.Value + right.Value);
}

return GetAdditive(0);
}
}

public abstract class FieldDrawer
{
protected readonly FieldInfo _fieldInfo;
Expand Down Expand Up @@ -141,7 +76,7 @@ internal void PostDrawInternal(Rect position, SerializedProperty property, GUICo
PostDraw(position, property, label);
}

internal HeightCache GetPropertyHeightInternal(SerializedProperty property, GUIContent label)
internal HeightCacheValue GetPropertyHeightInternal(SerializedProperty property, GUIContent label)
{
var propertyHeight = GetPropertyHeight(property, label);
if (_nextDrawer != null)
Expand All @@ -152,14 +87,14 @@ internal HeightCache GetPropertyHeightInternal(SerializedProperty property, GUIC

return propertyHeight;
}

protected abstract bool PreDraw(ref Rect position, SerializedProperty property, GUIContent label);
protected abstract Rect PreparePropertyRect(Rect original);
protected abstract void PostDraw(Rect position, SerializedProperty property, GUIContent label);

protected virtual HeightCache GetPropertyHeight(SerializedProperty property, GUIContent label)
protected virtual HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return HeightCache.GetFull(EditorGUI.GetPropertyHeight(property, label, true));
return HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(property, label, true));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using Better.EditorTools.Helpers.Caching;
using Better.Extensions.Runtime;
using UnityEngine;

namespace Better.EditorTools.Drawers.Base
{
public class HeightCacheValue : CacheValue<float>
{
public bool Forced { get; private set; }

public HeightCacheValue(bool additional, float height)
{
IsValid = additional;
Value = height;
}

public HeightCacheValue()
{
}

public HeightCacheValue Force()
{
Forced = true;
return this;
}

public static HeightCacheValue GetAdditive(float height)
{
var cache = new HeightCacheValue(true, height);
return cache;
}

public static HeightCacheValue GetFull(float height)
{
var cache = new HeightCacheValue(false, height);
return cache;
}

public static HeightCacheValue operator +(HeightCacheValue left, HeightCacheValue right)
{
if (left == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(left));
return new HeightCacheValue(false, 0);
}

if (right == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(right));
return new HeightCacheValue(false, 0);
}

if (left.Forced)
{
return left;
}

if (right.Forced)
{
return right;
}

if (!left.IsValid && !right.IsValid)
{
return GetFull(Mathf.Max(left.Value, right.Value));
}

if ((!left.IsValid && right.IsValid) || (left.IsValid && !right.IsValid))
{
return GetFull(left.Value + right.Value);
}

if (left.IsValid && right.IsValid)
{
return GetAdditive(left.Value + right.Value);
}

return GetAdditive(0);
}
}
}

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,10 +11,18 @@ namespace Better.EditorTools.Drawers.Base
{
public abstract class MultiFieldDrawer<T> : FieldDrawer where T : UtilityWrapper
{
private static readonly Cache CacheField = new Cache();
private static readonly CacheValue CacheValueField = new CacheValue();

protected WrapperCollection<T> _wrappers;

protected class CacheValue : CacheValue<WrapperCollectionValue<T>>
{
}

protected MultiFieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute)
{
}

/// <summary>
/// Method generates explicit typed collection inherited from <see cref="WrapperCollection{T}"/>
/// </summary>
Expand All @@ -34,29 +42,25 @@ protected override void Deconstruct()

protected virtual Type GetFieldOrElementType()
{
return _fieldInfo.GetFieldOrElementType();
var fieldType = _fieldInfo.FieldType;
if (fieldType.IsArrayOrList())
return fieldType.GetCollectionElementType();

return fieldType;
}

/// <summary>
/// Validates if <see cref="_wrappers"/> contains property by <see cref="SerializedPropertyComparer"/>
/// </summary>
/// <param name="property">SerializedProperty what will be stored into <see cref="_wrappers"/></param>
/// <param name="handler"><see cref="BaseUtility{THandler}"/> used to validate current stored wrappers and gets instance for recently added property</param>
/// <typeparam name="THandler"></typeparam>
/// <returns>Returns true if wrapper for <paramref name="property"/> was already stored into <see cref="_wrappers"/></returns>
protected Cache ValidateCachedProperties<THandler>(SerializedProperty property, BaseUtility<THandler> handler)
protected CacheValue ValidateCachedProperties<THandler>(SerializedProperty property, BaseUtility<THandler> handler)
where THandler : new()
{
_wrappers.ValidateCachedProperties(CacheField, property, GetFieldOrElementType(), _attribute.GetType(), handler);
return CacheField;
}

protected class Cache : Cache<WrapperCollectionValue<T>>
{
}

protected MultiFieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute)
{
ValidateCachedPropertiesUtility.Validate(_wrappers, CacheValueField, property, GetFieldOrElementType(), _attribute.GetType(), handler);
return CacheValueField;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public WrapperCollection() : base(SerializedPropertyComparer.Instance)
/// </summary>
public void Deconstruct()
{
foreach (var gizmo in Values)
foreach (var value in Values)
{
gizmo.Wrapper.Deconstruct();
value.Wrapper.Deconstruct();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class WrappersTypeCollection : BaseWrappersTypeCollection
{
protected Dictionary<Type, Dictionary<Type, Type>> _dictionary;

public WrappersTypeCollection() : base()
public WrappersTypeCollection()
{
_dictionary = new Dictionary<Type, Dictionary<Type, Type>>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class MultiPropertyDrawer : PropertyDrawer
[DidReloadScripts]
private static void OnInitialize()
{
var types = typeof(FieldDrawer).GetAllInheritedType();
var types = typeof(FieldDrawer).GetAllInheritedTypesWithoutUnityObject();
foreach (var type in types)
{
var atts = type.GetCustomAttributes<MultiCustomPropertyDrawer>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Better.EditorTools.Helpers.Caching
{
public class Cache<T>
public class CacheValue<T>
{
public bool IsValid { get; protected set; }
public T Value { get; protected set; }
Expand All @@ -11,9 +11,9 @@ public void Set(bool isValid, T value)
Value = value;
}

public Cache<T> Copy()
public CacheValue<T> Copy()
{
return new Cache<T>()
return new CacheValue<T>()
{
IsValid = IsValid,
Value = Value
Expand Down
Loading

0 comments on commit 59f46cd

Please sign in to comment.