Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 468a46d0ae32c3544b7d98094e6448a9, type: 3}
m_Name: AddressableAssetSettings
m_EditorClassIdentifier:
m_DefaultGroup: 2a0e06d9ccf214f8fa1ca5d1510af7d2
m_DefaultGroup: d88070ff273c67a47aa61b1ac322925e
m_currentHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
Hash: 0541ae50fa90e8e78e8bf32544e171fd
m_OptimizeCatalogSize: 0
m_BuildRemoteCatalog: 0
m_CatalogRequestsTimeout: 0
Expand All @@ -24,11 +24,11 @@ MonoBehaviour:
m_InternalBundleIdMode: 1
m_AssetLoadMode: 0
m_BundledAssetProviderType:
m_AssemblyName:
m_ClassName:
m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider
m_AssetBundleProviderType:
m_AssemblyName:
m_ClassName:
m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider
m_IgnoreUnsupportedFilesInBuild: 0
m_UniqueBundleIds: 0
m_EnableJsonCatalog: 0
Expand Down Expand Up @@ -60,6 +60,7 @@ MonoBehaviour:
m_overridePlayerVersion: '[UnityEditor.PlayerSettings.bundleVersion]'
m_GroupAssets:
- {fileID: 11400000, guid: 30f1ec4a0d3c9473d9b32a1b02474847, type: 2}
- {fileID: 11400000, guid: 1561a30b342064fa4896f0bfbf686fcb, type: 2}
m_BuildSettings:
m_LogResourceManagerExceptions: 1
m_BundleBuildPath: Temp/com.unity.addressables/AssetBundles
Expand Down Expand Up @@ -108,7 +109,7 @@ MonoBehaviour:
m_ClassName:
m_ActivePlayerDataBuilderIndex: 2
m_DataBuilders:
- {fileID: 11400000, guid: d6921a29df7234327863bccd63d917f6, type: 2}
- {fileID: 11400000, guid: 703d4c54c8176478e87c027f44a5424e, type: 2}
- {fileID: 11400000, guid: 276c7bc6c400449ed930dde9a70d1e70, type: 2}
- {fileID: 11400000, guid: 0618f16a59fed47c1933ae8dde25092a, type: 2}
- {fileID: 11400000, guid: e4575ed4ef1a746ccb1d0fba41ecd093, type: 2}
- {fileID: 11400000, guid: 5f12744ea547f4fe8b261b427250778b, type: 2}
m_ActiveProfileId: 1d0a56529a3514cf1aebb59dc61a2305
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ MonoBehaviour:
m_Name: Default Local Group
m_EditorClassIdentifier:
m_GroupName: Default Local Group
m_GUID: 2a0e06d9ccf214f8fa1ca5d1510af7d2
m_GUID: d88070ff273c67a47aa61b1ac322925e
m_SerializeEntries:
- m_GUID: c611eb631438746b991def52ebe74776
- m_GUID: 16a50852a63da4d0d9221dcb9b74c48c
m_Address: bar
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
m_ReadOnly: 0
m_Settings: {fileID: 11400000, guid: f1d773be05107486d85b5a324c1c2fb0, type: 2}
m_Settings: {fileID: 11400000, guid: a0f4200005a8343fa9cfda7e23be8a93, type: 2}
m_SchemaSet:
m_Schemas:
- {fileID: 11400000, guid: 1476390b038364f2f800595d61171b27, type: 2}
- {fileID: 11400000, guid: 7ebbf8a9fd56642d283eb1ef4c8ccf85, type: 2}
- {fileID: 11400000, guid: a90139adc8865497d8309c82638492b0, type: 2}
- {fileID: 11400000, guid: f83e7898558224636ac47d66c1d5f91d, type: 2}

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e5d17a21594effb4e9591490b009e7aa, type: 3}
m_Name: Default Local Group_BundledAssetGroupSchema
m_EditorClassIdentifier:
m_Group: {fileID: 11400000, guid: 30f1ec4a0d3c9473d9b32a1b02474847, type: 2}
m_Group: {fileID: 11400000, guid: 1561a30b342064fa4896f0bfbf686fcb, type: 2}
m_InternalBundleIdMode: 1
m_Compression: 1
m_IncludeAddressInCatalog: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5834b5087d578d24c926ce20cd31e6d6, type: 3}
m_Name: Default Local Group_ContentUpdateGroupSchema
m_EditorClassIdentifier:
m_Group: {fileID: 11400000, guid: 30f1ec4a0d3c9473d9b32a1b02474847, type: 2}
m_Group: {fileID: 11400000, guid: 1561a30b342064fa4896f0bfbf686fcb, type: 2}
m_StaticContent: 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3a189bb168d8d90478a09ea08c2f3d72, type: 3}
m_Name: DefaultObject
m_EditorClassIdentifier:
m_AddressableAssetSettingsGuid: f1d773be05107486d85b5a324c1c2fb0
m_AddressableAssetSettingsGuid: a0f4200005a8343fa9cfda7e23be8a93

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

