1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Unity . Cloud . AppLinking ;
14using Unity . Cloud . Assets ;
25using Unity . ReferenceProject . AssetManager ;
36using Unity . ReferenceProject . AssetList ;
47using Unity . ReferenceProject . DataStores ;
8+ using Unity . ReferenceProject . DeepLinking ;
59using Unity . ReferenceProject . StateMachine ;
610using UnityEngine ;
711using Zenject ;
@@ -14,34 +18,61 @@ public sealed class AssetListState : AppState
1418 AppState m_SceneSelectedState ;
1519
1620 IAssetListController m_AssetListController ;
21+ IDeepLinkingController m_DeepLinkingController ;
22+ IUrlRedirectionInterceptor m_UrlRedirectionInterceptor ;
1723
24+ Uri m_ForwardedDeepLink ;
1825 PropertyValue < IAsset > m_IAsset ;
1926
2027 [ Inject ]
21- void Setup ( IAssetListController assetListController , AssetManagerStore assetManagerStore )
28+ void Setup ( IAssetListController assetListController , IDeepLinkingController deepLinkingController , IUrlRedirectionInterceptor urlRedirectionInterceptor , AssetManagerStore assetManagerStore )
2229 {
2330 m_AssetListController = assetListController ;
31+ m_DeepLinkingController = deepLinkingController ;
32+ m_UrlRedirectionInterceptor = urlRedirectionInterceptor ;
33+
2434 m_IAsset = assetManagerStore . GetProperty < IAsset > ( nameof ( AssetManagerViewModel . Asset ) ) ;
2535 }
2636
2737 void Awake ( )
2838 {
2939 m_AssetListController . AssetSelected += OnAssetSelected ;
40+ m_UrlRedirectionInterceptor . DeepLinkForwarded += OnDeepLinkForwarded ;
3041 }
3142
3243 void OnDestroy ( )
3344 {
3445 m_AssetListController . AssetSelected -= OnAssetSelected ;
46+ m_UrlRedirectionInterceptor . DeepLinkForwarded -= OnDeepLinkForwarded ;
3547 }
3648
3749 protected override async void EnterStateInternal ( )
3850 {
39- await m_AssetListController . Refresh ( ) ;
51+ if ( ! await TryConsumeForwardedDeepLink ( ) )
52+ {
53+ await m_AssetListController . Refresh ( ) ;
54+ }
55+ }
56+
57+ async Task < bool > TryConsumeForwardedDeepLink ( )
58+ {
59+ if ( m_ForwardedDeepLink == null )
60+ return false ;
61+
62+ var deepLinkConsumptionSucceeded = await m_DeepLinkingController . TryConsumeUri ( m_ForwardedDeepLink . AbsoluteUri ) ;
63+ m_ForwardedDeepLink = null ;
64+
65+ return deepLinkConsumptionSucceeded ;
4066 }
4167
4268 void OnAssetSelected ( IAsset asset )
4369 {
4470 AppStateController . PrepareTransition ( m_SceneSelectedState ) . OnBeforeEnter ( ( ) => m_IAsset . SetValue ( asset ) ) . Apply ( ) ;
4571 }
72+
73+ void OnDeepLinkForwarded ( Uri uri )
74+ {
75+ m_ForwardedDeepLink = uri ;
76+ }
4677 }
4778}
0 commit comments