Description
The OnComponentEnabled
property is an event handler that is triggered when a component is enabled. This property is of type System.Action
, allowing you to assign a method that will be called whenever the component's enabled state changes to true.
Usage
To use the OnComponentEnabled
property, assign a method to it that you want to be executed when the component is enabled. This is useful for initializing or resetting component-specific data or states when the component becomes active.
Example
// Example of using OnComponentEnabled
public class MyComponent : Component
{
public MyComponent()
{
// Assign a method to be called when the component is enabled
OnComponentEnabled = HandleComponentEnabled;
}
private void HandleComponentEnabled()
{
// Code to execute when the component is enabled
// For example, initialize or reset data
InitializeData();
}
private void InitializeData()
{
// Initialization logic here
}
}