98 changes: 98 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Editor/LuacAssetEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Lua.CodeAnalysis.Compilation;
using Lua.Runtime;
using System;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;

namespace Lua.Unity.Editor
{
[CustomEditor(typeof(LuacAsset))]
public sealed class LuacAssetEditor : UnityEditor.Editor
{
LuacAsset asset;
static StringBuilder sb = new StringBuilder();
private byte[] bytes;
string prototypeCacheString;

public override void OnInspectorGUI()
{
if (asset == null) asset = (LuacAsset)serializedObject.targetObject;
if (bytes == null || !asset.bytes.AsSpan().SequenceEqual(bytes))
{
var prototype = LuaCompiler.UnDump(asset.bytes.AsSpan(), asset.name);
if (sb == null)
sb = new StringBuilder();
sb.Clear();
DebugChunk(sb, prototype, 0, 0);
prototypeCacheString = sb.ToString();
bytes = asset.bytes;
}

using (new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.TextArea(prototypeCacheString);
}
}

static void DebugChunk(StringBuilder builder, Prototype chunk, int nestCount, int id)
{
void AppendLine(string line)
{
for (int i = 0; i < nestCount; i++)
{
builder.Append(" ");
}

builder.AppendLine(line);
}

if (nestCount == 0)
AppendLine($"Chunk :{chunk.ChunkName}");
else AppendLine("[" + nestCount + "," + id + "]");
AppendLine($"Parameters:{chunk.ParameterCount}");

AppendLine("Code -------------------------------------");
var index = 0;
foreach (var inst in chunk.Code)
{
AppendLine($"[{index}]\t{chunk.LineInfo[index]}\t\t{inst}");
index++;
}

AppendLine("LocalVariables ---------------------------");
index = 0;
foreach (var local in chunk.LocalVariables)
{
AppendLine($"[{index}]\t{local.Name}\t{local.StartPc}\t{local.EndPc}");
index++;
}

AppendLine("Constants ---------------------------------");
index = 0;
foreach (var constant in chunk.Constants.ToArray())
{
AppendLine($"[{index}]\t{Regex.Escape(constant.ToString())}");
index++;
}

AppendLine("UpValues -----------------------------------");
index = 0;
foreach (var upValue in chunk.UpValues.ToArray())
{
AppendLine($"[{index}]\t{upValue.Name}\t{(upValue.IsLocal ? 1 : 0)}\t{upValue.Index}");
index++;
}

builder.AppendLine();

var chunkId = 0;

foreach (var localChunk in chunk.ChildPrototypes)
{
DebugChunk(builder, localChunk, nestCount + 1, chunkId);
chunkId++;
}
}
}
}
3 changes: 3 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Editor/LuacAssetEditor.cs.meta

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

32 changes: 32 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Editor/LuacImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;

