Skip to content

ComponentReference<T> capable to get derived class of component that inherits T.

License

Notifications You must be signed in to change notification settings

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<T> 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