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 and type description. This method is typically used to control the visibility of properties in the inspector based on dynamic conditions.
Usage
To use the TestCondition
method, you need to create a subclass of ConditionalVisibilityAttribute
and override this method to implement your custom logic for determining visibility. The method takes two parameters:
targetObject
: The object instance for which the condition is being tested.
td
: A TypeDescription
object that provides metadata about the type of the target 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)
{
// Implement your custom condition logic here
// For example, check if a certain property value is true
var myObject = targetObject as MyObjectType;
if (myObject != null)
{
return myObject.SomeProperty == true;
}
return false;
}
}