Skip to content

Instantly share code, notes, and snippets.

@fabSchneider
Created February 10, 2022 10:36
Show Gist options
  • Save fabSchneider/2aab06bd3b34e50a2c085a9660ae9550 to your computer and use it in GitHub Desktop.
Save fabSchneider/2aab06bd3b34e50a2c085a9660ae9550 to your computer and use it in GitHub Desktop.
This scripted importer will allow to import files with .lua extension as text assets into Unity.
using System.IO;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
/// <summary>
/// Scripted importer for files with .lua extension.
/// Will create a text asset from the lua script
/// </summary>
[ScriptedImporter(1, "lua")]
public class LuaScriptImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
TextAsset textAsset = new TextAsset(File.ReadAllText(ctx.assetPath));
ctx.AddObjectToAsset("lua script", textAsset);
ctx.SetMainObject(textAsset);
}
}
[CustomEditor(typeof(LuaScriptImporter))]
internal class LuaScriptImporterEditor : AssetImporterEditor
{
protected override bool needsApplyRevert => false;
public override void OnInspectorGUI(){ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment