Skip to content

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

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
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

14 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

Option 1: Install via Unity Package Manager

  1. Open Unity and go to Window > Package Manager.

  2. Click the + button in the top left corner.

  3. Select Add package from git URL....

  4. Enter the following URL: https://github.com/RimuruDev/Unity-PercentDrawer.git

  5. Click Add to install the package.

  6. If error -

Library/PackageCache/unity-percent-drawer@390d399580/Sources/Editor/PercentDrawer.cs(22,34):
error CS0246: The type or namespace name 'PercentageAttribute' could not be found (are you missing a using directive or an assembly reference?)

Go next -> Option 2: Install from Releases

Option 2: Install from Releases

  1. Go to the Releases page in this repository.
  2. Download the latest .unitypackage file.
  3. In Unity, go to Assets > Import Package > Custom Package....
  4. Select the downloaded .unitypackage file and import it into your project.

Option 3: Install from copy-past

  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.

License

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

Made by RimuruDev