Skip to content

Useful attributes for Unity. To make the inspector more beautiful and convenient.

Notifications You must be signed in to change notification settings

OlegVishnivetsky/awesome-attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWESOME ATTRIBUTES

Last Updated: 06/12/2024

Publisher: cherrydev

💡 About: Unity asset designed to speed up and improve your development process. Adds a large number of attributes with which you can make your inspector more beautiful and convenient.

📥 Installation

1️⃣ Unity asset store (not yet available)

  1. Directly from Unity asset store. Link soon

2️⃣ Using GitHub link

  1. Go to ‘Package Manager’ - + - ‘Add package from git URL’ and paste https://github.com/OlegVishnivetsky/awesome-attributes.git?path=/Assets/AwesomeAttributes

3️⃣ Add from disk

  1. Download .zip from git hub page and extract forder.
  2. Go to ‘Package Manager’ - + - ‘Add package from disk’ and select package.json file.

📝 Documentation

1. Title

Draws a title and subtitle (optional). You can change the text alignment to Left/Center/Right. You can choose whether this text will be bold, have a separation line or not.

    [Title("Health", "Player health")]
    [SerializeField] private float maxHealth;
    [SerializeField] private float currentHealth;

    --------------------------------------------------

    public TitleAttribute(string title, string subTitle = null, bool bold = true, bool withSeparationLine = true);
    public TitleAttribute(string title, TitleTextAlignments textAlignments, string subTitle = null,  bool bold = true, bool withSeparationLine = true)

2. GUI Color

Everything is simple here. The attribute changes gui color. You can use it by specifying color hex or rgba in the parameters.

    [GUIColor("#ff00ff")]
    [SerializeField] private float maxHealth;
    [GUIColor(255, 0, 0, 0.2f)]
    [SerializeField] private float currentHealth;

    --------------------------------------------------

    public GUIColorAttribute(int r, int g, int b, float a);
    public GUIColorAttribute(string colorHex)

3. Separation Line

Draws a separation line with height, top spacing and bottom spacing.

    [SeparationLine(10)]

    [SerializeField] private float maxHealth;
    [SerializeField] private float currentHealth;

    [SeparationLine(1, 10, 10)]

    [SerializeField] private float speed;
    [SerializeField] public float maxSpeed = 4;

    --------------------------------------------------

    public SeparationLineAttribute(float height, float topSpacing = 1, float bottomSpacing = 1);

4. Label

Changes the field name in the inspector, useful for long names.

    [Label("Short Name")]
    [SerializeField] private float veryveryveryveryveryLong;

    --------------------------------------------------

    public LabelAttribute(string lable)

5. ShowIf

Shows the field in the inspector if the condition is true, otherwise hides it. May contain several conditions and enum. You can also specify a method that returns a bool.

    [SerializeField] private bool showIfThisTrue;
    [ShowIf("showIfThisTrue")]
    [SerializeField] private int showMePlease;

    [SerializeField] private ShowIfTestEnum showIfEnumTest;
    [ShowIf(ShowIfTestEnum.Show, "showIfEnumTest")]
    [SerializeField] private int showEnumTest;

    --------------------------------------------------

    public ShowIfAttribute(string condition)
    public ShowIfAttribute(string conditionsOperator, params string[] conditions)
    public ShowIfAttribute(object enumValue, string enumFieldName)

6. Readonly

Attribute class for readonly fields, they are visible in the inspector but cannot be edited.

    [SerializeField] private float maxHealth;
    [Readonly]
    [SerializeField] private float currentHealth;

7. ReadonlyIf

Another conditional attribute. Makes the field readonly if the condition is true. May contain several conditions and enum.

    [SerializeField] private bool turnOnReadonly;
    [ReadonlyIf("turnOnReadonly")]
    [SerializeField] private float currentHealth;

    --------------------------------------------------

    public ReadonlyIfAttribute(string condition)
    public ReadonlyIfAttribute(string conditionsOperator, params string[] conditions)
    public ReadonlyIfAttribute(object enumValue, string enumFieldName)

8. MinMaxSlider

Attribute that creates special slider the user can use to specify a range between a min and a max. Can be used on Vector2 and float fields.

    [MinMaxSlider(0, 20)]
    [SerializeField] private Vector2 minMaxValue;

    --------------------------------------------------

    public MinMaxSliderAttribute(float minValue, float maxValue)

9. WithoutLabel

Hides the field label

    [WithoutLabel]
    [SerializeField] private Vector2 iDontNeedLabel;

10. Button

Shows a button under the field to which you placed the attribute. The name of the method is specified as a parameter; you can also specify the label and height.

    [Button("DebugCurrentHealth", "Check Health")]
    [SerializeField] private float currentHealth;

    --------------------------------------------------

    public ButtonAttribute(string methodName, string lable = null, float height = 18)

11. Required

Attribute that creates a warning box if the field is null.

    [Button("DebugCurrentHealth", "Check Health")]
    [SerializeField] private float currentHealth;

    --------------------------------------------------

    public ButtonAttribute(string methodName, string lable = null, float height = 18)

12. OnlyChildGameObjects

Restricts a property to reference only child objects of the same type. Adds a button "Pick" that opens a window with all child objects of the same type as the field and allows you to assign only child objects.

    [OnlyChildGameObjects]
    [SerializeField] private Rigidbody2D onlyChildObjects;

13. TagSelector

Allows you to select a tag from a dropdown in the Inspector.

    [TagSelector]
    [SerializeField] private string playerTag;

14. Scene

Allows you to select a scene from the drop-down list in the Inspector for string or integer fields. The drop-down list shows the scenes that are in Build Settings/Scenes In Build

    [Scene]
    [SerializeField] private string sceneField;

⭐⭐⭐⭐⭐ If you want to add your attribute. Then please follow the folder structure as in the asset and make a pull request. Feel free to edit any code to suit your needs. If you find any bugs or have any questions, you can write about it to me by email, github or in reviews in the Unity Asset Store. I will also be pleased if you visit my itchio page. 😄

Gmail: [email protected]

Github: https://github.com/OlegVishnivetsky

Itch.io: https://oleg-vishnivetsky.itch.io/

This file will be updated over time. If you write suggestions again.

About

Useful attributes for Unity. To make the inspector more beautiful and convenient.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages