x


detect when a textasset has changed

I am sure it's documented or been asked already, but I just can't find the right set of keyword to find the answer...

basically, I have a testAsset, an xml file, that I parse with a script. the scripts now runs in edit Mode.

I'd like to detect automatically that the xml file has changed and re parse it, instead of have to have a custom inspector with a button to trigger the parsing.

basically, how can I be notified in my script ( or in the custom inspector script), that an sset has changed?

thanks in advance.

Jean

more ▼

asked Feb 16 '12 at 06:05 PM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 75 103

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

I know that I'm kind of doing some Necromancy here, but I was looking for the solution to this problem and thought it would be nice to document the solution that I found here for any further searchers.

From the documentation at [AssetPostprocessor.OnPostprocessAllAssets][1] I have my C# script:

public class DetectChanges : AssetPostprocessor  
{

    static void OnPostprocessAllAssets (
        string[] importedAssets,
        string[] deletedAssets,
        string[] movedAssets,
        string[] movedFromAssetPaths) 
    {       
       foreach (string str in importedAssets)
       {
            Debug.Log("Reimported Asset: " + str);
         string[] splitStr = str.Split('/', '.');

         string folder = splitStr[splitStr.Length-3];
         string fileName = splitStr[splitStr.Length-2];
         string extension = splitStr[splitStr.Length-1];
         Debug.Log("File name: " + fileName);
         Debug.Log("File type: " + extension);             
       }

        foreach (string str in deletedAssets)
            Debug.Log("Deleted Asset: " + str);

        for (int i=0;i<movedAssets.Length;i++)
            Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);     
    }
}

This helped my issue where I needed to know the Folder, filename, and the file extension of every file that is changed. Keep in mind that in order to use AssetPostprocessor you must include: using UnityEditor; [1]: http://docs.unity3d.com/Documentation/ScriptReference/AssetPostprocessor.OnPostprocessAllAssets.html

more ▼

answered Oct 09 '12 at 10:42 PM

Muuskii gravatar image

Muuskii
1.1k 4 10

Excellent, thanks, Thank you for posting even tho after such a long time. this is the spirit :)

Oct 09 '12 at 11:27 PM Jean Fabre
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x419
x380
x28

asked: Feb 16 '12 at 06:05 PM

Seen: 671 times

Last Updated: Oct 09 '12 at 11:27 PM