update handling of Lua assets

This commit is contained in:
aliaksei.kalosha
2025-04-12 18:16:57 +02:00
parent a07a715d19
commit ecb1422937
15 changed files with 930 additions and 18 deletions

View File

@@ -5,11 +5,11 @@ using UnityEngine;
[CustomEditor(typeof(LuaFile))]
public class LuaScriptAssetEditor : Editor
{
private TextAsset asset;
public override void OnInspectorGUI()
{
LuaFile luaScriptAsset = (LuaFile)target;
// Allow user to drag-and-drop the Lua file
luaScriptAsset.luaScript = (TextAsset)EditorGUILayout.ObjectField("Lua Script", luaScriptAsset.luaScript, typeof(TextAsset), false);
EditorGUILayout.TextArea(luaScriptAsset.LuaScript);
}
}

View File

@@ -1,6 +1,8 @@
using UnityEngine;
using System.IO;
using UnityEditor;
using UnityEditor.AssetImporters;
using Splashedit.RuntimeCode;
namespace SplashEdit.EditorCode
{
@@ -9,9 +11,15 @@ namespace SplashEdit.EditorCode
{
public override void OnImportAsset(AssetImportContext ctx)
{
var asset = new TextAsset(File.ReadAllText(ctx.assetPath));
ctx.AddObjectToAsset("Text", asset);
ctx.SetMainObject(asset);
var asset = ScriptableObject.CreateInstance<LuaFile>();
var luaCode = File.ReadAllText(ctx.assetPath);
asset.Init(luaCode);
asset.name = Path.GetFileName(ctx.assetPath);
var text = new TextAsset(asset.LuaScript);
ctx.AddObjectToAsset("Text", text);
ctx.AddObjectToAsset("Script", asset);
ctx.SetMainObject(text);
}
}
}