-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
This is pretty awesome, ty, I have a suggestion:
You implemented GetComponent, and GetComponentProperty.
But I have a suggestion that does not have runtime cost, and that makes sure that the component exists. For example:
public partial class MyComponent : MonoBehaviour{
[RequiredComponent] private TMP_Text text;
}would generate:
[RequireComponent(typeof(TMP_Text))]
public partial class MyComponent : MonoBehaviour{
[SerializeField] private TMP_Text text;
public void OnValidate() {
if (text == null)
TryGetComponent<TMP_Text>(out text);
}
}By adding the [RequiredComponent] at the top of the class, it would make sure the component is added to the gameobject.
By adding the assignment in the OnValidate, this enforces the field is assigned in the editor with zero cost at runtime.
Ideally it would generate the OnValidate method, but if the user defines one, it would generate a ValidateFields() method that the user defined OnValidate has to call.
Metadata
Metadata
Assignees
Labels
No labels