public class Test : MonoBehaviour
{
[SearchContext("test:")] // works
public MonoBehaviour test1;
[MySearchContext] //doesn't work
public MonoBehaviour test2;
}
public class MySearchContextAttribute : SearchContextAttribute
{
public MySearchContextAttribute() : base("test:")
{
}
}
When reusing both the query
and the search provider
together, it may be necessary to define a custom attribute
that inherits from SearchContextAttribute
.
Ok this is a good one. I will log this bug officially (UUM-91984).
Thanks for reporting.
1 Like
Hi @santutu2,
WE have taken the decision to make the class SearchContextAttribute sealed. It was never meant to be derived from in the first place. I will close the bug.
Thanks for understanding,
Sebastien
Hello @sebastienp_unity, thank you for your support and response.
I have a question.
The reason I wanted to use inheritance was to implement the code below.
The following is an attribute that searches for MonoBehaviours implementing a specific interface.
using System;
using System.Reflection;
using UnityEngine.Search;
using UnityEngine;
public class Test : MonoBehaviour
{
[SearchInterface(typeof(ITest))]
public MonoBehaviour aa;
}
[AttributeUsage(AttributeTargets.Field)]
public class SearchInterfaceAttribute : SearchContextAttribute
{
public SearchInterfaceAttribute(Type interfaceType) : base(
$"ic:{new AssemblyName(interfaceType.Assembly.FullName).Name},{interfaceType.FullName}",
typeof(InterfaceComponentSearchProvider)
)
{ }
}
If it is not possible to inherit from SearchContextAttribute
, is there another way to achieve this kind of implementation?
Hi @santutu2,
after reviewing your feature request, we have decided to keep the [SearchContextAttribute]
sealed. Our rationale are as follow:
- Deriving from an attribute might have unforeseen consequences at the call site where we gather all attributes
- PropertyDrawer used to draw the SearchContextAttribute might also have issues
Sorry mate But keep up giving us feedback,
Sebastien