mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Allows ShowInInspector usage on fields
This commit is contained in:
parent
b969569ae7
commit
9f63461715
@ -5,6 +5,9 @@ public class Misc_ShowInInspectorSample : ScriptableObject
|
||||
{
|
||||
private float _field;
|
||||
|
||||
[ShowInInspector]
|
||||
private bool _myToggle;
|
||||
|
||||
[ShowInInspector]
|
||||
public float ReadOnlyProperty => _field;
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TriInspector;
|
||||
using TriInspector.TypeProcessors;
|
||||
using TriInspector.Utilities;
|
||||
|
||||
[assembly: RegisterTriTypeProcessor(typeof(TriRegisterShownByTriFieldsTypeProcessor), 1)]
|
||||
|
||||
namespace TriInspector.TypeProcessors
|
||||
{
|
||||
public class TriRegisterShownByTriFieldsTypeProcessor : TriTypeProcessor
|
||||
{
|
||||
public override void ProcessType(Type type, List<TriPropertyDefinition> properties)
|
||||
{
|
||||
const int fieldsOffset = 5001;
|
||||
|
||||
properties.AddRange(TriReflectionUtilities
|
||||
.GetAllInstanceFieldsInDeclarationOrder(type)
|
||||
.Where(IsSerialized)
|
||||
.Select((it, ind) => TriPropertyDefinition.CreateForFieldInfo(ind + fieldsOffset, it)));
|
||||
}
|
||||
|
||||
private static bool IsSerialized(FieldInfo fieldInfo)
|
||||
{
|
||||
return fieldInfo.GetCustomAttribute<ShowInInspector>() != null &&
|
||||
TriUnitySerializationUtilities.IsSerializableByUnity(fieldInfo) == false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5a485127f534bee963f620f86287c34
|
||||
timeCreated: 1670601276
|
@ -52,6 +52,9 @@ Shows non-serialized property in the inspector.
|
||||
```csharp
|
||||
private float _field;
|
||||
|
||||
[ShowInInspector]
|
||||
private bool _myToggle;
|
||||
|
||||
[ShowInInspector]
|
||||
public float ReadOnlyProperty => _field;
|
||||
|
||||
|
@ -3,7 +3,7 @@ using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class ShowInInspector : Attribute
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user