Refer to the Lzma SDK usage method for rain pine:
http://www.xuanyusong.com/archives/3095
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
You plan to use uncompressed assetbundle in your project, so you need to pack the assetbundle manually because you have previously packaged an analysis of 100,000 cold jokes, so this time firmly select the LZMA compression algorithm to compress the Assetbundle.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Note:
Because I do not know lzma how to compress and unzip the folder, so it is planned to upk the folder into UPK file, and then Lzma compression. Unzip the words first extract the UPK file, and then read the UPK file to release the source files.
LZMA official website Download SDK
Http://www.7-zip.org/sdk.html
After downloading the 7zip in C # directly into unity, then Setting.cs will error, delete it.
Note:
the LZMA SDK source code in this example has been modified by me.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
The code is as follows:
Using unityengine;using system.collections;using sevenzip;using system.io;using unityeditor;using System;using System.threading;using Unityengine.ui;public class Newbehaviourscript:monobehaviour {[SerializeField]Slider m_ Slider; Codeprogress m_codeprogress=null;//Progress; Thread m_compressthread=null;//compression threads; Thread m_decompressthread=null;//the extracted threads; string applicationdatapath=string. empty;private float m_percent=0f;//Use this for initializationvoid Start () {applicationdatapath=application.datapath; M_codeprogress=new codeprogress (setprogresspercent);} void Update () {if (m_percent>0f) {m_slider.value=m_percent;if (m_percent==1f) {Debug.Log ("m_percent==1f"); m_ percent=0f; Assetdatabase.refresh ();}}} void Ongui () {if (GUI. button (new Rect (100,100,100,100), "Compress")) {m_slider.value=0f;m_compressthread=new Thread (new ThreadStart ( testcompress)); M_compressthread.start ();} if (GUI. button (new Rect (300,100,100,100), "decompress")) {m_slider.value=0f;m_decompressthread=new Thread (new ThreadStart ( testdecompress)); m_Decompressthread.start ();}} void Testcompress () {try{compress (applicationdatapath+ "/lib. UPK ", applicationdatapath+"/lib. ZUPK ");} catch (Exception ex) {Debug.Log (ex);}} void Testdecompress () {try{decompress (applicationdatapath+ "/lib. ZUPK ", applicationdatapath+"/LIB1. UPK ");} catch (Exception ex) {Debug.Log (ex);}} void Setprogresspercent (Int64 filesize,int64 processsize) {m_percent= (float) processsize/filesize;} void Compress (String inpath,string outpath) {SevenZip.Compression.LZMA.Encoder encoder=new SevenZip.Compression.LZMA.Encoder (); FileStream inputfs=new FileStream (Inpath,filemode.open); FileStream outputfs=new FileStream (outpath,filemode.create); encoder. Writecoderproperties (OUTPUTFS); Outputfs.write (System.BitConverter.GetBytes (inputfs.length), 0,8); encoder. Code (inputfs,outputfs,inputfs.length,-1,m_codeprogress); Outputfs.flush (); Outputfs.close (); InputFS.Close ();} void Decompress (String inpath,string outpath) {SevenZip.Compression.LZMA.Decoder decoder=new SevenZip.Compression.LZMA.Decoder (); FileStream INPUtfs=new FileStream (Inpath,filemode.open); FileStream outputfs=new FileStream (outpath,filemode.create); int propertiessize= Sevenzip.compression.lzma.encoder.kpropsize;byte[] Properties=new Byte[propertiessize];inputfs.read (properties,0 , properties. Length); byte[] Filelengthbytes=new byte[8];inputfs.read (filelengthbytes,0,8); Long filelength= System.BitConverter.ToInt64 (filelengthbytes,0);d Ecoder. Setdecoderproperties (properties);d Ecoder. Code (inputfs,outputfs,inputfs.length,filelength,m_codeprogress); Outputfs.flush (); Outputfs.close (); Inputfs.close ();}} Class Codeprogress:icodeprogress{public delegate void Progressdelegate (Int64 filesize,int64 processsize);p ublic Progressdelegate m_progressdelegate=null;public codeprogress (Progressdelegate del) {M_progressdelegate=del;} public void Setprogress (Int64 insize, Int64 outsize) {}public void setprogresspercent (Int64 filesize,int64 processsize) { M_progressdelegate (filesize,processsize);}}
transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Sample Project Download:
Baidu Network Disk
Link: Http://pan.baidu.com/s/1jGlEDPO Password: wure
CSDN Download
About UPK Packaging
Unity3d Game Resources Package encryption (picture/xml/txt, etc.) C # encoding (i)
LZMA C # SDK Sub-threading compression and decompression Unity3d instance