mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Simplify processors code
This commit is contained in:
parent
30160b3e79
commit
c783e6dee7
@ -3,22 +3,13 @@ using TriInspector.Processors;
|
||||
using TriInspector.Resolvers;
|
||||
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))]
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableIfProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
public abstract class DisableIfProcessorBase<T> : TriPropertyDisableProcessor<T>
|
||||
where T : ConditionalDisableBaseAttribute
|
||||
public class DisableIfProcessor : TriPropertyDisableProcessor<DisableIfAttribute>
|
||||
{
|
||||
private readonly bool _inverse;
|
||||
|
||||
private ValueResolver<object> _conditionResolver;
|
||||
|
||||
protected DisableIfProcessorBase(bool inverse)
|
||||
{
|
||||
_inverse = inverse;
|
||||
}
|
||||
|
||||
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
||||
{
|
||||
base.Initialize(propertyDefinition);
|
||||
@ -36,21 +27,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
var val = _conditionResolver.GetValue(property);
|
||||
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
|
||||
return equal != _inverse;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DisableIfProcessor : DisableIfProcessorBase<DisableIfAttribute>
|
||||
{
|
||||
public DisableIfProcessor() : base(false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EnableIfProcessor : DisableIfProcessorBase<EnableIfAttribute>
|
||||
{
|
||||
public EnableIfProcessor() : base(true)
|
||||
{
|
||||
return equal != Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInEditModeProcessor))]
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableInEditModeProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
@ -11,15 +10,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
public override bool IsDisabled(TriProperty property)
|
||||
{
|
||||
return !Application.isPlaying;
|
||||
}
|
||||
}
|
||||
|
||||
public class EnableInEditModeProcessor : TriPropertyDisableProcessor<EnableInEditModeAttribute>
|
||||
{
|
||||
public override bool IsDisabled(TriProperty property)
|
||||
{
|
||||
return Application.isPlaying;
|
||||
return Application.isPlaying == Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInPlayModeProcessor))]
|
||||
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableInPlayModeProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
@ -11,15 +10,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
public override bool IsDisabled(TriProperty property)
|
||||
{
|
||||
return Application.isPlaying;
|
||||
}
|
||||
}
|
||||
|
||||
public class EnableInPlayModeProcessor : TriPropertyDisableProcessor<EnableInPlayModeAttribute>
|
||||
{
|
||||
public override bool IsDisabled(TriProperty property)
|
||||
{
|
||||
return !Application.isPlaying;
|
||||
return Application.isPlaying != Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(HideInEditModeProcessor))]
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowInEditModeProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
@ -11,15 +10,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
public override bool IsHidden(TriProperty property)
|
||||
{
|
||||
return !Application.isPlaying;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShowInEditModeProcessor : TriPropertyHideProcessor<ShowInEditModeAttribute>
|
||||
{
|
||||
public override bool IsHidden(TriProperty property)
|
||||
{
|
||||
return Application.isPlaying;
|
||||
return Application.isPlaying == Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,22 +3,13 @@ using TriInspector.Processors;
|
||||
using TriInspector.Resolvers;
|
||||
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(HideIfProcessor))]
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowIfProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
public abstract class HideIfProcessorBase<T> : TriPropertyHideProcessor<T>
|
||||
where T : ConditionalHideBaseAttribute
|
||||
public class HideIfProcessor : TriPropertyHideProcessor<HideIfAttribute>
|
||||
{
|
||||
private readonly bool _inverse;
|
||||
|
||||
private ValueResolver<object> _conditionResolver;
|
||||
|
||||
protected HideIfProcessorBase(bool inverse)
|
||||
{
|
||||
_inverse = inverse;
|
||||
}
|
||||
|
||||
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
||||
{
|
||||
base.Initialize(propertyDefinition);
|
||||
@ -37,21 +28,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
var val = _conditionResolver.GetValue(property);
|
||||
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
|
||||
return equal != _inverse;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HideIfProcessor : HideIfProcessorBase<HideIfAttribute>
|
||||
{
|
||||
public HideIfProcessor() : base(false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ShowIfProcessor : HideIfProcessorBase<ShowIfAttribute>
|
||||
{
|
||||
public ShowIfProcessor() : base(true)
|
||||
{
|
||||
return equal != Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(HideInPlayModeProcessor))]
|
||||
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowInPlayModeProcessor))]
|
||||
|
||||
namespace TriInspector.Processors
|
||||
{
|
||||
@ -11,15 +10,7 @@ namespace TriInspector.Processors
|
||||
{
|
||||
public override bool IsHidden(TriProperty property)
|
||||
{
|
||||
return Application.isPlaying;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShowInPlayModeProcessor : TriPropertyHideProcessor<ShowInPlayModeAttribute>
|
||||
{
|
||||
public override bool IsHidden(TriProperty property)
|
||||
{
|
||||
return !Application.isPlaying;
|
||||
return Application.isPlaying != Attribute.Inverse;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_DisableInEditMode : ScriptableObject
|
||||
{
|
||||
[DisableInEditMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4329a716d424b0babfe5e9c046950f6
|
||||
timeCreated: 1659515326
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_DisableInPlayMode : ScriptableObject
|
||||
{
|
||||
[DisableInPlayMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f04bc8a7e7574f5dafc3e02fc5917e5e
|
||||
timeCreated: 1659515316
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_EnableInEditMode : ScriptableObject
|
||||
{
|
||||
[EnableInEditMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eceba01bbe72411eaeb6ba5a6dd6bdbd
|
||||
timeCreated: 1659515330
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_EnableInPlayMode : ScriptableObject
|
||||
{
|
||||
[EnableInPlayMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b640777fb3e4eb8819741d07b11aa39
|
||||
timeCreated: 1659515322
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_HideInEditMode : ScriptableObject
|
||||
{
|
||||
[HideInEditMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2c0afeededf47bcaaebbc3e2d39aed3
|
||||
timeCreated: 1659515490
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_HideInPlayMode : ScriptableObject
|
||||
{
|
||||
[HideInPlayMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea1cf8b4405a4d309866c2b8cc2225cd
|
||||
timeCreated: 1659515499
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_ShowInEditMode : ScriptableObject
|
||||
{
|
||||
[ShowInEditMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab794f598d3940be927f3ecea8464097
|
||||
timeCreated: 1659515495
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Conditionals_ShowInPlayMode : ScriptableObject
|
||||
{
|
||||
[ShowInPlayMode]
|
||||
public float val;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4021d03b1ac443de8a283a15a2cc16ac
|
||||
timeCreated: 1659515502
|
@ -12,7 +12,7 @@ namespace TriInspector
|
||||
}
|
||||
|
||||
public abstract class TriPropertyDisableProcessor<TAttribute> : TriPropertyDisableProcessor
|
||||
where TAttribute : DisableBaseAttribute
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
[PublicAPI]
|
||||
public TAttribute Attribute => (TAttribute) RawAttribute;
|
||||
|
@ -12,7 +12,7 @@ namespace TriInspector
|
||||
}
|
||||
|
||||
public abstract class TriPropertyHideProcessor<TAttribute> : TriPropertyHideProcessor
|
||||
where TAttribute : HideBaseAttribute
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
[PublicAPI]
|
||||
public TAttribute Attribute => (TAttribute) RawAttribute;
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8eafca5093484faf8a443c5350b32394
|
||||
timeCreated: 1652289509
|
@ -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; }
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5ab937126ed4c07937264bce29616c0
|
||||
timeCreated: 1652289448
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
public abstract class DisableBaseAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ef6624296046438d41bb5ef66cc422
|
||||
timeCreated: 1641386025
|
@ -5,14 +5,21 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class DisableIfAttribute : ConditionalDisableBaseAttribute
|
||||
public class DisableIfAttribute : Attribute
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class DisableInEditModeAttribute : DisableBaseAttribute
|
||||
public class DisableInEditModeAttribute : Attribute
|
||||
{
|
||||
public bool Inverse { get; protected set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class DisableInPlayModeAttribute : DisableBaseAttribute
|
||||
public class DisableInPlayModeAttribute : Attribute
|
||||
{
|
||||
public bool Inverse { get; protected set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class EnableIfAttribute : ConditionalDisableBaseAttribute
|
||||
public class EnableIfAttribute : DisableIfAttribute
|
||||
{
|
||||
public EnableIfAttribute(string condition) : this(condition, true)
|
||||
{
|
||||
@ -13,6 +13,7 @@ namespace TriInspector
|
||||
|
||||
public EnableIfAttribute(string condition, object value) : base(condition, value)
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,11 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class EnableInEditModeAttribute : DisableBaseAttribute
|
||||
public class EnableInEditModeAttribute : DisableInEditModeAttribute
|
||||
{
|
||||
public EnableInEditModeAttribute()
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,11 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class EnableInPlayModeAttribute : DisableBaseAttribute
|
||||
public class EnableInPlayModeAttribute : DisableInPlayModeAttribute
|
||||
{
|
||||
public EnableInPlayModeAttribute()
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
public abstract class HideBaseAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff02ae4b7c9a4f2598212bef121bb141
|
||||
timeCreated: 1641386002
|
@ -5,14 +5,21 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class HideIfAttribute : ConditionalHideBaseAttribute
|
||||
public class HideIfAttribute : Attribute
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class HideInEditModeAttribute : HideBaseAttribute
|
||||
public class HideInEditModeAttribute : Attribute
|
||||
{
|
||||
public bool Inverse { get; protected set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class HideInPlayModeAttribute : HideBaseAttribute
|
||||
public class HideInPlayModeAttribute : Attribute
|
||||
{
|
||||
public bool Inverse { get; protected set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class ShowIfAttribute : ConditionalHideBaseAttribute
|
||||
public class ShowIfAttribute : HideIfAttribute
|
||||
{
|
||||
public ShowIfAttribute(string condition) : this(condition, true)
|
||||
{
|
||||
@ -13,6 +13,7 @@ namespace TriInspector
|
||||
|
||||
public ShowIfAttribute(string condition, object value) : base(condition, value)
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,11 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class ShowInEditModeAttribute : HideBaseAttribute
|
||||
public class ShowInEditModeAttribute : HideInEditModeAttribute
|
||||
{
|
||||
public ShowInEditModeAttribute()
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,11 @@ namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class ShowInPlayModeAttribute : HideBaseAttribute
|
||||
public class ShowInPlayModeAttribute : HideInPlayModeAttribute
|
||||
{
|
||||
public ShowInPlayModeAttribute()
|
||||
{
|
||||
Inverse = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user