/AutoReferenceAttribute

[Unity] Resolve the SerializeField reference.

Primary LanguageC#MIT LicenseMIT

Auto Reference Attribute

Automatically resolves SerializeField references. It collects the references on the Hierarchy and displays them in a drop-down.

Field

[SerializeField, AutoReference] AutoReferenceExampleObject obj;

Auto Reference

Array and List

[SerializeField, AutoReference] AutoReferenceExampleObject[] obj;
[SerializeField, AutoReference] List<AutoReferenceExampleObject> obj;

childOnly

Just give it an AutoReference attribute.

[SerializeField, AutoReference] MyScript script;

Why use Auto Reference Attribute?

  • It has better performance than GetComponent.
  • You can check it in Hierarchy, so it is intuitive.
  • It's easy to add AutoReference.
  • If a script goes missing, you can reconfigure it by simply selecting it.

Available Types

  • Class(MonoBehaviour)
  • Class(MonoBehaviour)[] array
  • List<Class(MonoBehaviour)> List
  • It is only supported on Hierarchy.
  • UnityEngine's api is NOT supported due to performance reasons.
  • You can get up to child objects.

Notes on Arrays and Lists

For some reasons, it will not work with 0, so enter 1.

Notes on Arrays and Lists

Unity Version

Unity 2018.4 higher

Getting started

Package Manager

URL : https://github.com/IShix-g/AutoReferenceAttribute.git?path=Assets/Plugins/AutoReferenceAttribute

[Unity 2019.3 higher] Install via git URL

Add the Url to Package Manager

UPM Package

[Unity 2018.4 higher] Add URL manually

Add the Url to Packages/manifest.json.

Unitypackage

SerializeFieldAutoReferenceAttribute/releases

Auto Reference

Options

childOnly

For transform children only.

[SerializeField, AutoReference(childOnly:true)] AutoReferenceExampleObject objChildOnly;

childOnly

parent

By passing transform as a string, only the children of the selected transform will be targeted.

[SerializeField] Transform parentTransform;
[SerializeField, AutoReference(parent:"parentTransform")] List<AutoReferenceExampleObject> objList;

parent