Simplify processors code

This commit is contained in:
VladV 2022-08-03 11:18:28 +03:00
parent 30160b3e79
commit c783e6dee7
44 changed files with 148 additions and 162 deletions

View File

@ -3,22 +3,13 @@ using TriInspector.Processors;
using TriInspector.Resolvers; using TriInspector.Resolvers;
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))] [assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))]
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableIfProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
public abstract class DisableIfProcessorBase<T> : TriPropertyDisableProcessor<T> public class DisableIfProcessor : TriPropertyDisableProcessor<DisableIfAttribute>
where T : ConditionalDisableBaseAttribute
{ {
private readonly bool _inverse;
private ValueResolver<object> _conditionResolver; private ValueResolver<object> _conditionResolver;
protected DisableIfProcessorBase(bool inverse)
{
_inverse = inverse;
}
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition) public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{ {
base.Initialize(propertyDefinition); base.Initialize(propertyDefinition);
@ -36,21 +27,7 @@ namespace TriInspector.Processors
{ {
var val = _conditionResolver.GetValue(property); var val = _conditionResolver.GetValue(property);
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null; var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
return equal != _inverse; return equal != Attribute.Inverse;
}
}
public sealed class DisableIfProcessor : DisableIfProcessorBase<DisableIfAttribute>
{
public DisableIfProcessor() : base(false)
{
}
}
public sealed class EnableIfProcessor : DisableIfProcessorBase<EnableIfAttribute>
{
public EnableIfProcessor() : base(true)
{
} }
} }
} }

View File

@ -3,7 +3,6 @@ using TriInspector;
using UnityEngine; using UnityEngine;
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInEditModeProcessor))] [assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInEditModeProcessor))]
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableInEditModeProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
@ -11,15 +10,7 @@ namespace TriInspector.Processors
{ {
public override bool IsDisabled(TriProperty property) public override bool IsDisabled(TriProperty property)
{ {
return !Application.isPlaying; return Application.isPlaying == Attribute.Inverse;
}
}
public class EnableInEditModeProcessor : TriPropertyDisableProcessor<EnableInEditModeAttribute>
{
public override bool IsDisabled(TriProperty property)
{
return Application.isPlaying;
} }
} }
} }

View File

@ -3,7 +3,6 @@ using TriInspector;
using UnityEngine; using UnityEngine;
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInPlayModeProcessor))] [assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInPlayModeProcessor))]
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableInPlayModeProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
@ -11,15 +10,7 @@ namespace TriInspector.Processors
{ {
public override bool IsDisabled(TriProperty property) public override bool IsDisabled(TriProperty property)
{ {
return Application.isPlaying; return Application.isPlaying != Attribute.Inverse;
}
}
public class EnableInPlayModeProcessor : TriPropertyDisableProcessor<EnableInPlayModeAttribute>
{
public override bool IsDisabled(TriProperty property)
{
return !Application.isPlaying;
} }
} }
} }

View File

@ -3,7 +3,6 @@ using TriInspector;
using UnityEngine; using UnityEngine;
[assembly: RegisterTriPropertyHideProcessor(typeof(HideInEditModeProcessor))] [assembly: RegisterTriPropertyHideProcessor(typeof(HideInEditModeProcessor))]
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowInEditModeProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
@ -11,15 +10,7 @@ namespace TriInspector.Processors
{ {
public override bool IsHidden(TriProperty property) public override bool IsHidden(TriProperty property)
{ {
return !Application.isPlaying; return Application.isPlaying == Attribute.Inverse;
}
}
public class ShowInEditModeProcessor : TriPropertyHideProcessor<ShowInEditModeAttribute>
{
public override bool IsHidden(TriProperty property)
{
return Application.isPlaying;
} }
} }
} }

View File

@ -3,22 +3,13 @@ using TriInspector.Processors;
using TriInspector.Resolvers; using TriInspector.Resolvers;
[assembly: RegisterTriPropertyHideProcessor(typeof(HideIfProcessor))] [assembly: RegisterTriPropertyHideProcessor(typeof(HideIfProcessor))]
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowIfProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
public abstract class HideIfProcessorBase<T> : TriPropertyHideProcessor<T> public class HideIfProcessor : TriPropertyHideProcessor<HideIfAttribute>
where T : ConditionalHideBaseAttribute
{ {
private readonly bool _inverse;
private ValueResolver<object> _conditionResolver; private ValueResolver<object> _conditionResolver;
protected HideIfProcessorBase(bool inverse)
{
_inverse = inverse;
}
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition) public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{ {
base.Initialize(propertyDefinition); base.Initialize(propertyDefinition);
@ -37,21 +28,7 @@ namespace TriInspector.Processors
{ {
var val = _conditionResolver.GetValue(property); var val = _conditionResolver.GetValue(property);
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null; var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
return equal != _inverse; return equal != Attribute.Inverse;
}
}
public sealed class HideIfProcessor : HideIfProcessorBase<HideIfAttribute>
{
public HideIfProcessor() : base(false)
{
}
}
public sealed class ShowIfProcessor : HideIfProcessorBase<ShowIfAttribute>
{
public ShowIfProcessor() : base(true)
{
} }
} }
} }

