Releases: RimuruDev/Unity-PercentDrawer
v1.1.0
⭐Percentage Property Drawer for Unity⭐
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.
Option 1: Install via Unity Package Manager
- Open Unity and go to
Window
>Package Manager
. - Click the
+
button in the top left corner. - Select
Add package from git URL...
. - Enter the following URL:
https://github.com/RimuruDev/Unity-PercentDrawer.git
- Click
Add
to install the package.
Option 2: Install from Releases
- Go to the Releases page in this repository.
- Download the latest
.unitypackage
file. - In Unity, go to
Assets
>Import Package
>Custom Package...
. - Select the downloaded
.unitypackage
file and import it into your project.
Option 3: Install from copy-past
- Create a folder named
Editor
within your project'sAssets
directory if it does not already exist. Unity requires
that all editor scripts be located in a folder namedEditor
. - Create a folder named
Attributes
within yourAssets
directory to store custom attributes. - Place the
PercentageAttribute.cs
file inside theAttributes
folder. - Place the
PercentDrawer.cs
file inside theEditor
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
Full Changelog: v1.0.0.0...v1.1.0