@@ -47,113 +47,113 @@ public static void RunGame()
4747 Debug . Log ( "HotUpdateScripts EntryPoint RunGame called." ) ;
4848 // Your game logic goes here
4949 Button addOnDemoButton = GameObject . Find ( "Canvas/BtnList/AddOnDemoButton" ) . GetComponent < Button > ( ) ;
50- addOnDemoButton . onClick . AddListener ( ( ) =>
50+
51+ async UniTask LoadAddOnPackage ( )
5152 {
52- UniTask . RunOnThreadPool ( async ( ) =>
53+ try
5354 {
54- await UniTask . SwitchToMainThread ( ) ;
55- try
56- {
57- addOnDemoButton . interactable = false ; // Prevent duplicate clicks
58- Debug . Log ( "AddOnDemoButton clicked." ) ;
59- var packageName = "addon1" ;
55+ addOnDemoButton . interactable = false ; // Prevent duplicate clicks
56+ Debug . Log ( "AddOnDemoButton clicked." ) ;
57+ var packageName = "addon1" ;
6058
61- // Create or get AddOn1 package
62- var package = Bootstrap . CreateOrGetPackage ( packageName ) ;
59+ // Create or get AddOn1 package
60+ var package = Bootstrap . CreateOrGetPackage ( packageName ) ;
6361
64- // Set up AddOn package initialization callbacks
65- var callbacks = new PackageInitializationCallbacks
62+ // Set up AddOn package initialization callbacks
63+ var callbacks = new PackageInitializationCallbacks
64+ {
65+ OnStatusUpdate = static status => Debug . Log ( $ "[AddOn1] Status: { GetStatusText ( status ) } ") ,
66+ OnVersionUpdate = static version => Debug . Log ( $ "[AddOn1] Version: { version } ") ,
67+ OnDownloadPrompt = static ( count , size ) => MessageBox . Show ( "Notice" ,
68+ $ "[AddOn1] Need to download { count } files, total size { size / 1024f / 1024f : F2} MB. Continue?",
69+ "Yes" , "No" ) ,
70+ OnDownloadProgress = static data =>
6671 {
67- OnStatusUpdate = static status => Debug . Log ( $ "[AddOn1] Status: { GetStatusText ( status ) } ") ,
68- OnVersionUpdate = static version => Debug . Log ( $ "[AddOn1] Version: { version } ") ,
69- OnDownloadPrompt = static ( count , size ) => MessageBox . Show ( "Notice" ,
70- $ "[AddOn1] Need to download { count } files, total size { size / 1024f / 1024f : F2} MB. Continue?",
71- "Yes" , "No" ) ,
72- OnDownloadProgress = static data =>
73- {
74- Debug . Log (
75- $ "[AddOn1] Download progress: { data . CurrentDownloadCount } /{ data . TotalDownloadCount } ({ Mathf . RoundToInt ( data . Progress * 100 ) } %)") ;
76- } ,
77- OnDownloadStart = static ( ) => Debug . Log ( "[AddOn1] Starting download..." ) ,
78- OnDownloadComplete = static ( ) => Debug . Log ( "[AddOn1] Download completed!" ) ,
79- OnError = static async error =>
80- {
81- Debug . LogError ( $ "[AddOn1] Error: { error } ") ;
82- await UniTask . CompletedTask ; // Simple error handling
83- }
84- } ;
85-
86- // Use Bootstrap's common initialization function
87- Debug . Log ( "[AddOn1] Starting AddOn1 package initialization..." ) ;
88- bool success = await Bootstrap . UpdatePackage ( package , callbacks , EncryptionOption . Xor ) ;
89-
90- if ( ! success )
72+ Debug . Log (
73+ $ "[AddOn1] Download progress: { data . CurrentDownloadCount } /{ data . TotalDownloadCount } ({ Mathf . RoundToInt ( data . Progress * 100 ) } %)") ;
74+ } ,
75+ OnDownloadStart = static ( ) => Debug . Log ( "[AddOn1] Starting download..." ) ,
76+ OnDownloadComplete = static ( ) => Debug . Log ( "[AddOn1] Download completed!" ) ,
77+ OnError = static async error =>
9178 {
92- Debug . LogError ( "[AddOn1] AddOn1 package initialization failed! " ) ;
93- return ;
79+ Debug . LogError ( $ "[AddOn1] Error: { error } ") ;
80+ await UniTask . CompletedTask ; // Simple error handling
9481 }
82+ } ;
9583
96- Debug . Log ( "[AddOn1] AddOn1 package initialization successful!" ) ;
84+ // Use Bootstrap's common initialization function
85+ Debug . Log ( "[AddOn1] Starting AddOn1 package initialization..." ) ;
86+ bool success = await Bootstrap . UpdatePackage ( package , callbacks , EncryptionOption . Xor ) ;
9787
98- // Load AddOn1 scene
99- var sceneLoadCallbacks = new SceneLoadCallbacks
100- {
101- OnStatusUpdate = static status => Debug . Log ( $ "[AddOn1] { GetSceneLoadStatusText ( status ) } ") ,
102- OnProgressUpdate = static progress => Debug . Log ( $ "[AddOn1] Loading progress: { progress * 100 : F0} %") ,
103- OnError = static exception =>
104- {
105- Debug . LogError ( $ "[AddOn1] Scene loading failed: { exception . Message } ") ;
106- return UniTask . CompletedTask ;
107- }
108- } ;
88+ if ( ! success )
89+ {
90+ Debug . LogError ( "[AddOn1] AddOn1 package initialization failed!" ) ;
91+ return ;
92+ }
10993
110- var handle = await Bootstrap . LoadHotUpdateScene ( package ,
111- "Assets/HotUpdate/AddOn1/Scene/test.unity" ,
112- sceneLoadCallbacks ) ;
113- if ( handle != null )
114- {
115- Debug . Log ( "Entered addon scene" ) ;
116- }
117- else
118- {
119- Debug . LogError ( "[AddOn1] Scene loading exception" ) ;
120- }
94+ Debug . Log ( "[AddOn1] AddOn1 package initialization successful!" ) ;
12195
122- // Load AddOn1 resources
123- var textHandle = package . LoadAssetAsync < TextAsset > ( "Assets/HotUpdate/AddOn1/Other/test.txt" ) ;
124- await textHandle . Task ;
125- if ( textHandle . Status == EOperationStatus . Succeed )
126- {
127- var textAsset = textHandle . GetAssetObject < TextAsset > ( ) ;
128- Debug . Log ( $ "[AddOn1] Loaded text content: { textAsset . text } ") ;
129- textHandle . Release ( ) ; // Remember to release resources
130- }
131- else
96+ // Load AddOn1 scene
97+ var sceneLoadCallbacks = new SceneLoadCallbacks
98+ {
99+ OnStatusUpdate = static status => Debug . Log ( $ "[AddOn1] { GetSceneLoadStatusText ( status ) } ") ,
100+ OnProgressUpdate = static progress =>
101+ Debug . Log ( $ "[AddOn1] Loading progress: { progress * 100 : F0} %") ,
102+ OnError = static exception =>
132103 {
133- Debug . LogWarning ( $ "[AddOn1] Failed to load test.txt file: { textHandle . LastError } ") ;
104+ Debug . LogError ( $ "[AddOn1] Scene loading failed: { exception . Message } ") ;
105+ return UniTask . CompletedTask ;
134106 }
107+ } ;
135108
136- // Clear AddOn1 package cache (optional)
137- await Bootstrap . DeletePackageCache ( package ) ;
138- Debug . Log ( "[AddOn1] AddOn1 package download cache cleanup completed." ) ;
109+ var handle = await Bootstrap . LoadHotUpdateScene ( package ,
110+ "Assets/HotUpdate/AddOn1/Scene/test.unity" ,
111+ sceneLoadCallbacks ) ;
112+ if ( handle != null )
113+ {
114+ Debug . Log ( "Entered addon scene" ) ;
139115 }
140- catch ( System . Exception ex )
116+ else
141117 {
142- Debug . LogError ( $ "[AddOn1] Exception occurred: { ex . Message } ") ;
118+ Debug . LogError ( "[AddOn1] Scene loading exception " ) ;
143119 }
144- finally
120+
121+ // Load AddOn1 resources
122+ var textHandle = package . LoadAssetAsync < TextAsset > ( "Assets/HotUpdate/AddOn1/Other/test.txt" ) ;
123+ await textHandle . Task ;
124+ if ( textHandle . Status == EOperationStatus . Succeed )
145125 {
146- try
147- {
148- addOnDemoButton . interactable = true ; // Restore button clickability
149- }
150- catch
151- {
152- // Ignore exception
153- }
126+ var textAsset = textHandle . GetAssetObject < TextAsset > ( ) ;
127+ Debug . Log ( $ "[AddOn1] Loaded text content: { textAsset . text } ") ;
128+ textHandle . Release ( ) ; // Remember to release resources
129+ }
130+ else
131+ {
132+ Debug . LogWarning ( $ "[AddOn1] Failed to load test.txt file: { textHandle . LastError } ") ;
133+ }
134+
135+ // Clear AddOn1 package cache (optional)
136+ await Bootstrap . DeletePackageCache ( package ) ;
137+ Debug . Log ( "[AddOn1] AddOn1 package download cache cleanup completed." ) ;
138+ }
139+ catch ( System . Exception ex )
140+ {
141+ Debug . LogError ( $ "[AddOn1] Exception occurred: { ex . Message } ") ;
142+ }
143+ finally
144+ {
145+ try
146+ {
147+ addOnDemoButton . interactable = true ; // Restore button clickability
148+ }
149+ catch
150+ {
151+ // Ignore exception
154152 }
155- } ) . Forget ( ) ;
156- } ) ;
153+ }
154+ }
155+
156+ addOnDemoButton . onClick . AddListener ( ( ) => { LoadAddOnPackage ( ) . Forget ( ) ; } ) ;
157157 }
158158
159159 private static string GetStatusText ( PackageInitializationStatus status )
0 commit comments