Skip to content

Instantly share code, notes, and snippets.

Last active Aug 21, 2019
What would you like to do?
Import files with the extensions you specify as text assets in Unity 3D.
/* Original code[1] Copyright (c) 2019 Shane Celis[2]
Licensed under the MIT License[3]
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using System.IO;
/** Do you want to import your own text files? Sure, we all do!
Unity natively supports text extensions: txt, html, htm, xml, bytes, json
csv, yaml, and fnt. These are imported as text assets.
This TextImporter script imports files with the extensions you specify
as text assets.
[ScriptedImporter(0 /* Version number. Increment when script is changed. */,
new [] { "text", "markdown" } /* Filename extensions */)]
public class TextImporter : ScriptedImporter {
public override void OnImportAsset(AssetImportContext ctx) {
var asset = new TextAsset(File.ReadAllText(ctx.assetPath));
ctx.AddObjectToAsset("Main Object" /* This name won't be shown. The filename
will be shown for the main asset. */,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment