Skip to content

Commit 137c76d

Browse files
authored
Merge pull request #57 from AnnulusGames/lua-unity
Add: Lua.Unity package
2 parents 3fa08d6 + d79deba commit 137c76d

File tree

59 files changed

+6408
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+6408
-20
lines changed

README.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ Install-Package LuaCSharp
4848

4949
### Unity
5050

51-
Lua-CSharp can also be used in Unity (works with both Mono and IL2CPP).
52-
53-
### Requirements
54-
55-
* Unity 2021.3 or higher
56-
57-
### Installation
58-
59-
1. Install [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity).
60-
2. Open the NuGet window by going to `NuGet > Manage NuGet Packages`, search for the `LuaCSharp` package, and install it.
51+
You can also use Lua-CSharp with Unity. For details, see the [Lua.Unity](#luaunity) section.
6152

6253
## Quick Start
6354

@@ -487,6 +478,51 @@ catch (LuaRuntimeException)
487478
}
488479
```
489480

481+
## Lua.Unity
482+
483+
Lua-CSharp can also be used in Unity (works with both Mono and IL2CPP).
484+
485+
### Requirements
486+
487+
* Unity 2021.3 or higher
488+
489+
### Installation
490+
491+
1. Install [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity).
492+
493+
2. Open the NuGet window by going to `NuGet > Manage NuGet Packages`, search for the `LuaCSharp` package, and install it.
494+
495+
3. Open the Package Manager window by selecting `Window > Package Manager`, then click on `[+] > Add package from git URL` and enter the following URL:
496+
497+
```
498+
https://github.com/AnnulusGames/Lua-CSharp.git?path=src/Lua.Unity/Assets/Lua.Unity
499+
```
500+
501+
### LuaImporter / LuaAsset
502+
503+
By introducing Lua.Unity, files with the `.lua` extension can be treated as `LuaAsset`.
504+
505+
![img](docs/img-lua-importer.png)
506+
507+
These assets can be used similarly to a standard `TextAsset`.
508+
509+
```cs
510+
var asset = Resources.Load<LuaAsset>("example");
511+
await state.DoStringAsync(asset.Text, ct);
512+
```
513+
514+
### Resources(Addressables)ModuleLoader
515+
516+
Implementations of `ILuaModuleLoader` that utilize either Resources or Addressables internally are also provided.
517+
518+
```cs
519+
// Use Resources for module loading
520+
state.ModuleLoader = new ResourcesModuleLoader();
521+
522+
// Use Addressables for module loading (requires the Addressables package)
523+
state.ModuleLoader = new AddressablesModuleLoader();
524+
```
525+
490526
## Compatibility
491527

492528
Lua-CSharp is designed with integration into .NET in mind, so there are several differences from the C implementation.

README_JA.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ Install-Package LuaCSharp
4848

4949
### Unity
5050

51-
Lua-CSharpをUnityで利用することも可能です。(Mono/IL2CPPの両方で動作します)
52-
53-
### 要件
54-
55-
* Unity 2021.3 以上
56-
57-
### インストール
58-
59-
1. [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)をインストールします。
60-
2. `NuGet > Manage NuGet Packages`からNuGetウィンドウを開き、`LuaCSharp`パッケージを検索してインストールします。
51+
Lua-CSharpをUnityで利用することも可能です。詳細は[Lua.Unity](#luaunity)の項目を参照してください。
6152

6253
## クイックスタート
6354

@@ -487,6 +478,51 @@ catch (LuaRuntimeException)
487478
}
488479
```
489480

481+
## Lua.Unity
482+
483+
Lua-CSharpはUnityで利用することも可能です。(Mono/IL2CPPの両方で動作します)
484+
また、Lua-CSharpをUnityと統合するための`Lua.Unity`拡張パッケージも提供されています。
485+
486+
### 要件
487+
488+
* Unity 2021.3 以上
489+
490+
### インストール
491+
492+
1. [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)をインストールします。
493+
494+
2. `NuGet > Manage NuGet Packages`からNuGetウィンドウを開き、`LuaCSharp`パッケージを検索してインストールします。
495+
496+
3. `Window > Package Manager`からPackage Managerウィンドウを開き、`[+] > Add package from git URL`から以下のURLを入力します。
497+
```
498+
https://github.com/AnnulusGames/Lua-CSharp.git?path=src/Lua.Unity/Assets/Lua.Unity
499+
```
500+
501+
### LuaImporter / LuaAsset
502+
503+
Lua.Unityを導入することで、`.lua`拡張子のファイルを`LuaAsset`として扱えるようになります。
504+
505+
![img](docs/img-lua-importer.png)
506+
507+
これは通常の`TextAsset`のように利用することが可能です。
508+
509+
```cs
510+
var asset = Resources.Load<LuaAsset>("example");
511+
await state.DoStringAsync(asset.Text, ct);
512+
```
513+
514+
### Resources(Addressables)ModuleLoader
515+
516+
また、内部でResourcesまたはAddressablesを利用する`ILuaModuleLoader`の実装が用意されています。
517+
518+
```cs
519+
// モジュールの読み込みにResourcesを利用する
520+
state.ModuleLoader = new ResourcesModuleLoader();
521+
522+
// モジュールの読み込みにAddressablesを利用する (Addressablesパッケージが必要)
523+
state.ModuleLoader = new AddressablesModuleLoader();
524+
```
525+
490526
## 互換性
491527

