Skip to content

Commit 5f9246b

Browse files
🔀 Merge develop into main (pull request #6)
- Prepare for Unity Asset Store publication: - Change folder structure. - Add Unity Asset Store tools package. - Add a sample. - Add README on package's root. - Upgrade to Unity 6.0.39.
2 parents ee85e6c + 7545bd4 commit 5f9246b

790 files changed

Lines changed: 33477 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/DefaultVolumeProfile.asset

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3}
13+
m_Name: DefaultVolumeProfile
14+
m_EditorClassIdentifier:
15+
components: []

Assets/DefaultVolumeProfile.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Min/max Range Attribute
2+
![openupm](https://img.shields.io/npm/v/com.lazysquirrellabs.minmaxrangeattribute?label=openupm&registry_uri=https://package.openupm.com)
3+
4+
A bounded (i.e., with a minimum and maximum) range attribute for Unity's `Vector2` and `Vector2Int` fields that draws fields as min/max range sliders, easing the definition of bounded ranges on the inspector.
5+
6+
![Five examples of attribute usage on the Unity inspector.](https://minmax.lslabs.dev/assets/images/header.gif)
7+
8+
[![](https://minmax.lslabs.dev/assets/images/get_unity.webp)](https://assetstore.unity.com/packages/tools/utilities/min-max-range-attribute-302500)
9+
10+
## Features
11+
- Intuitive, compact inspector representation.
12+
- Support for Unity's `Vector2` and `Vector2Int` types.
13+
- Easy to use: just add the attribute to a serialized field of a supported type.
14+
- Custom floating-point decimal places (0 to 3).
15+
- Error prevention. Unlike using separate fields for minimum and maximum, value integrity is guaranteed (e.g., the minimum will never be greater than the maximum) by the inspector.
16+
- Uses built-in Unity's [`EditorGUILayout.MinMaxSlider`](https://docs.unity3d.com/ScriptReference/EditorGUILayout.MinMaxSlider.html) under the hood.
17+
18+
19+
## Usage
20+
To use the attribute, simply add it to a serialized field of a supported type (`Vector2` or `Vector2Int`). Its inspector representation will be a [`MinMaxSlider`](https://docs.unity3d.com/ScriptReference/EditorGUILayout.MinMaxSlider.html), a slider than can be used to represent a range within minimum and maximum limits. The left handle controls the vector's `x` component and the right handle controls the vector's
21+
22+
### Vector2 usage
23+
When using the attribute on a field of type `Vector2`, its constructor takes 3 arguments:
24+
- `minLimit`: the minimum possible value (lower bound).
25+
- `maxLimit`: the maximum possible value (upper bound).
26+
- `decimals`: how many decimal places the inspector should display. Default is 1 and values must be in the [0, 3] range.
27+
28+
For example, the field below has `minLimit` equal to 0, `maxLimit` equal to 10 and `decimals` equal to 3:
29+
```csharp
30+
[MinMaxRange(0f, 10f, 3)]
31+
[SerializeField] private Vector2 _optimalSpeed = new (3.141f, 5.789f);
32+
```
33+
34+
And its inspector representation is:
35+
36+
![](https://minmax.matheusamazonas.net/assets/images/usage/vector_3.png)
37+
38+
If `decimals` is 2 (`MinMaxRange(0f, 10f, 2)`):
39+
40+
![](https://minmax.matheusamazonas.net/assets/images/usage/vector_2.png)
41+
42+
The default value of `decimals` is 1, so we might as well omit the parameter if we would like to display only 1 decimal place:
43+
```csharp
44+
[MinMaxRange(0f, 10f)]
45+
[SerializeField] private Vector2 _optimalSpeed = new (3.141f, 5.789f);
46+
```
47+
48+
Which will be displayed as:
49+
50+
![](https://minmax.matheusamazonas.net/assets/images/usage/vector_1.png)
51+
52+
Keep in mind that the `decimals` parameter only controls how the value labels will be displayed on the inspector. It doesn't control the values' precision.
53+
54+
### Vector2Int usage
55+
When using the attribute on a field of type `Vector2Int`, its constructor takes 2 arguments, similar to `RangeAttribute`'s parameters:
56+
- `minLimit`: the minimum possible value (lower bound).
57+
- `maxLimit`: the maximum possible value (upper bound).
58+
59+
For example, the field below has `minLimit` equal to 0 and `maxLimit` equal to 10:
60+
```csharp
61+
[MinMaxRange(0, 10)]
62+
[SerializeField] private Vector2Int _rewardRange = new(2, 4);
63+
```
64+
And its inspector representation is:
65+
66+
![](https://minmax.matheusamazonas.net/assets/images/usage/vector_int.png)
67+
68+
## Importing
69+
The first step is to import the library into your Unity project. There are three ways to do so:
70+
- [Via the Asset Store](#import-via-unity-asset-store).
71+
- Via the Package Manager:
72+
- [Using a git URL](#import-using-a-git-url).
73+
- [Using OpenUPM](#import-with-openupm).
74+
75+
### Import via Unity Asset Store
76+
Click on the image below to visit the package's page on the Unity Asset Store. One there, follow the instructions to import it into your project.
77+
78+
[![](https://minmax.lslabs.dev/assets/images/get_unity.webp)](https://assetstore.unity.com/packages/tools/utilities/min-max-range-attribute-302500)
79+
80+
### Import using a git URL
81+
This approach uses Unity's Package Manager to add the attribute to your project using the repo's git URL. To do so, navigate to `Window > Package Manager` in Unity. Then click on the `+` and select "Add package from git URL":
82+
83+
![](https://minmax.matheusamazonas.net/assets/images/upm_adding.png)
84+
85+
Next, enter the following in the "URL" input field to install the latest version of the attribute:
86+
```
87+
https://github.com/lazysquirrellabs/min_max_range_attribute.git?path=Assets/Lazy Squirrel Labs/MinMaxRangeAttribute
88+
```
89+
Finally, click on the "Add" button. The importing process should start automatically. Once it's done, the attribute can be used in your project.
90+
91+
### Import with OpenUPM
92+
Min/max Range Attribute is available as a package on [OpenUPM](https://openupm.com/packages/com.lazysquirrellabs.minmaxrangeattribute/). To import it into your project via the command line, run the following command:
93+
```
94+
openupm add com.lazysquirrellabs.minmaxrangeattribute
95+
```
96+
Once the importing process is complete, the attribute can be used in your project.
97+
98+
## Compatibility and dependencies
99+
The Min/max Range Attribute requires Unity 2021.3.X or above, its target API compatibility level is .NET Standard 2.1, and it does not depend on any other packages.
100+
101+
## Contributing
102+
If you would like to report a bug, please create an [issue](https://github.com/lazysquirrellabs/min_max_range_attribute/issues). If you would like to contribute with bug fixing or small improvements, please open a Pull Request. If you would like to contribute with a new feature, [contact the developer](https://matheusamazonas.net/contact.html).
103+
104+
## Getting help
105+
Use the [issues page](https://github.com/lazysquirrellabs/min_max_range_attribute/issues) if there's a problem with your setup, if something isn't working as expected, or if you would like to ask questions about the tool and its usage.
106+
107+
## License
108+
Min/max Range Attribute is distributed under the terms of the MIT license. For more information, check the [LICENSE](https://github.com/lazysquirrellabs/min_max_range_attribute/blob/main/LICENSE) file in this repository.

Assets/Lazy Squirrel Labs/MinMaxRangeAttribute/README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Lazy Squirrel Labs/MinMaxRangeAttribute/Samples~/Sample 1.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "LazySquirrelLabs.MinMaxRangeAttribute.Sample1",
3+
"rootNamespace": "LazySquirrelLabs.MinMaxRangeAttribute.Sample1",
4+
"references": [
5+
"GUID:397edf9bfe7ea4399b706e9ee953b982"
6+
],
7+
"includePlatforms": [],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

Assets/Lazy Squirrel Labs/MinMaxRangeAttribute/Samples~/Sample 1/LazySquirrelLabs.MinMaxRangeAttribute.Sample1.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine;
2+
3+
namespace LazySquirrelLabs.MinMaxRangeAttribute.Sample1
4+
{
5+
internal class MinMaxRangeAttributeSample : MonoBehaviour
6+
{
7+
// Vector 2 with integer values within the [1, 11] range.
8+
[SerializeField, MinMaxRange(1, 11)] private Vector2Int _rewardRange;
9+
// Vector 2 with integer values within the [0, 100] range.
10+
[SerializeField, MinMaxRange(0, 100)] private Vector2Int _allowedLevels;
11+
// Vector 2 with floating point values within the [0, 10] range, with default decimals (1).
12+
[SerializeField, MinMaxRange(0f, 10f)] private Vector2 _optimalSpeed;
13+
// Vector 2 with floating point values within the [0, 1] range, with 2 decimals.
14+
[SerializeField, MinMaxRange(0f, 1f, 2)] private Vector2 _normalTemperature;
15+
// Vector 2 with floating point values within the [0, 1] range, with 3 decimals.
16+
[SerializeField, MinMaxRange(0f, 1f, 3)] private Vector2 _relativeDistance;
17+
}
18+
}

0 commit comments

Comments
 (0)