Unity download resources from the server and save to the local area

2023-01-07   ES  

Two small functions

From the server to download resources and resources to the local area ~

The following code

/// <summary> 
     /// Download and save resources to the local area 
     /// </summary> 
     /// <param name = "url"> </param> 
     /// <param name = "name"> </param> 
     /// <return> </retarns> 
     Public Static Ienmerator DownloadsAve (String URL, String name, Action <Bool, String> Finish = NULL) 
     {{ 
         url = Uri.escapeuristring (url); 
         string loading = string.empty; 
         BOOL B = FALSE; 
         Www www = new www (url); 
         if (www.error! = Null) 
         {{ 
             Print ("error:" + www.error); 
         } 
         While (! www.isdone) 
         {{ 
             Loading = ((int) ((int) (www.progress * 100)) % 100) + " %"; 
             If (Finish! = NULL) 
 {{ 
 Finish (b, loading); 
 } 
             yield Return 1; 
         } 
        if (www.isdone) 
         {{ 
             Loading = "100%"; 
             byte [] bytes = www.bytes; 
             B = SaveasSETS (Application.PersistentDataPath, name, bytes); 
             If (Finish! = NULL) 
 {{ 
 Finish (b, loading); 
 } 
         } 
     }

/// <summary> 
     /// Save resources to the local area 
     /// </summary> 
     /// <param name = "PATH"> </Param> 
     /// <param name = "name"> </param> 
     /// <param name = "info"> </param> 
     /// <param name = "length"> </param> 
     Public Static Bool Saveassets (String Path, String name, byte [] bytes) 
     {{ 
         Stream SW; 
         Fileinfo t = new fileinfo (path + "//" + name); 
         if (! T.Exists) 
         {{ 
             try 
             {{ 
                 sw = t.create (); 
                 sw.write (bytes, 0, bytes.length); 
                 sw.close (); 
                 sw.dispose (); 
                 Return true; 
             } 
             catch 
             {{ 
                 Return false; 
             } 
         } 
         else 
         {{ 
             Return true; 
         } 
     }

source

Random Posts

1 1 1 1, line color THOMAS

jetpack data binding source code interpretation (1)

1 1 1 1 1 1

Vue project actual combat (1) Vue-CLI scaffolding project

HTML common text element BB