1010using UnityEngine . Android ;
1111using UnityEngine . UI ;
1212
13-
1413public class Modeling3dDemoManager : MonoBehaviour
1514{
1615 ///It is necessary to add permissions in the Android manifest. Assets\Huawei\Plugins\Android\HMSUnityModelingKit.plugin\AndroidManifest.xml
@@ -24,7 +23,6 @@ public class Modeling3dDemoManager : MonoBehaviour
2423 } ;
2524
2625 //Getting apikey in agconnect json file.
27- private const string YOUR_API_KEY = "" ;
2826 private const string TASK_LIST_PREFS_KEY = "3dTaskList" ;
2927 private const string TAG = "[HMS] Modeling3dDemoManager " ;
3028
@@ -38,7 +36,7 @@ public class Modeling3dDemoManager : MonoBehaviour
3836 [ SerializeField ] private GameObject taskList ;
3937 [ SerializeField ] private GameObject taskItemPrefab ;
4038 #endregion
41- /// TODO: This singleton can be written as a generic class to extend MonoBehavior. It saves code repetition and is available in every demo manager.r.
39+ /// TODO: This singleton can be written as a generic class to extend MonoBehavior. It saves code repetition and is available in every demo manager.
4240 #region Singleton
4341
4442 public static Modeling3dDemoManager Instance { get ; private set ; }
@@ -74,10 +72,7 @@ void Start()
7472 HMSModeling3dKitManager . Instance . OnResultDownload = OnResultDownload ;
7573 //HMSModeling3dKitManager.Instance.OnResultPreview = OnResultPreview;
7674
77- Debug . Log ( TAG + "LogIn By API key" ) ;
78-
79- HMSModeling3dKitManager . Instance . AuthWithApiKey ( YOUR_API_KEY ) ;
80-
75+ HMSModeling3dKitManager . Instance . AuthWithApiKey ( HMSModelingKitSettings . ModelingKeyAPI ) ;
8176 }
8277 public void OnUploadProgress ( string taskId , double progress , AndroidJavaObject obj ) {
8378 progressBar . current = Mathf . RoundToInt ( ( float ) progress ) ;
@@ -93,7 +88,6 @@ public void OnUploadProgress(string taskId, double progress, AndroidJavaObject o
9388 modeling3dTaskEntity . Update ( data ) ;
9489 PlayerPrefs . SetString ( "currentTaskId" , taskId ) ;
9590 } ) ;
96-
9791 }
9892 public void OnResultUpload ( string taskId , Modeling3dReconstructUploadResult result , AndroidJavaObject obj )
9993 {
@@ -111,9 +105,9 @@ public void OnResultUpload(string taskId, Modeling3dReconstructUploadResult resu
111105 data . Type = 1 ;
112106 modeling3dTaskEntity . Update ( data ) ;
113107 PlayerPrefs . SetString ( "currentTaskId" , taskId ) ;
108+ PlayerPrefs . Save ( ) ;
114109 AndroidToast . MakeText ( "Upload Complated. Open Task List and Check It." ) . Show ( ) ;
115110 progressBar . gameObject . SetActive ( false ) ;
116-
117111 } ) ;
118112 }
119113 else
@@ -131,7 +125,7 @@ public void OnDownloadProgress(string taskId, double progress, AndroidJavaObject
131125 HMSDispatcher . Invoke ( ( ) =>
132126 {
133127 var data = new Modeling3dDTO ( ) ;
134- var currentTaskId = PlayerPrefs . GetString ( "currentTaskId" ) ;
128+ var currentTaskId = PlayerPrefs . GetString ( "currentTaskId" , "null" ) ;
135129 data = modeling3dTaskEntity . Find ( currentTaskId ) ;
136130 data . TaskId = taskId ;
137131 data . Status = $ "DownloadProgress";
@@ -158,7 +152,6 @@ public void OnResultDownload(string taskId, Modeling3dReconstructDownloadResult
158152 PlayerPrefs . SetString ( "currentTaskId" , taskId ) ;
159153 AndroidToast . MakeText ( $ "Download Complated.\n Download Path: { currentDownloadFilePath } ") . Show ( ) ;
160154 progressBar . gameObject . SetActive ( false ) ;
161-
162155 } ) ;
163156 }
164157 else
@@ -168,7 +161,6 @@ public void OnResultDownload(string taskId, Modeling3dReconstructDownloadResult
168161 AndroidToast . MakeText ( "Download Not Complated" ) . Show ( ) ;
169162 } ) ;
170163 }
171-
172164 }
173165 public void OnResultPreview ( string taskId , AndroidJavaObject obj )
174166 {
@@ -185,7 +177,6 @@ public void OnResultPreview(string taskId, AndroidJavaObject obj)
185177 modeling3dTaskEntity . Update ( data ) ;
186178 PlayerPrefs . SetString ( "currentTaskId" , taskId ) ;
187179 AndroidToast . MakeText ( "Preview Complated" ) . Show ( ) ;
188-
189180 } ) ;
190181 }
191182 private bool ArePermissionsGranted ( string [ ] permissions )
@@ -201,9 +192,9 @@ private bool ArePermissionsGranted(string[] permissions)
201192 }
202193 public void UploadFile ( )
203194 {
195+ AndroidToast . MakeText ( "Number of Input Images:20 to 200 (at least 50 recommended.)" ) . Show ( ) ;
204196 AndroidFolderPicker . mOnSuccessListener = OnUploadSuccessFolderPicker ;
205197 AndroidFolderPicker . OpenFolderPicker ( ) ;
206-
207198 }
208199 public void OnUploadSuccessFolderPicker ( AndroidIntent androidIntent )
209200 {
@@ -215,7 +206,6 @@ public void OnUploadSuccessFolderPicker(AndroidIntent androidIntent)
215206 progressBar . current = 0 ;
216207 HMSModeling3dKitManager . Instance . UploadFile ( settings , currentUploadFilePath ) ;
217208 AndroidToast . MakeText ( "Start Uploading..." ) . Show ( ) ;
218-
219209 }
220210 public void DownloadFile ( string TaskId , string ModelFormat = null , int ? TextureMode = null )
221211 {
@@ -237,7 +227,6 @@ public void OnDownloadSuccessFolderPicker(AndroidIntent androidIntent)
237227 progressBar . current = 0 ;
238228 HMSModeling3dKitManager . Instance . DownloadFile ( config , PlayerPrefs . GetString ( "currentTaskId" ) , currentDownloadFilePath ) ;
239229 AndroidToast . MakeText ( "Start Downloading...\n Please Back to Main Menu." ) . Show ( ) ;
240-
241230 }
242231 public void PreviewFile ( string TaskId , int ? TextureMode = null )
243232 {
@@ -250,16 +239,14 @@ public void PreviewFile(string TaskId, int? TextureMode = null)
250239
251240 HMSModeling3dKitManager . Instance . PreviewFile ( config , TaskId ) ;
252241 AndroidToast . MakeText ( "Start Previewing..." ) . Show ( ) ;
253-
254-
255242 }
256243 public Modeling3dReconstructQueryResult QueryTask ( string taskId = null )
257244 {
258245 if ( taskId == null )
259246 {
260247 taskId = PlayerPrefs . GetString ( "currentTaskId" ) ;
261248 }
262- Debug . Log ( $ "Current TaskId { taskId } ") ;
249+ Debug . Log ( $ "{ TAG } Current TaskId { taskId } ") ;
263250 return HMSModeling3dKitManager . Instance . QueryTask ( taskId ) ;
264251 }
265252 public void Create3DCaptureImage ( )
@@ -296,7 +283,6 @@ public void Cancel3dModelReconstruct()
296283 Invoke ( "CancelOperationWait" , 5 ) ;
297284 } ) ;
298285 }
299-
300286 }
301287 private void CancelOperationWait ( )
302288 {
@@ -326,7 +312,6 @@ public void TaskList()
326312
327313 DestoryChildrenByType ( taskListItemParentObj , typeof ( TaskListDisplay ) ) ;
328314 CreateTaskListItem ( taskListData , taskListItem , taskListItemParentObj ) ;
329-
330315 }
331316 private void CreateTaskListItem ( List < Modeling3dDTO > taskListData , TaskListDisplay taskListItem , GameObject taskListItemParentObj ) {
332317 foreach ( var task in taskListData )
@@ -342,7 +327,7 @@ private void CreateTaskListItem(List<Modeling3dDTO> taskListData, TaskListDispla
342327 taskListItem . RawImage . texture = texture ;
343328 }
344329 taskListItem . HasDownloaded . gameObject . SetActive ( ! string . IsNullOrWhiteSpace ( task . DownloadFilePath ) ) ;
345- var successCondition = task . Status . Contains ( "3" ) && task . Status . Contains ( "success " ) ;
330+ var successCondition = task . Status . Contains ( "3" ) && task . Status . Contains ( "Success " ) ;
346331 taskListItem . PreviewButton . gameObject . SetActive ( successCondition ) ;
347332 taskListItem . DownloadButton . gameObject . SetActive ( successCondition ) ;
348333
@@ -357,7 +342,6 @@ private void CreateTaskListItem(List<Modeling3dDTO> taskListData, TaskListDispla
357342 obj . transform . SetSiblingIndex ( lastChild . GetSiblingIndex ( ) + 1 ) ;
358343 obj . transform . SetPositionAndRotation ( new Vector3 ( lastChild . position . x , lastChild . position . y - 150 , lastChild . position . z ) , lastChild . rotation ) ;
359344 }
360-
361345 }
362346 }
363347 private void DestoryChildrenByType ( GameObject parent , Type type )
@@ -378,7 +362,7 @@ public void DeleteTask(string taskId = null)
378362 {
379363 taskId = PlayerPrefs . GetString ( "currentTaskId" ) ;
380364 }
381- Debug . Log ( $ "Current TaskId { taskId } ") ;
365+ Debug . Log ( $ "{ TAG } Current TaskId { taskId } ") ;
382366 HMSModeling3dKitManager . Instance . DeleteTask ( taskId ) ;
383367 }
384368
0 commit comments