Custom propery drawers to ease fields value management in Unity editor.
- AnimationName
- AnimatorLayerName
- AnimatorParameterName
- AnimatorStateName
- AssetPath
- GameObjectLayer
- GameObjectTag
- ScenePath
- SortingLayerName
- SpriteAtlasSpriteName
Project supports Unity Package Manager. To install project as Git package do following:
- Close Unity project and open the
Packages/manifest.json
file. - Update
dependencies
to havecom.rfadeev.unityforge.propertydrawers
package:
{
"dependencies": {
"com.rfadeev.unityforge.propertydrawers": "https://github.com/rfadeev/unity-forge-property-drawers.git"
}
}
- Open Unity project.
Alternatively, add this repository as submodule under Assets
folder or download it and put to Assets
folder of your Unity project.
Import UnityForge.PropertyDrawers
namespace to be able to use attribute from the attributes list.
Add attribute to string field to enable selection of animation name value from dropdown list in Unity editor. Attribute without parameters works on Animation component attached to inspected object.
[SerializeField, AnimationName]
private string animationName;
Specify animation component via animationField
constructor parameter to enable animation name selection from that component.
[SerializeField]
private Animation exampleAnimation;
[SerializeField, AnimationName(animationField: "exampleAnimation")]
private string animationName;
Unity manages clips internally specifically so for some reason order of clips returned by AnimationUtility.GetAnimationClips differs from the one displayed in the editor for Animation comoponent. Due to this expect different order of items in dropdown list for attribute.
Add attribute to string field to enable selection of animator layer name value from dropdown list in Unity editor. Attribute without parameters works on Animator component attached to inspected object.
[SerializeField, AnimatorLayerName]
private string layerName;
Specify Animator component via animatorField
constructor parameter to enable layer name selection from that Animator component.
[SerializeField]
private Animator exampleAnimator;
[SerializeField, AnimatorStateName(animatorField: "exampleAnimator")]
private string exampleLayerName;
Add attribute to string field to enable selection of animator parameter name value from dropdown list in Unity editor. Note that parameter type must be specified for attribute. Attribute without other parameters works on Animator component attached to inspected object.
[SerializeField, AnimatorParameterName(AnimatorControllerParameterType.Float)]
private string exampleFloatParameterName;
Specify Animator component via animatorField
constructor parameter to enable parameter name selection from that Animator component.
[SerializeField]
private Animator exampleAnimator;
[SerializeField]
[AnimatorParameterName(AnimatorControllerParameterType.Float, animatorField: "exampleAnimator"))]
private string exampleFloatParameterName;
Add attribute to string field to enable selection of animator state name value from dropdown list in Unity editor. Attribute without parameters works on Animator component attached to inspected object.
[SerializeField, AnimatorStateName]
private string stateName;
Specify Animator component via animatorField
constructor parameter to enable state name selection from that Animator component.
[SerializeField]
private Animator exampleAnimator;
[SerializeField, AnimatorStateName(animatorField: "exampleAnimator")]
private string exampleStateName;
Since layer index is decoupled from animator state name in Unity API, state name alone does not determine state and state index value should be managed separately. If only one animation layer is used, it's not the problem and Play(string stateName)
overload can be used safely for fields using AnimatorStateName
attribute.
Add attribute to string field to enable show object field instead of text input for object path. Object selection updates serialized value of the string field. Attribute declataion requires object type. Attribute supports both full project path (like "Assets/Sprites/MySpriteA.png") and resources path type (like "Sprites/MySpriteB" for full path value "Assets/Resources/Sprites/MySpriteB.png"). Additionnal option allows to preview path value which is serialized.
[SerializeField, AssetPath(typeof(Sprite), false)]
private string spriteProjectPath01;
[SerializeField, AssetPath(typeof(Sprite), true)]
private string spriteResourcesPath01;
[SerializeField, AssetPath(typeof(Sprite), false, true)]
private string spriteProjectPath02;
[SerializeField, AssetPath(typeof(Sprite), true, true)]
private string spriteResourcesPath02;
Add attribute to int field to enable selection of game object layer value from dropdown list in Unity editor. Layers are configured in Tags and Layers Manager.
[SerializeField, GameObjectLayer]
private int exampleLayer;
Add attribute to string field to enable selection of game object tag value from dropdown list in Unity editor. Tags are configured in Tags and Layers Manager.
[SerializeField, GameObjectTag]
private string exampleTag;
Add attribute to string field to enable selection of scene path value from dropdown list in Unity editor. Path type can be set via fullProjectPath
argument: if true, scene path will be full project path like "Assets/Scenes/MyScene.unity"; if false, path will be short project path without "Assets/" and ".unity" extension like "Scenes/MyScene". Source to populate dropdown can be set via fromBuildSettings
argument: if true, only scenes from build settings will be shown in dropdown; if false, all scenes from project will be shown in dropdown. Additionally, onlyEnabled
argument can be used to show only scenes enabled in build settings if fromBuildSettings
is set to true.
// Full scene path, only enabled scenes from build settings
[SerializeField, ScenePath]
private string exampleScenePath01;
// Short scene path, only enabled scenes from build settings
[SerializeField, ScenePath(fullProjectPath: false))]
private string exampleScenePath02;
// Full scene path, all scenes from project
[SerializeField, ScenePath(fromBuildSettings: false))]
private string exampleScenePath03;
// Short scene path, all scenes from build settings
[SerializeField, ScenePath(fullProjectPath: false, onlyEnabled: false))]
private string exampleScenePath04;
Add attribute to string field to enable selection of sorting layer name value from dropdown list in Unity editor. Sorting layers are configured in Tags and Layers Manager.
[SerializeField, SortingLayerName]
private string exampleSortingLayerName;
Add attribute to string field and specify sprite atlas field to enable selection of sprite name from that atlas via dropdown list in Unity editor.
[SerializeField]
private SpriteAtlas atlas;
[SerializeField, SpriteAtlasSpriteName(spriteAtlasField: "atlas")]
private string spriteName;