Open n3roxis opened 5 years ago
C# has no 'variadic templates' like C++ does. This request would result in reflection-heavy code, like:
var obj = MakeGameObject(typeof(RectTransform), typeof(LineRenderer), typeof(Button));
compared to the old style, this looks rather messy:
var obj = new GameObject();
obj.AddComponent<RectTransform>();
obj.AddComponent<LineRenderer>();
obj.AddComponent<Button>();
Sure, it's more bloated, but also more readable.
I think we don't need this. Better solutions include:
[RequireComponent(typeof(RectTransform))]
for each component type, which forces the dev to give the combination a name and allows custom decoupled initialization logicA discussion with @Eregerog and @n3roxis revealed following idea:
Generate code for a number of generic (A, B, C, ...) AddComponents<A, B, C ...>()
methods, which work exactly like Unitys AddComponent
.
Marked for C#7 only because of the use of tuples that make this convenient at all.
Something like: var obj = CreateGameObject(RectTransform, LineRenderer, Button);