Get the MD5 value from the unity resource to prepare for the resource update configuration file

Source: Internet
Author: User

As we said earlier, how do we get the Assetbundle importer property of the resource that needs to be packaged and the simple one-click Package, if the resources are updated?

In Unity, the editor assigns a MD5 value to each of our resources, which is unique, and if our resources change, then this MD5 value will also be there, which is beyond doubt;

In this way, we can get the MD5 value of the resource, which is better than the MD5 value of the local resource and the latest MD5 value, so that we know whether to update the resource

Under the Unityeditor namespace, there is a way to get this unique value assetdatabase.assetpathtoguid (path);

So let's do an experiment. We select an object, then get his path, and get the MD5 value by the path.

[MenuItem ("tools/get GUID")]      Public Static void Getassetsguid ()    {        = selection.activeobject;         string Path = Assetdatabase.getassetpath (obj);        Debug.Log (path);         string str=  assetdatabase.assetpathtoguid (path);        Debug.Log (str);    }

From the output you can see that I've got the required MD5 value

But this is too troublesome, need to go to manually set up, really is the mood of the dog has been beep, we still say with the previous set importer, through IO operation, to find, and get

[MenuItem ("tools/Setting the GUID")]     Public Static voidSetassetguid () {Checkassetbundledir (Getassetbundlestringpath ()); }     Public Static stringGetassetbundlestringpath ()//get the file path that holds the packaged resource    {        stringPath =Application.streamingassetspath; //Debug.Log (path);        string[] STRs = path. Split ('/'); intIDX =0;  for(inti =0; I < STRs. Length; i++)        {            if(Strs[i] = ="Assets") IDX=i; }        //Debug.Log (IDX); //Path = Strs[strs. Length-2] + "/" + strs[strs. LENGTH-1];        stringstr ="";  for(inti = idx; I < STRs. Length; i++)        {            if(I! = STRs. Length-1) Str+ = Strs[i] +"/"; Else if(i = = STRs. Length-1) Str+=Strs[i]; //Debug.Log (i);} path=str; returnpath; //Debug.Log (path);    }     Public Static voidCheckassetbundledir (stringPath//is the file, continue down{DirectoryInfo directory=NewDirectoryInfo (@path); Filesysteminfo[] Filesysteminfos=directory.        Getfilesysteminfos (); foreach(varIteminchFilesysteminfos) {            //Debug.Log (item);            intIDX = Item. ToString (). LastIndexOf (@"\"); stringName = Item. ToString (). Substring (idx +1); if(!name. Contains (". Meta") {checkassetbundlefileordirectory (item, Path+"/"+ name);//item file system, plus relative path            }        }    }     Public Static voidCheckassetbundlefileordirectory (FileSystemInfo FileSystemInfo,stringPath//decide if it's a file or a folder{FileInfo FileInfo= FileSystemInfo asFileInfo; if(FileInfo! =NULL)        {            //Debug.Log (path);Debug.Log ("not empty ==>>"+getguid (path)); }        Else        {            //Debug.Log ("Empty");        }    }     Public Static stringGetGuid (stringpath) {        returnassetdatabase.assetpathtoguid (path); }

Here we have the same print, we can get the MD5 value of the packaged resources under the parent directory, next we are going to go through a layer of search, get all, next time goodbye

Get the MD5 value from the unity resource to prepare for the resource update configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.