492528
Lua-CSharpは.NETとの統合を念頭に設計されているため、C実装とは互換性がない仕様がいくつか存在します。

docs/img-lua-importer.png

92 KB
Loading

src/Lua.Unity/.gitignore

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# This .gitignore file should be placed at the root of your Unity project directory
2+
#
3+
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
4+
#
5+
/[Ll]ibrary/
6+
/[Tt]emp/
7+
/[Oo]bj/
8+
/[Bb]uild/
9+
/[Bb]uilds/
10+
/[Ll]ogs/
11+
/[Uu]ser[Ss]ettings/
12+
13+
# MemoryCaptures can get excessive in size.
14+
# They also could contain extremely sensitive data
15+
/[Mm]emoryCaptures/
16+
17+
# Recordings can get excessive in size
18+
/[Rr]ecordings/
19+
20+
# Uncomment this line if you wish to ignore the asset store tools plugin
21+
/[Aa]ssets/AssetStoreTools*
22+
/[Pp]ackages/com.unity.asset-store-tools*
23+
24+
# Autogenerated Jetbrains Rider plugin
25+
/[Aa]ssets/Plugins/Editor/JetBrains*
26+
27+
# Visual Studio cache directory
28+
.vs/
29+
30+
# Visual Studio Code cache directory
31+
.vscode/
32+
33+
# Gradle cache directory
34+
.gradle/
35+
36+
# Autogenerated VS/MD/Consulo solution and project files
37+
ExportedObj/
38+
.consulo/
39+
*.csproj
40+
*.unityproj
41+
*.sln
42+
*.suo
43+
*.tmp
44+
*.user
45+
*.userprefs
46+
*.pidb
47+
*.booproj
48+
*.svd
49+
*.pdb
50+
*.mdb
51+
*.opendb
52+
*.VC.db
53+
54+
# Unity3D generated meta files
55+
*.pidb.meta
56+
*.pdb.meta
57+
*.mdb.meta
58+
59+
# Unity3D generated file on crash reports
60+
sysinfo.txt
61+
62+
# Builds
63+
*.apk
64+
*.aab
65+
*.unitypackage
66+
*.app
67+
68+
# Crashlytics generated file
69+
crashlytics-build.properties
70+
71+
# Packed Addressables
72+
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
73+
74+
# Temporary auto-generated Android Assets
75+
/[Aa]ssets/[Ss]treamingAssets/aa.meta
76+
/[Aa]ssets/[Ss]treamingAssets/aa/*
77+
78+
# DS_Store
79+
*.DS_Store
80+
81+
# TextMesh Pro
82+
/[Aa]ssets/TextMesh Pro/
83+
/[Aa]ssets/TextMesh Pro.meta
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 468a46d0ae32c3544b7d98094e6448a9, type: 3}
13+
m_Name: AddressableAssetSettings
14+
m_EditorClassIdentifier:
15+
m_DefaultGroup: 2a0e06d9ccf214f8fa1ca5d1510af7d2
16+
m_currentHash:
17+
serializedVersion: 2
18+
Hash: 00000000000000000000000000000000
19+
m_OptimizeCatalogSize: 0
20+
m_BuildRemoteCatalog: 0
21+
m_CatalogRequestsTimeout: 0
22+
m_DisableCatalogUpdateOnStart: 0
23+
m_InternalIdNamingMode: 0
24+
m_InternalBundleIdMode: 1
25+
m_AssetLoadMode: 0
26+
m_BundledAssetProviderType:
27+
m_AssemblyName:
28+
m_ClassName:
29+
m_AssetBundleProviderType:
30+
m_AssemblyName:
31+
m_ClassName:
32+
m_IgnoreUnsupportedFilesInBuild: 0
33+
m_UniqueBundleIds: 0
34+
m_EnableJsonCatalog: 0
35+
m_NonRecursiveBuilding: 1
36+
m_CCDEnabled: 0
37+
m_maxConcurrentWebRequests: 3
38+
m_UseUWRForLocalBundles: 0
39+
m_BundleTimeout: 0
40+
m_BundleRetryCount: 0
41+
m_BundleRedirectLimit: -1
42+
m_SharedBundleSettings: 0
43+
m_SharedBundleSettingsCustomGroupIndex: 0
44+
m_ContiguousBundles: 1
45+
m_StripUnityVersionFromBundleBuild: 0
46+
m_DisableVisibleSubAssetRepresentations: 0
47+
m_BuiltInBundleNaming: 0
48+
mBuiltInBundleCustomNaming:
49+
m_MonoScriptBundleNaming: 0
50+
m_CheckForContentUpdateRestrictionsOption: 0
51+
m_MonoScriptBundleCustomNaming:
52+
m_RemoteCatalogBuildPath:
53+
m_Id:
54+
m_RemoteCatalogLoadPath:
55+
m_Id:
56+
m_ContentStateBuildPathProfileVariableName:
57+
m_CustomContentStateBuildPath:
58+
m_ContentStateBuildPath:
59+
m_BuildAddressablesWithPlayerBuild: 0
60+
m_overridePlayerVersion: '[UnityEditor.PlayerSettings.bundleVersion]'
61+
m_GroupAssets:
62+
- {fileID: 11400000, guid: 30f1ec4a0d3c9473d9b32a1b02474847, type: 2}
63+
m_BuildSettings:
64+
m_LogResourceManagerExceptions: 1
65+
m_BundleBuildPath: Temp/com.unity.addressables/AssetBundles
66+
m_ProfileSettings:
67+
m_Profiles:
68+
- m_InheritedParent:
69+
m_Id: 1d0a56529a3514cf1aebb59dc61a2305
70+
m_ProfileName: Default
71+
m_Values:
72+
- m_Id: 3d2c4246f2d9c4355b5acd8b3a19e557
73+
m_Value: 'ServerData/[BuildTarget]'
74+
- m_Id: 717ab8aa570a245ef8065628c9ff1501
75+
m_Value: <undefined>
76+
- m_Id: 7deb6bdcfd7e148bd8e411f164e168ad
77+
m_Value: '{UnityEngine.AddressableAssets.Addressables.RuntimePath}/[BuildTarget]'
78+
- m_Id: c649b540d1bf94a80844c4472c08a22b
79+
m_Value: '[UnityEditor.EditorUserBuildSettings.activeBuildTarget]'
80+
- m_Id: e169f91311e984e908fcdcff8215d9b9
81+
m_Value: '[UnityEngine.AddressableAssets.Addressables.BuildPath]/[BuildTarget]'
82+
m_ProfileEntryNames:
83+
- m_Id: 3d2c4246f2d9c4355b5acd8b3a19e557
84+
m_Name: Remote.BuildPath
85+
m_InlineUsage: 0
86+
- m_Id: 717ab8aa570a245ef8065628c9ff1501
87+
m_Name: Remote.LoadPath
88+
m_InlineUsage: 0
89+
- m_Id: 7deb6bdcfd7e148bd8e411f164e168ad
90+
m_Name: Local.LoadPath
91+
m_InlineUsage: 0
92+
- m_Id: c649b540d1bf94a80844c4472c08a22b
93+
m_Name: BuildTarget
94+
m_InlineUsage: 0
95+
- m_Id: e169f91311e984e908fcdcff8215d9b9
96+
m_Name: Local.BuildPath
97+
m_InlineUsage: 0
98+
m_ProfileVersion: 1
99+
m_LabelTable:
100+
m_LabelNames:
101+
- default
102+
m_SchemaTemplates: []
103+
m_GroupTemplateObjects:
104+
- {fileID: 11400000, guid: faa35a57f036243239643631bf4ab68d, type: 2}
105+
m_InitializationObjects: []
106+
m_CertificateHandlerType:
107+
m_AssemblyName:
108+
m_ClassName:
109+
m_ActivePlayerDataBuilderIndex: 2
110+
m_DataBuilders:
111+
- {fileID: 11400000, guid: d6921a29df7234327863bccd63d917f6, type: 2}
112+
- {fileID: 11400000, guid: 703d4c54c8176478e87c027f44a5424e, type: 2}
113+
- {fileID: 11400000, guid: 276c7bc6c400449ed930dde9a70d1e70, type: 2}
114+
m_ActiveProfileId: 1d0a56529a3514cf1aebb59dc61a2305

0 commit comments

Comments
 (0)