Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ComponentReference allows using GameObject at addressable asset pipeline in the same way as in the classic unity pipeline. This repo moreover solved minor but significant problem: ComponentReference<T> now capable to get derived class of component that inherits T.

License

cyberaslan/Addressables-ComponentReference-with-DerivedClass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

Addressables ComponentReference with DerivedClass

What is AssetReference?

Addressables AssetReference is a special reference to any asset in you project. You can control device memory and build dependencies by using AssetReference instead of native asset type (Sprite, GameObject etc.). See more at doc.

What is AssetReferenceT?

asset-types There is generic AssetReferenceT<TComponent> designed to make strictly typed asset variables. Your assets workflow become the same as Unity classic workflow this way.

How it works with GameObjects?
We can store only AssetReferenceT<GameObject> not to attached MonoBehaviour component. But classic Unity assets workflow supports reference to MonoBehaviour, so? Use ComponentReference<T>.

What is ComponentReference<T>?

ComponentReference is an Addressables extension to store AssetReference via Component attached to GameObject asset. Yes, like a classic Unity prefab. The ComponentReference<T> is a part of Basic Addressables code example doc.

Component derived class problem

Imagine you have some service creates Overlay from prefab list by generic type parameter. type-check Concrete overlay class inherits BaseOverlay but ComponentReference<ConcreteOverlay> is always not ComponentReference<BaseOverlay> cause generic-types specific.

Solution

okay

  1. Realise IComponentReference interface in BaseClass
  2. Get derived ConcreteClass type attached to prefab by GetDerivedComponentType() method.

About

ComponentReference allows using GameObject at addressable asset pipeline in the same way as in the classic unity pipeline. This repo moreover solved minor but significant problem: ComponentReference<T> now capable to get derived class of component that inherits T.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /