Yes, IT IS better and faster than Unity coroutines
Required UniTask itself, so first-thing-first install a .unitypackage from this link. Can be used for default .NET classes if you install UniTask as NuGet package. Also feel free to change whatever you want or collab.
Simple example where we have our popups inside Popups
folder (Assets/Resources/Popups/
), and we need to get our prefab which is MonoContainer
inherited and called Friend Invite Popup
:
First create a factory, our base one or your custom one (you can inherit and override creation process for your needs):
_popupsFactory = new BaseResourceFactory("Popups", _popupScreenRoot.transform);
Lets get the Friend Invite Popup
from Resources/Popups/
and pass it whoever, since MonoContainer.Data
inside is initialized and Unity GameObject
already created:
var container = await _popupsFactory
.CreateInstance<FriendInvitePopup, InviteData>(new InviteData(_friend, _unixTimeRequestCreated));
Remark: You can create new factories and override creation methods and you can pass any data to a container, just create class and inherit
ContainerData
(for examplepublic class LoginData : ContainerData
), or even pass anull
ornew ContainerData()
if u dont need it for some reason