ruk·si

Unity
Attributes

Updated at 2016-10-30 07:41

A quick overview of all the class/method/field attributes Unity has.

Components

  • HelpURLAttribute set a custom URL for documentation.
  • DisallowMultipleComponent prevents multiple instances of this component in a game object.
  • RequireComponent this component requires another component to be present in the game object.
  • SelectionBaseAttribute defines which object will be picked when selected in the scene view.

Component Fields

  • HideInInspector hide the field from inspector.
  • SerializeField serialize the field, makes non-public fields visible.
  • TooltipAttribute set help text on field mouse-over.
  • SpaceAttribute add spacing between fields.
  • HeaderAttribute add heading text above fields.
  • DelayedAttribute this field is not updated until user presses enter or removes focus.
  • RangeAttribute restrict int/float to be in the specified range.
  • MultilineAttribute change string field to multiline textbox.
  • TextAreaAttribute change string field to flexible text area.
  • ColorUsageAttribute configure color field's color picker settings.

Menus

  • AddComponentMenu add custom script in specified Add Component menu.
  • ContextMenu add this method in context menu of the component.
  • ContextMenuItemAttribute add a method under context menu of this field.
  • CreateAssetMenuAttribute add this scriptable object under Assets/Create.
  • MenuItem add a method to the editor main menu.
  • PreferenceItem add preference section to Preferences window.

Rendering

  • ImageEffectOpaque make image effect to be rendered after opaque geometry.
  • ImageEffectAllowedInSceneView make image effect to be rendered into scene view camera
  • ImageEffectTransformsToLDR switch image effect to LDR rendering.

Runtime

  • RuntimeInitializeOnLoadMethodAttribute automatically call a static function after a runtime scene has been loaded.
  • SharedBetweenAnimatorsAttribute makes that this StateMachineBehaviour is only initialized once and shared between all animators.

Editor

  • InitializeOnLoadAttribute automatically initialize a class after editor launches.
  • InitializeOnLoadMethodAttribute automatically call a static function after editor launches.
  • DidReloadScripts automatically call a static function after scripts have been reloaded.
  • ExecuteInEditMode make a script execute even when not in play mode.
  • DrawGizmoAttribute add gizmo icon for this component type.
  • GUITargetAttribute controls to which display is OnGUI UI rendered.
  • OnOpenAssetAttribute allow overriding what Unity does when you open an asset.

Custom Editors

  • CustomPropertyDrawer specifies which runtime class this drawer is for.
  • CustomEditor specifies which runtime class this custom editor is for.
  • CanEditMultipleObjects allows multi-object editing for this custom editor.
  • CustomPreviewAttribute allow adding custom preview for containing game object.

Building

  • PreserveAttribute prevents a class, method or field from being stripped if build code stripping is enabled.
  • PostProcessSceneAttribute automatically call a static function after each scene build.
  • PostProcessBuildAttribute automatically call a static function after whole build.

Sources