Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

恢复简化版的 LuaAsset #1184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Assets/XLua/Src/Editor/LuaImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if UNITY_2018_1_OR_NEWER
using UnityEngine;
using UnityEditor;

using System.IO;

#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
using UnityEditor.Experimental.AssetImporters;
#endif

namespace XLua
{
[ScriptedImporter(2, new[] { "lua" })]
public class LuaImporter : ScriptedImporter
{
private const string IconGUID = "0eb86212f60529a4b9e9deeeebde247c";

const string Tag = "LuaImporter";

public override void OnImportAsset(AssetImportContext ctx)
{
var id = AssetDatabase.AssetPathToGUID(ctx.assetPath);
var asset = LuaAsset.Create(File.ReadAllText(ctx.assetPath));
ctx.AddObjectToAsset("LuaCode", asset, LoadIconTexture(), id);
ctx.SetMainObject(asset);
}

private static Texture2D LoadIconTexture()
{
return AssetDatabase.LoadAssetAtPath(
AssetDatabase.GUIDToAssetPath(IconGUID),
typeof(Texture2D)
) as Texture2D;
}
}
}

#endif
3 changes: 3 additions & 0 deletions Assets/XLua/Src/Editor/LuaImporter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/XLua/Src/Editor/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions Assets/XLua/Src/Editor/logo.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Assets/XLua/Src/LuaAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using UnityEngine;

namespace XLua
{
public partial class LuaAsset : ScriptableObject
{
[SerializeField]
private string Guid;

[SerializeField, HideInInspector]
private string _code;

public string Code => _code;

/**
* 保留 “text” 属性兼容以往 TextAsset 的写法
* Retain the 'text' property for compatibility with the previous TextAsset usage.
**/
public string text => Code;

public override string ToString() => Code;

public static LuaAsset Create(string code, string guid)
{
var asset = CreateInstance<LuaAsset>();
asset._code = code;
asset.Guid = guid;
return asset;
}

// In the future, we may be able to add other extended features here.
}
}
3 changes: 3 additions & 0 deletions Assets/XLua/Src/LuaAsset.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.