- Property attributes for Unity fields
- Unity minimum version: 2020.3
- Current version: 3.0.0
- Licence: MIT
Just use one of the following attributes:
- AssetsOnly: only select assets references.
- Required: use it on strings, exposed and object reference types. If the value is null or empty, an error message will be displayed on Inspector bellow the given attribute.
- Tag: use it only with string fields. It'll replace the string field by a tag popup.
- DisableInPlayMode: use this to prevent users from editing a property when in play mode.
using UnityEngine;
using ActionCode.Attributes;
public sealed class TestBehaviour : MonoBehaviour
{
[AssetsOnly(typeof(GameObject))] public GameObject player;
[Required] public string playerId;
[Tag] public string playerTag = "Player";
}
- ShowIf: use it to show properties based on the current state of the object.
using ActionCode.Attributes;
public sealed class TestBehaviour : MonoBehaviour
{
[Range(0, 20)] public int powerLevel;
[ShowIf("powerLevel", LogicalOperatorType.GreaterOrEqual, 10)]
public string powerLevelName = "Super Power";
}
- ReadonlyIf: use it to disallow changes in properties based on the current state of the object.
using ActionCode.Attributes;
public sealed class TestBehaviour : MonoBehaviour
{
public RigidbodyConstraints2D constraint;
[ReadonlyIf("constraint", RigidbodyConstraints2D.FreezePositionX)]
public float forceX = 10F;
}
- CreateButton: use it to add a Create Button next to a ScriptableObject field if no reference is set.
using ActionCode.Attributes;
public sealed class TestBehaviour : MonoBehaviour
{
[CreateButton(typeof(SceneTransition))]
public SceneTransition defaultTransition;
}
Follow the instructions inside here and the package ActionCode-Attributes will be available for you to install using the Package Manager windows.
You will need a Git client installed on your computer with the Path variable already set.
-
Use the Package Manager "Add package from git URL..." feature and paste this URL:
https://github.com/HyagoOliveira/Attributes.git
-
You can also manually modify you
Packages/manifest.json
file and add this line insidedependencies
attribute:
"com.actioncode.attributes":"https://github.com/HyagoOliveira/Attributes.git"
Hyago Oliveira