using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using System.IO;

[ScriptedImporter(1, "script")]
public class ScriptImporter : ScriptedImporter
{
	public override void OnImportAsset(AssetImportContext ctx) {
		ScriptData script = ScriptableObject.CreateInstance<ScriptData>();

		string text = File.ReadAllText(ctx.assetPath);

		try {
			ScriptCompiler compiler = new ScriptCompiler(script, text, ctx.assetPath);
		} catch (ScriptCompiler.ParserException e) {
			ctx.LogImportError(e.Message);
			return;
		}

		ctx.AddObjectToAsset("Script", script);
		ctx.SetMainObject(script);
	}
}
