my goal is to extend the MonoBehaviour object from Unity3D engine with my functionality. This is what I do:
public static class Extensions {
public static T GetComponentInChildren<T>(this UnityEngine.MonoBehaviour o, bool includeInactive) {
T[] components = o.GetComponentsInChildren<T>(includeInactive);
return components.Length > 0 ? components[0] : default(T);
}
}
But when I am going to use it, I can only access it when I use this
in front of the call: this.GetComponentInChildren(true)
But this
should be implicit, right?
So I assume I am doing something wrong...
Here is where I use the extension:
public class SomeController : MonoBehaviour {
private SomeComponent component;
void Awake() {
component = this.GetComponentInChildren<SomeComponent>(true);
}
}
I hope I made my problem clear. Is there a way to extend the MonoBehaviour correctly (w/o the need to use the this
keyword explicitly) or why is it behaving that way?