DarkRewar / BaseTool

A big library of basic tools that you might need in your Unity projects.
MIT License
41 stars 6 forks source link

Message Attribute #91 #92

Closed DarkRewar closed 4 months ago

DarkRewar commented 4 months ago

MessageAttribute

You can add a [Message] attribute before a field to display a message in the inspector. You need to pass the message as the first parameter, and you can precise which type of message you want (None, Info, Warning or Error).

[MessageAttribute(string message, MessageAttribute.MessageType type = MessageAttribute.MessageType.Info)]

There also is three shortcut to write those messages: InfoMessage, WarningMessage and ErrorMessage.

using BaseTool;
using UnityEngine;

public class MyClass : MonoBehaviour
{
    [Message("This is a normal message")]
    public float _hello;

    [WarningMessage("This is a warning message")]
    public float _helloWarning;

    [Message("This is an error message", MessageAttribute.MessageType.Error)]
    public float _helloError;
}

message_attribute