namespace Lua.Unity.Editor
{
[ScriptedImporter(1, "luac")]
public sealed class LuacImporter : ScriptedImporter
{
static Texture2D icon;
public override void OnImportAsset(AssetImportContext ctx)
{
var bytes = File.ReadAllBytes(ctx.assetPath);
var asset = ScriptableObject.CreateInstance<LuacAsset>();
if (icon == null)
{
icon = Resources.Load<Texture2D>("LuaAssetIcon");
if (icon == null)
{
Debug.LogWarning("LuaAssetIcon not found in Resources. Using default icon.");
icon = EditorGUIUtility.IconContent("ScriptableObject Icon").image as Texture2D;
}
}
EditorGUIUtility.SetIconForObject (asset,icon );
asset.bytes = bytes;
ctx.AddObjectToAsset("Main", asset);
ctx.SetMainObject(asset);
}
}
}
3 changes: 3 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Editor/LuacImporter.cs.meta

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

3 changes: 3 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Editor/Resources.meta

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Lua.Unity
{
public sealed class AddressablesModuleLoader : ILuaModuleLoader
{
readonly Dictionary<string, LuaAsset> cache = new();
readonly Dictionary<string, LuaAssetBase> cache = new();

public bool Exists(string moduleName)
{
Expand All @@ -26,7 +26,8 @@ public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken
{
if (cache.TryGetValue(moduleName, out var asset))
{
return new LuaModule(moduleName, asset.text);

return asset .GetModule( moduleName);
}

var asyncOperation = Addressables.LoadAssetAsync<LuaAsset>(moduleName);
Expand All @@ -38,7 +39,7 @@ public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken
}

cache.Add(moduleName, asset);
return new LuaModule(moduleName, asset.text);
return asset .GetModule( moduleName);
}
}
internal static class AsyncOperationHandleExtensions
Expand Down
7 changes: 6 additions & 1 deletion src/Lua.Unity/Assets/Lua.Unity/Runtime/LuaAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace Lua.Unity
{
public sealed class LuaAsset : ScriptableObject
public sealed class LuaAsset : LuaAssetBase
{
[SerializeField] internal string text;
public string Text => text;

public override LuaModule GetModule(string searchedName)
{
return new LuaModule(searchedName,text);
}
}
}
10 changes: 10 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Runtime/LuaAssetBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

namespace Lua.Unity
{

public abstract class LuaAssetBase : ScriptableObject
{
public abstract LuaModule GetModule(string searchedName);
}
}
3 changes: 3 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Runtime/LuaAssetBase.cs.meta

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

3 changes: 3 additions & 0 deletions src/Lua.Unity/Assets/Lua.Unity/Runtime/LuacAsset.cs.meta

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

12 changes: 6 additions & 6 deletions src/Lua.Unity/Assets/Lua.Unity/Runtime/ResourcesModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace Lua.Unity
{
public sealed class ResourcesModuleLoader : ILuaModuleLoader
{
readonly Dictionary<string, LuaAsset> cache = new();
readonly Dictionary<string, LuaAssetBase> cache = new();

public bool Exists(string moduleName)
{
Debug.Log(moduleName);
if (cache.TryGetValue(moduleName, out _)) return true;

var asset = Resources.Load<LuaAsset>(moduleName);
var asset = Resources.Load<LuaAssetBase>(moduleName);
if (asset == null) return false;

cache.Add(moduleName, asset);
Expand All @@ -26,7 +27,7 @@ public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken
{
if (cache.TryGetValue(moduleName, out var asset))
{
return new LuaModule(moduleName, asset.text);
return asset.GetModule(moduleName);
}

var request = Resources.LoadAsync<LuaAsset>(moduleName);
Expand All @@ -37,10 +38,9 @@ public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken
throw new LuaModuleNotFoundException(moduleName);
}

asset = (LuaAsset)request.asset;
asset = (LuaAssetBase)request.asset;
cache.Add(moduleName, asset);
return new LuaModule(moduleName, asset.text);
}
return asset.GetModule(moduleName); }
}

#if !UNITY_2023_1_OR_NEWER
Expand Down
Loading