Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created April 7, 2024 08:15
Show Gist options
  • Save unitycoder/b721535b8a568d5f3e6525cb9350b4a9 to your computer and use it in GitHub Desktop.
Save unitycoder/b721535b8a568d5f3e6525cb9350b4a9 to your computer and use it in GitHub Desktop.
import non .txt file as TextAsset with OnImportAsset
// https://forum.unity.com/threads/tsv-file-as-textassets.495244/#post-9754270
using System.IO;
using UnityEditor;
 
using UnityEngine;
 
[UnityEditor.AssetImporters.ScriptedImporter(1, "tsv")]
public class TSVImporter : UnityEditor.AssetImporters.ScriptedImporter
{
    public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx)
    {
        TextAsset textAsset = new TextAsset(File.ReadAllText(ctx.assetPath));
        ctx.AddObjectToAsset(Path.GetFileNameWithoutExtension(ctx.assetPath), textAsset);
        ctx.SetMainObject(textAsset);
        AssetDatabase.SaveAssets();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment