mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Add SceneObjectsOnly attriute
This commit is contained in:
parent
a56ae84197
commit
b21f687394
36
Editor.Extras/Validators/SceneObjectsOnlyValidator.cs
Normal file
36
Editor.Extras/Validators/SceneObjectsOnlyValidator.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using TriInspector;
|
||||
using TriInspector.Validators;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: RegisterTriAttributeValidator(typeof(SceneObjectsOnlyValidator))]
|
||||
|
||||
namespace TriInspector.Validators
|
||||
{
|
||||
public class SceneObjectsOnlyValidator : TriAttributeValidator<SceneObjectsOnlyAttribute>
|
||||
{
|
||||
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
||||
{
|
||||
if (!typeof(Object).IsAssignableFrom(propertyDefinition.FieldType))
|
||||
{
|
||||
return "AssetsOnly attribute can be used only on Object fields";
|
||||
}
|
||||
|
||||
return TriExtensionInitializationResult.Ok;
|
||||
}
|
||||
|
||||
public override TriValidationResult Validate(TriProperty property)
|
||||
{
|
||||
var obj = property.TryGetSerializedProperty(out var serializedProperty)
|
||||
? serializedProperty.objectReferenceValue
|
||||
: (Object) property.Value;
|
||||
|
||||
if (obj == null || !AssetDatabase.Contains(obj))
|
||||
{
|
||||
return TriValidationResult.Valid;
|
||||
}
|
||||
|
||||
return TriValidationResult.Error($"{obj} cannot be an asset.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98948bb92a504f87abeda6e500dc22b2
|
||||
timeCreated: 1657621306
|
@ -0,0 +1,8 @@
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class Validators_SceneObjectsOnlySample : ScriptableObject
|
||||
{
|
||||
[SceneObjectsOnly]
|
||||
public GameObject obj;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bd709dcdda44927b14c8a77ffebf843
|
||||
timeCreated: 1657621668
|
@ -171,6 +171,15 @@ private bool VisibleInEditMode => !Application.isPlaying;
|
||||
public GameObject obj;
|
||||
```
|
||||
|
||||
#### SceneObjectsOnly
|
||||
|
||||
![SceneObjectsOnly](https://user-images.githubusercontent.com/26966368/178470605-618c9796-054f-40bb-9c09-2d9c6f342faf.png)
|
||||
|
||||
```csharp
|
||||
[SceneObjectsOnly]
|
||||
public GameObject obj;
|
||||
```
|
||||
|
||||
### Decorators
|
||||
|
||||
#### Dropdown
|
||||
|
11
Runtime/Attributes/SceneObjectsOnlyAttribute.cs
Normal file
11
Runtime/Attributes/SceneObjectsOnlyAttribute.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage((AttributeTargets.Field | AttributeTargets.Property))]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public sealed class SceneObjectsOnlyAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
3
Runtime/Attributes/SceneObjectsOnlyAttribute.cs.meta
Normal file
3
Runtime/Attributes/SceneObjectsOnlyAttribute.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 908b02bc0b5d4cdd88e952625ce0cbc7
|
||||
timeCreated: 1657621281
|
Loading…
Reference in New Issue
Block a user