Game.Prefabs.ComponentMenu
Assembly: Assembly-CSharp (game assembly; actual DLL name may be Assembly-CSharp.dll)
Namespace: Game.Prefabs
Type: sealed class (Attribute)
Base: System.Attribute
Summary:
Attribute used to annotate component classes with an editor/menu label and/or to declare required prefab types. Applied to classes only (AttributeTargets.Class) and not allowed to be used multiple times on the same class (AllowMultiple = false). The attribute stores a menu string (optional) and an array of required prefab Types.
Fields
-
public readonly string menu
Stores the menu path/label provided when the attribute is constructed with the string overload. May be null if the constructor without a menu string is used. -
public readonly Type[] requiredPrefab
Array of Types representing required prefab classes. Populated by the params Type[] argument passed to either constructor. May be an empty array if no required prefabs were specified.
Properties
- None
Constructors
-
public ComponentMenu(params Type[] requiredPrefab)
Initializes a ComponentMenu attribute with only required prefab types. Sets the requiredPrefab field to the provided array. The menu field remains null when using this constructor. -
public ComponentMenu(string menu, params Type[] requiredPrefab)
Initializes a ComponentMenu attribute with a menu string and required prefab types. Sets the menu field to the provided string and requiredPrefab to the provided array.
Methods
- None (no methods beyond constructors)
Usage Example
// Simple: specify required prefab types only
[ComponentMenu(typeof(RoadPrefab), typeof(LightPrefab))]
public class MyCustomComponent : MonoBehaviour
{
// ...
}
// With a menu path/label and required prefabs
[ComponentMenu("MyMods/Traffic/My Custom Component", typeof(RoadPrefab))]
public sealed class MyCustomComponentWithMenu : MonoBehaviour
{
// ...
}
// With only a menu (no required prefabs)
[ComponentMenu("MyMods/Decor/Sign")]
public class SignComponent : MonoBehaviour
{
// ...
}
Additional notes: - The attribute is sealed and cannot be inherited. - Because the fields are readonly, their values are set at construction time and cannot be changed at runtime. - Use the string overload when you want the editor/menu to display a specific path or label; omit it if you only need to declare required prefab Types.