Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid two files in project view when creating a custom importer in Unity3D?

Tags:

unity3d

assets

NOTE: I'm casting a wider net than Unity Answers, my original question can be found here.

I've created a ProTools CueSheet importer. It uses OnPostprocessAllAssets() to detect a files in the project that have a .cuesheet extension. It then runs those cuesheet files through my parser. This generates a ScriptableObject which is then turned into an asset via Database.CreateAsset().

The problem is, this leaves me with two files, the original cuesheet and the newly generated asset. Is there any way I can generate the asset in such as way that the original cuesheet acts as the asset, the same way textures or FBX files do?

public class CueSheetPostProcessor : AssetPostprocessor {
    static string extension = ".cuesheet";

    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
        foreach (string assetPath in importedAssets) {
            if (assetPath.EndsWith(extension, StringComparison.OrdinalIgnoreCase)) {
                string newPath = assetPath + ".asset";
                Session session = CueImporter.Load(assetPath);
                AssetDatabase.CreateAsset(session, newPath);
                AssetDatabase.SaveAssets();
            }
        }
    }
}
like image 985
Soviut Avatar asked Apr 27 '15 04:04

Soviut


1 Answers

I would create a PropertyDrawer for the Serializable class CueSheet such that it accepts the .cueSheet TextAsset or path to the .cueSheet file and create an instance of the class CueSheet and assign it or modify it.

like image 81
Sri Krishna Paritala Avatar answered Nov 05 '22 14:11

Sri Krishna Paritala