Attributes List

Started by Seven · 9 months ago · 4 replies · 325 views

edited 9 months ago#1
Seven
Member
JoinedMay 2023 Posts36 Score1,310
Just posting this here for my own sake since i don't like digging through the full api list for the common ones

edit: This was just quickly thrown together in a notepad originally, iv pasted slightly better one that removes ones that arn't as common or working as well as adding some code examples for more complex ones

edit2: went back through and cleaned up this list ordering in a way that makes more sense and removing ones iv since tested and could not determine a change, left some ones i didnt test for the the sake of ~completeness~

Classes
  • [ClassName("")] - Use this for the visible class name
  • [Alias("")] - Provides alternate class names.
  • [Icon("", "#FF0000")] - Sets an icon for display. Colors in HTML format.
  • [Library("")] - Marks a class for library registration.
 

Property Customizers
  • [Property] - Marks something as a property visible to inspector
  • [Header("")] - Adds a header above the property in the inspector.
  • [Space] - Adds vertical space above the property.
  • [Title("")] - Manually set the pretty name 
  • [Description("")] - Description in the tooltip
  • [Placeholder("")] - Placeholder text in string properties
  • [Group("")] - Similar to Category, groups properties together. 
  • [ToggleGroup("")] - Creates a group that can be toggled on/off using a named property.
  • [Category("")] - Groups properties into categories in the inspector.
  • [Feature("")] - Sets the category or group (similar to Category).
  • [FeatureEnabled] - Marks a boolean property as a feature toggle. 
  • [Order(1)] - Controls the visual order of members in UI.   
  • [WideMode] - Expands the value editor to fill the next line, placing the title above it.
  • [ReadOnly] - Displays in the inspector but prevents editing. 
  • [TextArea] - Shows a multi-line text box for string properties.
  • [Range(0, 100)] - Creates a slider for ranged float values.
  • [Step(5)] - Restricts values to multiples of the step value.
 

Property Helpers
  • [RequireComponent] - Ensures a component exists on the GameObject (creates it if missing).
  • [HideIf("PropertyName", value)] - Hides property if another property has a given value.
  • [ShowIf("PropertyName", value)] - Shows property if another property has a given value.
  • [Change] or [Change("MethodName")] - Invokes a method when the property changes. Calls On[PropertyName]Changed if no name provided. The callback should have 2 arguments - oldValue and newValue.
  • Validate( "SimpleMethod", "ValidateMessage", LogLevel.Warn ) - Similar to change but method returns bool, if bool is false displays an infobox
  • [InputAction] - Uses an input action selector for string properties. 
  • [FontName] - Uses a font name selector for string properties. 
  • [IconName] - Uses a Material Icon selector for string properties. 
  • [InfoBox("")] - Draws an information box above the property. 
  • [Normal] -  For Vector properties provides normal selection tools . 

 
Methods
[Button("BtnText")] - Shows a button in the inspector that calls the method.



Not Personally Tested - Educated Guesses
[ClientEditable] - Indicates a property can be edited by the client (e.g., in Sandbox Mode).
[Event("event.name")] - Generic event listener.
[Input] - Makes a method available as a Map Logic Input in Hammer Editor (entities only).

Hotload Attributes
[SkipHotload] - Skips processing during hotload for specific fields or types.
[SuppressNullKeyWarning] - Suppresses warnings for null keys during hotload in dictionaries/hashsets.
[SupportsILHotload] - Marks a type as supporting IL hotload.
[MethodBodyChange] - Indicates method body changes support.
[PropertyAccessorBodyChange] - Indicates property accessor body changes support.

Console Commands & Variable
[ConCmd("command_name")] - Registers a console command.
[ConVar("var_name")] - Registers a console variable.

File Path Attributes
[AssetPath] - String selector for assets of a specific extension.
[ImageAssetPath] - String selector for image assets.
[FilePath("txt")] - File picker for the given extension (or all by default).
[TextureImagePath] - Allows selection of anything that can be a Texture.
[MapAssetPath] - String selector for map assets.

Networking Attributes
[Rpc] - Marks a method as an RPC callable over the network.
[Rpc.Broadcast] - RPC called for everyone.
[Rpc.Host] - RPC only called on the host.
[Rpc.Owner] - RPC only called on the owner of the object. 
[Sync] - Auto-synchronizes a property from owner to other clients.
#2
fishy
Member
JoinedFeb 2023 Posts82 Score1,548
What's the logic behind the categorization of these attributes? I feel like a lot of Sandbox-Specific Editor Attributes are just Display & UI Attributes in many cases.

Thanks for the compiled list, super useful to look back on this when I need it!

[DefaultValue(100)] the console will yell at you for using [DefaultValue()]:

#3
Seven
Member
JoinedMay 2023 Posts36 Score1,310
this is actually getting noticed by others so I will be remaking this a lot better so stand by for that
#4
Seven
Member
JoinedMay 2023 Posts36 Score1,310
Remake with actual working code examples. Some self explanatory ones will just be mentioned.


For Use On Properties

Placeholder(string)
[Property, Placeholder( "Placeholder" )]
public string MyProperty { get; set; }

