Skip to content

Commit

Permalink
Merge pull request #25 from DerpyNewbie/feature/newbie-inject-propert…
Browse files Browse the repository at this point in the history
…y-drawer

Add property drawer for NewbieInjected fields
  • Loading branch information
DerpyNewbie authored Nov 28, 2024
2 parents 7976665 + c126aaa commit 617e648
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEditor;
using UnityEngine;

namespace DerpyNewbie.Common.Editor
{
[CustomPropertyDrawer(typeof(NewbieInject))]
public class NewbieInjectPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var newbieInject = (NewbieInject)attribute;

using (new EditorGUI.DisabledScope(true))
{
label.text = $"{label.text} (NewbieInjected-{newbieInject.Scope})";
EditorGUI.PropertyField(position, property, label);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Packages/dev.derpynewbie.common/Runtime/NewbieInject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using UnityEngine;

namespace DerpyNewbie.Common
{
Expand All @@ -9,7 +9,7 @@ namespace DerpyNewbie.Common
/// Field attributed with this class will be searched at VRCSDK BuildRequestedCallback time,
/// then injected with first-found component of field type.
/// </remarks>
public sealed class NewbieInject : Attribute
public sealed class NewbieInject : PropertyAttribute
{
public readonly SearchScope Scope;

Expand All @@ -30,14 +30,17 @@ public enum SearchScope
/// Searches from whole Scene
/// </summary>
Scene,

/// <summary>
/// Searches from attached GameObject
/// </summary>
Self,

/// <summary>
/// Searches from children of attached GameObject
/// </summary>
Children,

/// <summary>
/// Searches from parents of attached GameObject
/// </summary>
Expand Down

0 comments on commit 617e648

Please sign in to comment.