View File

@ -3,7 +3,6 @@ using TriInspector;
using UnityEngine; using UnityEngine;
[assembly: RegisterTriPropertyHideProcessor(typeof(HideInPlayModeProcessor))] [assembly: RegisterTriPropertyHideProcessor(typeof(HideInPlayModeProcessor))]
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowInPlayModeProcessor))]
namespace TriInspector.Processors namespace TriInspector.Processors
{ {
@ -11,15 +10,7 @@ namespace TriInspector.Processors
{ {
public override bool IsHidden(TriProperty property) public override bool IsHidden(TriProperty property)
{ {
return Application.isPlaying; return Application.isPlaying != Attribute.Inverse;
}
}
public class ShowInPlayModeProcessor : TriPropertyHideProcessor<ShowInPlayModeAttribute>
{
public override bool IsHidden(TriProperty property)
{
return !Application.isPlaying;
} }
} }
} }

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_DisableInEditMode : ScriptableObject
{
[DisableInEditMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d4329a716d424b0babfe5e9c046950f6
timeCreated: 1659515326

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_DisableInPlayMode : ScriptableObject
{
[DisableInPlayMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f04bc8a7e7574f5dafc3e02fc5917e5e
timeCreated: 1659515316

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_EnableInEditMode : ScriptableObject
{
[EnableInEditMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eceba01bbe72411eaeb6ba5a6dd6bdbd
timeCreated: 1659515330

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_EnableInPlayMode : ScriptableObject
{
[EnableInPlayMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9b640777fb3e4eb8819741d07b11aa39
timeCreated: 1659515322

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_HideInEditMode : ScriptableObject
{
[HideInEditMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d2c0afeededf47bcaaebbc3e2d39aed3
timeCreated: 1659515490

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_HideInPlayMode : ScriptableObject
{
[HideInPlayMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea1cf8b4405a4d309866c2b8cc2225cd
timeCreated: 1659515499

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_ShowInEditMode : ScriptableObject
{
[ShowInEditMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab794f598d3940be927f3ecea8464097
timeCreated: 1659515495

View File

@ -0,0 +1,8 @@
using TriInspector;
using UnityEngine;
public class Conditionals_ShowInPlayMode : ScriptableObject
{
[ShowInPlayMode]
public float val;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4021d03b1ac443de8a283a15a2cc16ac
timeCreated: 1659515502

View File

@ -12,7 +12,7 @@ namespace TriInspector
} }
public abstract class TriPropertyDisableProcessor<TAttribute> : TriPropertyDisableProcessor public abstract class TriPropertyDisableProcessor<TAttribute> : TriPropertyDisableProcessor
where TAttribute : DisableBaseAttribute where TAttribute : Attribute
{ {
[PublicAPI] [PublicAPI]
public TAttribute Attribute => (TAttribute) RawAttribute; public TAttribute Attribute => (TAttribute) RawAttribute;

View File

@ -12,7 +12,7 @@ namespace TriInspector
} }
public abstract class TriPropertyHideProcessor<TAttribute> : TriPropertyHideProcessor public abstract class TriPropertyHideProcessor<TAttribute> : TriPropertyHideProcessor
where TAttribute : HideBaseAttribute where TAttribute : Attribute
{ {
[PublicAPI] [PublicAPI]
public TAttribute Attribute => (TAttribute) RawAttribute; public TAttribute Attribute => (TAttribute) RawAttribute;

View File

@ -1,14 +0,0 @@
namespace TriInspector
{
public abstract class ConditionalDisableBaseAttribute : DisableBaseAttribute
{
protected ConditionalDisableBaseAttribute(string condition, object value)
{
Condition = condition;
Value = value;
}
public string Condition { get; }
public object Value { get; }
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 8eafca5093484faf8a443c5350b32394
timeCreated: 1652289509

View File

@ -1,14 +0,0 @@
namespace TriInspector
{
public abstract class ConditionalHideBaseAttribute : HideBaseAttribute
{
protected ConditionalHideBaseAttribute(string condition, object value)
{
Condition = condition;
Value = value;
}
public string Condition { get; }
public object Value { get; }
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f5ab937126ed4c07937264bce29616c0
timeCreated: 1652289448

View File

@ -1,8 +0,0 @@
using System;
namespace TriInspector
{
public abstract class DisableBaseAttribute : Attribute
{
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 62ef6624296046438d41bb5ef66cc422
timeCreated: 1641386025

View File

@ -5,14 +5,21 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class DisableIfAttribute : ConditionalDisableBaseAttribute public class DisableIfAttribute : Attribute
{ {
public DisableIfAttribute(string condition) : this(condition, true) public DisableIfAttribute(string condition) : this(condition, true)
{ {
} }
public DisableIfAttribute(string condition, object value) : base(condition, value) public DisableIfAttribute(string condition, object value)
{ {
Condition = condition;
Value = value;
} }
public string Condition { get; }
public object Value { get; }
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,8 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class DisableInEditModeAttribute : DisableBaseAttribute public class DisableInEditModeAttribute : Attribute
{ {
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,8 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class DisableInPlayModeAttribute : DisableBaseAttribute public class DisableInPlayModeAttribute : Attribute
{ {
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,7 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class EnableIfAttribute : ConditionalDisableBaseAttribute public class EnableIfAttribute : DisableIfAttribute
{ {
public EnableIfAttribute(string condition) : this(condition, true) public EnableIfAttribute(string condition) : this(condition, true)
{ {
@ -13,6 +13,7 @@ namespace TriInspector
public EnableIfAttribute(string condition, object value) : base(condition, value) public EnableIfAttribute(string condition, object value) : base(condition, value)
{ {
Inverse = true;
} }
} }
} }

View File

@ -5,7 +5,11 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class EnableInEditModeAttribute : DisableBaseAttribute public class EnableInEditModeAttribute : DisableInEditModeAttribute
{ {
public EnableInEditModeAttribute()
{
Inverse = true;
}
} }
} }

View File

@ -5,7 +5,11 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class EnableInPlayModeAttribute : DisableBaseAttribute public class EnableInPlayModeAttribute : DisableInPlayModeAttribute
{ {
public EnableInPlayModeAttribute()
{
Inverse = true;
}
} }
} }

View File

@ -1,8 +0,0 @@
using System;
namespace TriInspector
{
public abstract class HideBaseAttribute : Attribute
{
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ff02ae4b7c9a4f2598212bef121bb141
timeCreated: 1641386002

View File

@ -5,14 +5,21 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class HideIfAttribute : ConditionalHideBaseAttribute public class HideIfAttribute : Attribute
{ {
public HideIfAttribute(string condition) : this(condition, true) public HideIfAttribute(string condition) : this(condition, true)
{ {
} }
public HideIfAttribute(string condition, object value) : base(condition, value) public HideIfAttribute(string condition, object value)
{ {
Condition = condition;
Value = value;
} }
public string Condition { get; }
public object Value { get; }
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,8 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class HideInEditModeAttribute : HideBaseAttribute public class HideInEditModeAttribute : Attribute
{ {
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,8 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class HideInPlayModeAttribute : HideBaseAttribute public class HideInPlayModeAttribute : Attribute
{ {
public bool Inverse { get; protected set; }
} }
} }

View File

@ -5,7 +5,7 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class ShowIfAttribute : ConditionalHideBaseAttribute public class ShowIfAttribute : HideIfAttribute
{ {
public ShowIfAttribute(string condition) : this(condition, true) public ShowIfAttribute(string condition) : this(condition, true)
{ {
@ -13,6 +13,7 @@ namespace TriInspector
public ShowIfAttribute(string condition, object value) : base(condition, value) public ShowIfAttribute(string condition, object value) : base(condition, value)
{ {
Inverse = true;
} }
} }
} }

View File

@ -5,7 +5,11 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class ShowInEditModeAttribute : HideBaseAttribute public class ShowInEditModeAttribute : HideInEditModeAttribute
{ {
public ShowInEditModeAttribute()
{
Inverse = true;
}
} }
} }

View File

@ -5,7 +5,11 @@ namespace TriInspector
{ {
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
public class ShowInPlayModeAttribute : HideBaseAttribute public class ShowInPlayModeAttribute : HideInPlayModeAttribute
{ {
public ShowInPlayModeAttribute()
{
Inverse = true;
}
} }
} }