Created
February 10, 2022 10:36
-
-
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.
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
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