Created
April 7, 2024 08:15
-
-
Save unitycoder/b721535b8a568d5f3e6525cb9350b4a9 to your computer and use it in GitHub Desktop.
import non .txt file as TextAsset with OnImportAsset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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