Title(string)
[Property, Title("Title")]
public string MyProperty { get; set; }
Description(string)
[Property, Description( "Description  Attribute Text" )]
public string MyProperty { get; set; }
Category(string) & Group(string)
Grouped together because they functionally do the same thing
[Property, Group( "Group" )]
public string MyProperty { get; set; }
[Property, Category( "Category" )]
public string MySecondProperty { get; set; }
ToggleGroup(string GroupName)
Creates a group just like Category & Group with additional toggle value. Note: this does not actually handle any logic in code, Values within a disabled ToggleGroup are still valid values unless you handle them based on the ToggleGroup's Value

Techincally this can be any type but clearly expects a bool
[Property, ToggleGroup( "Toggle" )] // Property Value that dicates if other properties are used
public bool Toggle { get; set; }

[Property, Group( "Toggle" )] // group this into our ToggleGroup attribute
public string MyProperty { get; set; } = "Default String";

Order(int)
Without this properties appear in the editor in the order they are listed in code, with this you can manually place them.  Order Attributes with the same order number will still order around other numbers correct but display in code written order within the same group.

[Property, Order( 4 )] //Order 4 Coded First
public string MyProperty { get; set; } = "Default String";

[Property, Order( 4 )] // Order 4 Coded Second
public string MySecondProperty { get; set; }

[Property, Order( 2 )] // Order 2 Coded Third
public string MyThirdProperty { get; set; }

[Property, Order( 1 )] // Order 1 Coded Fourth
public string MyFourthProperty { get; set; }
Note that `MyProperty` and `MySecondProperty` are both `Order(4)` so they appear last but display in code order with that order

Range(float min, float max)
converts normal number input into a slider with min and max values. Limits are only respected by the inspector. Manual setting can bypass limits.
[Property, Range(1,2)]
public float MyPropertyFloatVersion { get; set; } = 50; //Apears outside of slider

Step(float)
Limits inspector to only set values of this variable in increments of this number
[Property, Step( 100 )]
public float MyPropertyFloatVersion { get; set; } = 0;

WideMode
Put input field on a newline the full width of inspector

ReadOnly
Make value un-editable in inspector

Text Area
MultiLine Text Input

InputAction
For use on string property. Will display a dropdown containing the names of all input actions for easy selection

FontName
Dropdown of all font names

Feature(string)
Provides tab based grouping

FeatureEnabled(string NameOfTab)
Similar to ToggleGroups, This tab can be added or removed based on the value of the bool
[Property, FeatureEnabled( "FeatureAttribute" )] //Controls if Feature is Enabled
public bool MyProperty { get; set; }

[Property, Feature( "FeatureAttribute" )] // Puts property within feature group
public float MyPropertyFloatVersion { get; set; } = 50;

[Property, Feature( "NormalFeature" )]
public string MySecondProperty { get; set; }

Header(string)

Space(float distance)
Takes an float then adds that much space inbetween the property and the one above it

InfoBox(string Txt, string Icon, EditorTint ColorToDisplay)
Adds an infobox to the inspector
[Property, InfoBox( "InfoBox", "Favorite", EditorTint.Pink )]
public float MyPropertyFloatVersion { get; set; } = 50;

Normal
For use on vectors to provide quick dropdown for setting a normal value

Change
Change(string TargetMethod)

While the type does not matter, will automatically call the class method following `On[PropertyName]Changed` when the value is changed. If provided with a string name argument it will instead call that method on the class when property is changed.
[Property, Change]
public bool MyProperty { get; set; }

protected void OnMyPropertyChanged( int oldvalue, int NewValue )
{
	Log.Info( "Change Detected" );
	Log.Info( $"Old Value: {oldvalue}" );
	Log.Info( $"New Value: {NewValue}" );
}

RequireComponent(string)

Hide

ConVar(string)
must be static field

HideIf(string PropName, object Value)
if string property target matchs objects value hide this property
[Property]
public bool Toggle { get; set; }

[Property, HideIf( "Toggle", true )]
public int MyProperty { get; set; }
ShowIf(string PropName, object Value)
Same as HideIf just inverted

Validate(string MethodToCall, string ValidationErrorMsg, LogLevel Severity)
When this property is changed it will call the method named in the first argument, this method needs to return a bool, and will pass in the new properties value to the method. If the validation returns true nothing displays, if false, an Infobox styled with the specific LogLevel will appear above the property.
[Property]
public bool Toggle { get; set; }

[Property, Validate( "SimpleMethod", "ValidateMessage", LogLevel.Warn )]
public int MyProperty { get; set; }

bool SimpleMethod( int Var )
{
	if ( Toggle ) { return true; } else { return false; }
}

For Use On Classes

Icon(string Icon, string ForegroundColor, string BackgroundColor)
Adds an Icon beside component name in the inspector
[Icon( "Favorite", "rgb(255,255,255)", "rgb(255,255,255)" )]
public sealed class AttributesTest : Component {}

SelectionBase
GameObjects with this attribute will be selected when one of their child GameObjects are selected, Clicking again on the child will then select the child. This does not affect Hierarchy, only selcting with scene view

Library(string)
I would guess this does more but this acts as alternative name when search for components that does change the display name of it

For Use On Methods

Button(string Txt, string Icon)
[Button( "This is the Button Text", "Favorite" )]
void ButtonCall( int Var )
{
	Log.Info( $"{Var}" );
}
ConCmd(string)


#5
gasleet
Member
JoinedAug 2024 Posts78 Score6,923
Awesome! <3 
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.