Description
The TestCondition
method is a virtual method of the ConditionalVisibilityAttribute
class. It is used to determine whether a specific condition is met for a given object, which in turn affects the visibility of a property in the inspector. This method is part of the attribute's functionality to conditionally hide properties based on runtime conditions.
Usage
To use the TestCondition
method, you need to override it in a derived class of ConditionalVisibilityAttribute
. This method takes two parameters:
targetObject
: The object instance on which the condition is being tested.
td
: A TypeDescription
object that provides metadata about the type of the object.
The method returns a bool
indicating whether the condition is met (true
) or not (false
).
Example
public class MyVisibilityAttribute : ConditionalVisibilityAttribute
{
public override bool TestCondition(object targetObject, TypeDescription td)
{
// Example condition: Check if the target object has a specific property set to true
var myProperty = td.GetProperty("MyProperty");
if (myProperty != null)
{
return (bool)myProperty.GetValue(targetObject);
}
return false;
}
}