Description
The TestCondition
method in the HideIfAttribute
class is used to determine whether a specific condition is met for hiding a property in the editor. This method checks if a given property within the same class has a specified value, which is useful for conditional visibility in the editor's inspector.
Usage
To use the TestCondition
method, you need to pass the target object and a type description as parameters. The method will return a boolean value indicating whether the condition for hiding the property is satisfied.
Parameters:
targetObject
(System.Object
): The object instance containing the property to be tested.
td
(Sandbox.TypeDescription
): The type description of the property to be tested.
Returns:
System.Boolean
: true
if the condition for hiding the property is met; otherwise, false
.
Example
// Example usage of TestCondition method
public class MyComponent : Component
{
[HideIf("IsHidden", true)]
public int MyProperty { get; set; }
public bool IsHidden { get; set; }
public void CheckVisibility()
{
HideIfAttribute hideIf = new HideIfAttribute("IsHidden", true);
bool shouldHide = hideIf.TestCondition(this, new TypeDescription(typeof(MyComponent)));
// shouldHide will be true if IsHidden is true
}
}