Skip to content

Percentage Property Drawer for Unity | Draw percentages in the editor | How to display the drop chance in unity

License

Notifications You must be signed in to change notification settings

RimuruDev/Unity-PercentDrawer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

⭐Percentage Property Drawer for Unity⭐

Made With Unity License Last Commit Repo Size Downloads Last Release GitHub stars GitHub user stars

This solution includes a custom attribute PercentageAttribute and a property drawer PercentDrawer that work together to provide a convenient way of displaying float values as percentages in the Unity Editor.

image image

Installation

  1. Create a folder named Editor within your project's Assets directory if it does not already exist. Unity requires that all editor scripts be located in a folder named Editor.
  2. Create a folder named Attributes within your Assets directory to store custom attributes.
  3. Place the PercentageAttribute.cs file inside the Attributes folder.
  4. Place the PercentDrawer.cs file inside the Editor folder.

Your folder structure should look like this:

Assets/
│
├── Editor/
│ └── PercentDrawer.cs
│
└── Attributes/
└── PercentageAttribute.cs

Usage

To use the PercentageAttribute, you first need to define it in a script file:

// PercentageAttribute.cs
using UnityEngine;

public class PercentageAttribute : PropertyAttribute {}

Then, apply the [Percentage] attribute to any float field in your MonoBehaviour or ScriptableObject classes:

// SomeScript.cs
using UnityEngine;

public class SomeScript : MonoBehaviour
{
    [Percentage]
    public float dropChance;
}

When you select a GameObject with this script attached in the Unity Editor, you'll see the dropChance field displayed as a slider with a percentage value next to it.

Customizing the Drawer

If you wish to customize the behavior of the PercentDrawer, you can edit the PercentDrawer.cs file within the Editor folder. Comments in the code provide guidance on what each part does and how to adjust the layout.

Support

For support, questions, or contributions, please open an issue on the repository's issue tracker.

Contributing Contributions to improve the PercentageAttribute and PercentDrawer are welcome. Please follow the standard pull request process to submit improvements.

TODO:

  • Add package in Relese
  • Add Unity package manager

License

This project is licensed under the GNU License - see the LICENSE file for details.

Made by RimuruDev