mirror of
https://github.com/focus-creative-games/luban_unity.git
synced 2025-11-12 09:35:56 +08:00
[init] 提交Luban v1.0.0版本
This commit is contained in:
parent
a2b72782b4
commit
aa41b56501
1
.gitignore
vendored
1
.gitignore
vendored
@ -73,7 +73,6 @@ StyleCopReport.xml
|
|||||||
*_p.c
|
*_p.c
|
||||||
*_h.h
|
*_h.h
|
||||||
*.ilk
|
*.ilk
|
||||||
*.meta
|
|
||||||
*.obj
|
*.obj
|
||||||
*.iobj
|
*.iobj
|
||||||
*.pch
|
*.pch
|
||||||
|
|||||||
8
Editor.meta
Normal file
8
Editor.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c335f426d24e88841a24ea17cb64aeef
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
28
Editor/EditorBeanBase.cs
Normal file
28
Editor/EditorBeanBase.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban
|
||||||
|
{
|
||||||
|
public abstract class EditorBeanBase
|
||||||
|
{
|
||||||
|
public abstract void LoadJson(SimpleJSON.JSONObject json);
|
||||||
|
|
||||||
|
public abstract void SaveJson(SimpleJSON.JSONObject json);
|
||||||
|
|
||||||
|
public void LoadJsonFile(string file)
|
||||||
|
{
|
||||||
|
string jsonText = System.IO.File.ReadAllText(file, Encoding.UTF8);
|
||||||
|
LoadJson((SimpleJSON.JSONObject)SimpleJSON.JSON.Parse(jsonText));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveJsonFile(string file)
|
||||||
|
{
|
||||||
|
var json = new SimpleJSON.JSONObject();
|
||||||
|
SaveJson(json);
|
||||||
|
System.IO.File.WriteAllText(file, json.ToString(), System.Text.Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Editor/EditorBeanBase.cs.meta
Normal file
11
Editor/EditorBeanBase.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f35aae35cabc2ae4bb742daf77aa8ee4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
27
Editor/EditorEnumItemInfo.cs
Normal file
27
Editor/EditorEnumItemInfo.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban
|
||||||
|
{
|
||||||
|
public class EditorEnumItemInfo
|
||||||
|
{
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
public string Alias { get; }
|
||||||
|
|
||||||
|
public int Value { get; }
|
||||||
|
|
||||||
|
public string Comment { get; }
|
||||||
|
|
||||||
|
public EditorEnumItemInfo(string name, string alias, int value, string comment)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Alias = alias;
|
||||||
|
Value = value;
|
||||||
|
Comment = comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Editor/EditorEnumItemInfo.cs.meta
Normal file
11
Editor/EditorEnumItemInfo.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 190bd966f7cc19240ba02ca2aed38f7e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
Editor/Luban.Editor.asmdef
Normal file
18
Editor/Luban.Editor.asmdef
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "Luban.Editor",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"Luban.Runtime"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": true,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
7
Editor/Luban.Editor.asmdef.meta
Normal file
7
Editor/Luban.Editor.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5796a4f593192714cbff2c4360722388
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
7
LICENSE.meta
Normal file
7
LICENSE.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 078e48d5b430a7d4db6745b56c27f8d5
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
250
README.md
Normal file
250
README.md
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
|
||||||
|
- [README 中文](./README_zh.md)
|
||||||
|
- [README English](./README.md)
|
||||||
|
|
||||||
|
# Luban
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[](https://opensource.org/licenses/MIT) 
|
||||||
|
|
||||||
|
|
||||||
|
luban is a powerful, easy-to-use, elegant, and stable game configuration solution. It is designed to meet the needs of simple to complex game configuration workflows from small to very large game projects.
|
||||||
|
|
||||||
|
luban can handle a variety of file types, supports mainstream languages, can generate multiple export formats, supports rich data inspection functions, has good cross-platform capabilities, and generates extremely fast.
|
||||||
|
Luban has a clear and elegant generation pipeline design, supports good modularization and plug-in, and is convenient for developers to carry out secondary development. Developers can easily adapt luban to their own configuration format, and customize powerful configuration tools that meet project requirements.
|
||||||
|
|
||||||
|
Luban standardizes the game configuration development workflow, which can greatly improve the efficiency of planning and programming.
|
||||||
|
|
||||||
|
## Core features
|
||||||
|
|
||||||
|
- Rich source data format. Support excel family (csv, xls, xlsx, xlsm), json, xml, yaml, lua, etc.
|
||||||
|
- Rich export formats. Support generating binary, json, bson, xml, lua, yaml and other format data
|
||||||
|
- Enhanced excel format. Simple configurations such as simple lists, substructures, structured lists, and arbitrarily complex deep nested structures can be concisely configured
|
||||||
|
- Complete type system. Not only can it express common specification line lists, but it can flexibly and elegantly express complex GamePlay data such as behavior trees, skills, plots, and dungeons because **supports OOP type inheritance**
|
||||||
|
- Support multiple languages. Supports generating language codes such as c#, java, go, cpp, lua, python, typescript, etc.
|
||||||
|
- Support mainstream message schemes. protobuf(schema + binary + json), flatbuffers(schema + json), msgpack(binary)
|
||||||
|
- Powerful data verification capability. ref reference check, path resource path, range range check, etc.
|
||||||
|
- Perfect localization support
|
||||||
|
- Supports all major game engines and platforms. Support Unity, Unreal, Cocos2x, Godot, WeChat games, etc.
|
||||||
|
- Good cross-platform capability. It can run well on Win, Linux, and Mac platforms.
|
||||||
|
- Support all mainstream hot update solutions. hybridclr, ilruntime, {x,t,s}lua, puerts, etc.
|
||||||
|
- Clear and elegant generation pipeline, it is easy to carry out secondary development on the basis of luban, and customize a configuration tool suitable for your own project style.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- [Official Documentation](https://luban.doc.code-philosophy.com/)
|
||||||
|
- [Quick Start](https://luban.doc.code-philosophy.com/docs/beginner/quickstart)
|
||||||
|
- **Example Project** ([github](https://github.com/focus-creative-games/luban_examples)) ([gitee](https://gitee.com/focus-creative-games/luban_examples) )
|
||||||
|
- Support and contact
|
||||||
|
- QQ group: 692890842 (Luban development exchange group)
|
||||||
|
- discord: https://discord.gg/dGY4zzGMJ4
|
||||||
|
- Email: luban@code-philosophy.com
|
||||||
|
|
||||||
|
## Excel format overview
|
||||||
|
|
||||||
|
basic data format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
enum data format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
bean data format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Polymorphic bean data format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
container
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
nullable type
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
no primary key table
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Multi-primary key table (joint index)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Multi-primary key table (independent index)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
singleton table
|
||||||
|
|
||||||
|
Some configurations have only one copy globally, such as the opening level of the guild module, the initial size of the backpack, and the upper limit of the backpack. At this time, it is more appropriate to use a singleton table to configure these data.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
vertical table
|
||||||
|
|
||||||
|
Most tables are horizontal tables, that is, one record per row. Some tables, such as singleton tables, are more comfortable to fill in vertically, with one field per line. A1 is ##column means using vertical table mode. The singleton table above is filled in as follows in vertical table mode.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Use sep to read beans and nested beans.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Use sep to read normal containers.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Use sep to read structure containers.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
multi-level header
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Qualify column format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Enumerated column-qualified format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
polymorphic bean column qualification format
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
column-qualified format for map
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
multiline field
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Data label filtering
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## Overview of other formats
|
||||||
|
|
||||||
|
Take behavior tree as an example to show how to configure behavior tree configuration in json format. For xml, lua, yaml and other formats, please refer to [Detailed Documentation](https://luban.doc.code-philosophy.com/docs/intro).
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": 10002,
|
||||||
|
"name": "random move",
|
||||||
|
"desc": "demo behavior tree",
|
||||||
|
"executor": "SERVER",
|
||||||
|
"blackboard_id": "demo",
|
||||||
|
"root": {
|
||||||
|
"$type": "Sequence",
|
||||||
|
"id": 1,
|
||||||
|
"node_name": "test",
|
||||||
|
"desc": "root",
|
||||||
|
"services": [],
|
||||||
|
"decorators": [
|
||||||
|
{
|
||||||
|
"$type": "UeLoop",
|
||||||
|
"id": 3,
|
||||||
|
"node_name": "",
|
||||||
|
"flow_abort_mode": "SELF",
|
||||||
|
"num_loops": 0,
|
||||||
|
"infinite_loop": true,
|
||||||
|
"infinite_loop_timeout_time": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"$type": "UeWait",
|
||||||
|
"id": 30,
|
||||||
|
"node_name": "",
|
||||||
|
"ignore_restart_self": false,
|
||||||
|
"wait_time": 1,
|
||||||
|
"random_deviation": 0.5,
|
||||||
|
"services": [],
|
||||||
|
"decorators": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "MoveToRandomLocation",
|
||||||
|
"id": 75,
|
||||||
|
"node_name": "",
|
||||||
|
"ignore_restart_self": false,
|
||||||
|
"origin_position_key": "x5",
|
||||||
|
"radius": 30,
|
||||||
|
"services": [],
|
||||||
|
"decorators": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## code usage preview
|
||||||
|
|
||||||
|
|
||||||
|
Here we only briefly show the usage of c#, typescript, go, and c++ languages in development. For more languages and more detailed usage examples and codes, see [Example Project](https://github.com/focus-creative-games/luban_examples ).
|
||||||
|
|
||||||
|
- C# usage example
|
||||||
|
|
||||||
|
```C#
|
||||||
|
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
|
||||||
|
var tables = new cfg.Tables(file => return new ByteBuf(File.ReadAllBytes($"{gameConfDir}/{file}.bytes")));
|
||||||
|
// access a singleton table
|
||||||
|
Console.WriteLine(tables.TbGlobal.Name);
|
||||||
|
// access normal key-value table
|
||||||
|
Console.WriteLine(tables.TbItem.Get(12).Name);
|
||||||
|
// support operator [] usage
|
||||||
|
Console.WriteLine(tables.TbMail[1001].Desc);
|
||||||
|
```
|
||||||
|
|
||||||
|
- example of typescript usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
|
||||||
|
let tables = new cfg. Tables(f => JsHelpers. LoadFromFile(gameConfDir, f))
|
||||||
|
// access a singleton table
|
||||||
|
console.log(tables.TbGlobal.name)
|
||||||
|
// access normal key-value table
|
||||||
|
console.log(tables.TbItem.get(12).Name)
|
||||||
|
```
|
||||||
|
|
||||||
|
- go usage example
|
||||||
|
|
||||||
|
```go
|
||||||
|
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
|
||||||
|
if tables , err := cfg.NewTables(loader) ; err != nil {
|
||||||
|
println(err. Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// access a singleton table
|
||||||
|
println(tables. TbGlobal. Name)
|
||||||
|
// access normal key-value table
|
||||||
|
println(tables. TbItem. Get(12). Name)
|
||||||
|
```
|
||||||
|
|
||||||
|
- c++ usage example
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
cfg::Tables tables;
|
||||||
|
if (!tables.load([](ByteBuf& buf, const std::string& s) { return buf.loadFromFile("../GenerateDatas/bytes/" + s + ".bytes"); }))
|
||||||
|
{
|
||||||
|
std::cout << "== load fail == " << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cout << tables. TbGlobal->name << std::endl;
|
||||||
|
std::cout << tables.TbItem.get(12)->name << std::endl;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## license
|
||||||
|
|
||||||
|
Luban is licensed under the [MIT](https://github.com/focus-creative-games/luban/blob/main/LICENSE) license
|
||||||
7
README.md.meta
Normal file
7
README.md.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3cefe9933a4e0e44e845f53b784d2fc6
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
46
README_zh.md
Normal file
46
README_zh.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
- [README 中文](./README_zh.md)
|
||||||
|
- [README English](./README.md)
|
||||||
|
|
||||||
|
# Luban
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[](https://opensource.org/licenses/MIT) 
|
||||||
|
|
||||||
|
|
||||||
|
luban是一个强大、易用、优雅、稳定的游戏配置解决方案。它设计目标为满足从小型到超大型游戏项目的简单到复杂的游戏配置工作流需求。
|
||||||
|
|
||||||
|
luban可以处理丰富的文件类型,支持主流的语言,可以生成多种导出格式,支持丰富的数据检验功能,具有良好的跨平台能力,并且生成极快。
|
||||||
|
luban有清晰优雅的生成管线设计,支持良好的模块化和插件化,方便开发者进行二次开发。开发者很容易就能将luban适配到自己的配置格式,定制出满足项目要求的强大的配置工具。
|
||||||
|
|
||||||
|
luban标准化了游戏配置开发工作流,可以极大提升策划和程序的工作效率。
|
||||||
|
|
||||||
|
## 核心特性
|
||||||
|
|
||||||
|
- 丰富的源数据格式。支持excel族(csv,xls,xlsx,xlsm)、json、xml、yaml、lua等
|
||||||
|
- 丰富的导出格式。 支持生成binary、json、bson、xml、lua、yaml等格式数据
|
||||||
|
- 增强的excel格式。可以简洁地配置出像简单列表、子结构、结构列表,以及任意复杂的深层次的嵌套结构
|
||||||
|
- 完备的类型系统。不仅能表达常见的规范行列表,由于**支持OOP类型继承**,能灵活优雅表达行为树、技能、剧情、副本之类复杂GamePlay数据
|
||||||
|
- 支持多种的语言。支持生成c#、java、go、cpp、lua、python、typescript 等语言代码
|
||||||
|
- 支持主流的消息方案。 protobuf(schema + binary + json)、flatbuffers(schema + json)、msgpack(binary)
|
||||||
|
- 强大的数据校验能力。ref引用检查、path资源路径、range范围检查等等
|
||||||
|
- 完善的本地化支持
|
||||||
|
- 支持所有主流的游戏引擎和平台。支持Unity、Unreal、Cocos2x、Godot、微信小游戏等
|
||||||
|
- 良好的跨平台能力。能在Win,Linux,Mac平台良好运行。
|
||||||
|
- 支持所有主流的热更新方案。hybridclr、ilruntime、{x,t,s}lua、puerts等
|
||||||
|
- 清晰优雅的生成管线,很容易在luban基础上进行二次开发,定制出适合自己项目风格的配置工具。
|
||||||
|
|
||||||
|
## 文档
|
||||||
|
|
||||||
|
- [官方文档](https://luban.doc.code-philosophy.com/)
|
||||||
|
- [快速上手](https://luban.doc.code-philosophy.com/docs/beginner/quickstart)
|
||||||
|
- **示例项目** ([github](https://github.com/focus-creative-games/luban_examples)) ([gitee](https://gitee.com/focus-creative-games/luban_examples))
|
||||||
|
- 支持与联系
|
||||||
|
- QQ群: 692890842 (Luban开发交流群)
|
||||||
|
- discord: https://discord.gg/dGY4zzGMJ4
|
||||||
|
- 邮箱: luban@code-philosophy.com
|
||||||
|
|
||||||
|
## license
|
||||||
|
|
||||||
|
Luban is licensed under the [MIT](https://github.com/focus-creative-games/luban/blob/main/LICENSE) license
|
||||||
7
README_zh.md.meta
Normal file
7
README_zh.md.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a673262afcffe1d4a920ae8401c26bef
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime.meta
Normal file
8
Runtime.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ab26624db001e7c45b46b70cacc75ac1
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime/BeanBase.cs
Normal file
8
Runtime/BeanBase.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
namespace Luban
|
||||||
|
{
|
||||||
|
public abstract class BeanBase
|
||||||
|
{
|
||||||
|
public abstract int GetTypeId();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/BeanBase.cs.meta
Normal file
11
Runtime/BeanBase.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2a1978c3ede87404e99b5429f92b2eb9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
1568
Runtime/ByteBuf.cs
Normal file
1568
Runtime/ByteBuf.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Runtime/ByteBuf.cs.meta
Normal file
11
Runtime/ByteBuf.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 07bfa7e432cf1334ca285411f9c97a9a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
14
Runtime/Luban.Runtime.asmdef
Normal file
14
Runtime/Luban.Runtime.asmdef
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "Luban.Runtime",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": true,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
7
Runtime/Luban.Runtime.asmdef.meta
Normal file
7
Runtime/Luban.Runtime.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2a81c6962524d424a8ef5072bd3b0fa0
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime/SimpleJSON.meta
Normal file
8
Runtime/SimpleJSON.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 01830ef12a97cf045bd989f2484f73ce
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
111
Runtime/SimpleJSON/Changelog.txt
Normal file
111
Runtime/SimpleJSON/Changelog.txt
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* [2012-06-09 First Version]
|
||||||
|
* - provides strongly typed node classes and lists / dictionaries
|
||||||
|
* - provides easy access to class members / array items / data values
|
||||||
|
* - the parser now properly identifies types. So generating JSON with this framework should work.
|
||||||
|
* - only double quotes (") are used for quoting strings.
|
||||||
|
* - provides "casting" properties to easily convert to / from those types:
|
||||||
|
* int / float / double / bool
|
||||||
|
* - provides a common interface for each node so no explicit casting is required.
|
||||||
|
* - the parser tries to avoid errors, but if malformed JSON is parsed the result is more or less undefined
|
||||||
|
* - It can serialize/deserialize a node tree into/from an experimental compact binary format. It might
|
||||||
|
* be handy if you want to store things in a file and don't want it to be easily modifiable
|
||||||
|
*
|
||||||
|
* [2012-12-17 Update]
|
||||||
|
* - Added internal JSONLazyCreator class which simplifies the construction of a JSON tree
|
||||||
|
* Now you can simple reference any item that doesn't exist yet and it will return a JSONLazyCreator
|
||||||
|
* The class determines the required type by it's further use, creates the type and removes itself.
|
||||||
|
* - Added binary serialization / deserialization.
|
||||||
|
* - Added support for BZip2 zipped binary format. Requires the SharpZipLib ( http://www.icsharpcode.net/opensource/sharpziplib/ )
|
||||||
|
* The usage of the SharpZipLib library can be disabled by removing or commenting out the USE_SharpZipLib define at the top
|
||||||
|
* - The serializer uses different types when it comes to store the values. Since my data values
|
||||||
|
* are all of type string, the serializer will "try" which format fits best. The order is: int, float, double, bool, string.
|
||||||
|
* It's not the most efficient way but for a moderate amount of data it should work on all platforms.
|
||||||
|
*
|
||||||
|
* [2017-03-08 Update]
|
||||||
|
* - Optimised parsing by using a StringBuilder for token. This prevents performance issues when large
|
||||||
|
* string data fields are contained in the json data.
|
||||||
|
* - Finally refactored the badly named JSONClass into JSONObject.
|
||||||
|
* - Replaced the old JSONData class by distict typed classes ( JSONString, JSONNumber, JSONBool, JSONNull ) this
|
||||||
|
* allows to propertly convert the node tree back to json without type information loss. The actual value
|
||||||
|
* parsing now happens at parsing time and not when you actually access one of the casting properties.
|
||||||
|
*
|
||||||
|
* [2017-04-11 Update]
|
||||||
|
* - Fixed parsing bug where empty string values have been ignored.
|
||||||
|
* - Optimised "ToString" by using a StringBuilder internally. This should heavily improve performance for large files
|
||||||
|
* - Changed the overload of "ToString(string aIndent)" to "ToString(int aIndent)"
|
||||||
|
*
|
||||||
|
* [2017-11-29 Update]
|
||||||
|
* - Removed the IEnumerator implementations on JSONArray & JSONObject and replaced it with a common
|
||||||
|
* struct Enumerator in JSONNode that should avoid garbage generation. The enumerator always works
|
||||||
|
* on KeyValuePair<string, JSONNode>, even for JSONArray.
|
||||||
|
* - Added two wrapper Enumerators that allows for easy key or value enumeration. A JSONNode now has
|
||||||
|
* a "Keys" and a "Values" enumerable property. Those are also struct enumerators / enumerables
|
||||||
|
* - A KeyValuePair<string, JSONNode> can now be implicitly converted into a JSONNode. This allows
|
||||||
|
* a foreach loop over a JSONNode to directly access the values only. Since KeyValuePair as well as
|
||||||
|
* all the Enumerators are structs, no garbage is allocated.
|
||||||
|
* - To add Linq support another "LinqEnumerator" is available through the "Linq" property. This
|
||||||
|
* enumerator does implement the generic IEnumerable interface so most Linq extensions can be used
|
||||||
|
* on this enumerable object. This one does allocate memory as it's a wrapper class.
|
||||||
|
* - The Escape method now escapes all control characters (# < 32) in strings as uncode characters
|
||||||
|
* (\uXXXX) and if the static bool JSONNode.forceASCII is set to true it will also escape all
|
||||||
|
* characters # > 127. This might be useful if you require an ASCII output. Though keep in mind
|
||||||
|
* when your strings contain many non-ascii characters the strings become much longer (x6) and are
|
||||||
|
* no longer human readable.
|
||||||
|
* - The node types JSONObject and JSONArray now have an "Inline" boolean switch which will default to
|
||||||
|
* false. It can be used to serialize this element inline even you serialize with an indented format
|
||||||
|
* This is useful for arrays containing numbers so it doesn't place every number on a new line
|
||||||
|
* - Extracted the binary serialization code into a seperate extension file. All classes are now declared
|
||||||
|
* as "partial" so an extension file can even add a new virtual or abstract method / interface to
|
||||||
|
* JSONNode and override it in the concrete type classes. It's of course a hacky approach which is
|
||||||
|
* generally not recommended, but i wanted to keep everything tightly packed.
|
||||||
|
* - Added a static CreateOrGet method to the JSONNull class. Since this class is immutable it could
|
||||||
|
* be reused without major problems. If you have a lot null fields in your data it will help reduce
|
||||||
|
* the memory / garbage overhead. I also added a static setting (reuseSameInstance) to JSONNull
|
||||||
|
* (default is true) which will change the behaviour of "CreateOrGet". If you set this to false
|
||||||
|
* CreateOrGet will not reuse the cached instance but instead create a new JSONNull instance each time.
|
||||||
|
* I made the JSONNull constructor private so if you need to create an instance manually use
|
||||||
|
* JSONNull.CreateOrGet()
|
||||||
|
*
|
||||||
|
* [2018-01-09 Update]
|
||||||
|
* - Changed all double.TryParse and double.ToString uses to use the invariant culture to avoid problems
|
||||||
|
* on systems with a culture that uses a comma as decimal point.
|
||||||
|
*
|
||||||
|
* [2018-01-26 Update]
|
||||||
|
* - Added AsLong. Note that a JSONNumber is stored as double and can't represent all long values. However
|
||||||
|
* storing it as string would work.
|
||||||
|
* - Added static setting "JSONNode.longAsString" which controls the default type that is used by the
|
||||||
|
* LazyCreator when using AsLong
|
||||||
|
*
|
||||||
|
* [2018-04-25 Update]
|
||||||
|
* - Added support for parsing single values (JSONBool, JSONString, JSONNumber, JSONNull) as top level value.
|
||||||
|
*
|
||||||
|
* [2019-02-18 Update]
|
||||||
|
* - Added HasKey(key) and GetValueOrDefault(key, default) to the JSONNode class to provide way to read
|
||||||
|
* values conditionally without creating a LazyCreator
|
||||||
|
*
|
||||||
|
* [2019-03-25 Update]
|
||||||
|
* - Added static setting "allowLineComments" to the JSONNode class which is true by default. This allows
|
||||||
|
* "//" line comments when parsing json text as long as it's not within quoted text. All text after // up
|
||||||
|
* to the end of the line is completely ignored / skipped. This makes it easier to create human readable
|
||||||
|
* and editable files. Note that stripped comments are not read, processed or preserved in any way. So
|
||||||
|
* this feature is only relevant for human created files.
|
||||||
|
* - Explicitly strip BOM (Byte Order Mark) when parsing to avoid getting it leaked into a single primitive
|
||||||
|
* value. That's a rare case but better safe than sorry.
|
||||||
|
* - Allowing adding the empty string as key
|
||||||
|
*
|
||||||
|
* [2019-12-10 Update]
|
||||||
|
* - Added Clone() method to JSONNode to allow cloning of a whole node tree.
|
||||||
|
*
|
||||||
|
* [2020-09-19 Update]
|
||||||
|
* - Added Clear() method to JSONNode.
|
||||||
|
* - The parser will now automatically mark arrays or objects as inline when it doesn't contain any
|
||||||
|
* new line characters. This should more or less preserve the layout.
|
||||||
|
* - Added new extension file "SimpleJSONDotNetTypes.cs" to provide support for some basic .NET types
|
||||||
|
* like decimal, char, byte, sbyte, short, ushort, uint, DateTime, TimeSpan and Guid as well as some
|
||||||
|
* nullable types.
|
||||||
|
* - Fixed an error in the Unity extension file. The Color component order was wrong (it was argb, now it's rgba)
|
||||||
|
* - There are now two static float variables (ColorDefaultAlpha and Color32DefaultAlpha) to specify the default
|
||||||
|
* alpha values when reading UnityEngine.Color / Color32 values where the alpha value is absent. The default
|
||||||
|
* values are 1.0f and 255 respectively.
|
||||||
|
*/
|
||||||
7
Runtime/SimpleJSON/Changelog.txt.meta
Normal file
7
Runtime/SimpleJSON/Changelog.txt.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35336dcb5aad4cf45b523dbf1482a514
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
21
Runtime/SimpleJSON/LICENSE
Normal file
21
Runtime/SimpleJSON/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2012-2017 Markus Göbel (Bunny83)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
7
Runtime/SimpleJSON/LICENSE.meta
Normal file
7
Runtime/SimpleJSON/LICENSE.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4615d3ebbd0d7ae4fa8c107f727bbab4
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
0
Runtime/SimpleJSON/README
Normal file
0
Runtime/SimpleJSON/README
Normal file
7
Runtime/SimpleJSON/README.meta
Normal file
7
Runtime/SimpleJSON/README.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0b3e755f11799b5458a47d6b897a9393
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
1434
Runtime/SimpleJSON/SimpleJSON.cs
Normal file
1434
Runtime/SimpleJSON/SimpleJSON.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Runtime/SimpleJSON/SimpleJSON.cs.meta
Normal file
11
Runtime/SimpleJSON/SimpleJSON.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c041f301d0633aa488c390e2574f6584
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
301
Runtime/SimpleJSON/SimpleJSONBinary.cs
Normal file
301
Runtime/SimpleJSON/SimpleJSONBinary.cs
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
//#define USE_SharpZipLib
|
||||||
|
/* * * * *
|
||||||
|
* This is an extension of the SimpleJSON framework to provide methods to
|
||||||
|
* serialize a JSON object tree into a compact binary format. Optionally the
|
||||||
|
* binary stream can be compressed with the SharpZipLib when using the define
|
||||||
|
* "USE_SharpZipLib"
|
||||||
|
*
|
||||||
|
* Those methods where originally part of the framework but since it's rarely
|
||||||
|
* used I've extracted this part into this seperate module file.
|
||||||
|
*
|
||||||
|
* You can use the define "SimpleJSON_ExcludeBinary" to selectively disable
|
||||||
|
* this extension without the need to remove the file from the project.
|
||||||
|
*
|
||||||
|
* If you want to use compression when saving to file / stream / B64 you have to include
|
||||||
|
* SharpZipLib ( http://www.icsharpcode.net/opensource/sharpziplib/ ) in your project and
|
||||||
|
* define "USE_SharpZipLib" at the top of the file
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012-2017 Markus Göbel (Bunny83)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* * * * */
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SimpleJSON
|
||||||
|
{
|
||||||
|
#if !SimpleJSON_ExcludeBinary
|
||||||
|
public abstract partial class JSONNode
|
||||||
|
{
|
||||||
|
public abstract void SerializeBinary(System.IO.BinaryWriter aWriter);
|
||||||
|
|
||||||
|
public void SaveToBinaryStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
var W = new System.IO.BinaryWriter(aData);
|
||||||
|
SerializeBinary(W);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if USE_SharpZipLib
|
||||||
|
public void SaveToCompressedStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
using (var gzipOut = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(aData))
|
||||||
|
{
|
||||||
|
gzipOut.IsStreamOwner = false;
|
||||||
|
SaveToBinaryStream(gzipOut);
|
||||||
|
gzipOut.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveToCompressedFile(string aFileName)
|
||||||
|
{
|
||||||
|
|
||||||
|
System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);
|
||||||
|
using(var F = System.IO.File.OpenWrite(aFileName))
|
||||||
|
{
|
||||||
|
SaveToCompressedStream(F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string SaveToCompressedBase64()
|
||||||
|
{
|
||||||
|
using (var stream = new System.IO.MemoryStream())
|
||||||
|
{
|
||||||
|
SaveToCompressedStream(stream);
|
||||||
|
stream.Position = 0;
|
||||||
|
return System.Convert.ToBase64String(stream.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
public void SaveToCompressedStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveToCompressedFile(string aFileName)
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SaveToCompressedBase64()
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public void SaveToBinaryFile(string aFileName)
|
||||||
|
{
|
||||||
|
System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);
|
||||||
|
using (var F = System.IO.File.OpenWrite(aFileName))
|
||||||
|
{
|
||||||
|
SaveToBinaryStream(F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SaveToBinaryBase64()
|
||||||
|
{
|
||||||
|
using (var stream = new System.IO.MemoryStream())
|
||||||
|
{
|
||||||
|
SaveToBinaryStream(stream);
|
||||||
|
stream.Position = 0;
|
||||||
|
return System.Convert.ToBase64String(stream.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONNode DeserializeBinary(System.IO.BinaryReader aReader)
|
||||||
|
{
|
||||||
|
JSONNodeType type = (JSONNodeType)aReader.ReadByte();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case JSONNodeType.Array:
|
||||||
|
{
|
||||||
|
int count = aReader.ReadInt32();
|
||||||
|
JSONArray tmp = new JSONArray();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
tmp.Add(DeserializeBinary(aReader));
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
case JSONNodeType.Object:
|
||||||
|
{
|
||||||
|
int count = aReader.ReadInt32();
|
||||||
|
JSONObject tmp = new JSONObject();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
string key = aReader.ReadString();
|
||||||
|
var val = DeserializeBinary(aReader);
|
||||||
|
tmp.Add(key, val);
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
case JSONNodeType.String:
|
||||||
|
{
|
||||||
|
return new JSONString(aReader.ReadString());
|
||||||
|
}
|
||||||
|
case JSONNodeType.Number:
|
||||||
|
{
|
||||||
|
return new JSONNumber(aReader.ReadDouble());
|
||||||
|
}
|
||||||
|
case JSONNodeType.Boolean:
|
||||||
|
{
|
||||||
|
return new JSONBool(aReader.ReadBoolean());
|
||||||
|
}
|
||||||
|
case JSONNodeType.NullValue:
|
||||||
|
{
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new Exception("Error deserializing JSON. Unknown tag: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if USE_SharpZipLib
|
||||||
|
public static JSONNode LoadFromCompressedStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
var zin = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(aData);
|
||||||
|
return LoadFromBinaryStream(zin);
|
||||||
|
}
|
||||||
|
public static JSONNode LoadFromCompressedFile(string aFileName)
|
||||||
|
{
|
||||||
|
using(var F = System.IO.File.OpenRead(aFileName))
|
||||||
|
{
|
||||||
|
return LoadFromCompressedStream(F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static JSONNode LoadFromCompressedBase64(string aBase64)
|
||||||
|
{
|
||||||
|
var tmp = System.Convert.FromBase64String(aBase64);
|
||||||
|
var stream = new System.IO.MemoryStream(tmp);
|
||||||
|
stream.Position = 0;
|
||||||
|
return LoadFromCompressedStream(stream);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public static JSONNode LoadFromCompressedFile(string aFileName)
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONNode LoadFromCompressedStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONNode LoadFromCompressedBase64(string aBase64)
|
||||||
|
{
|
||||||
|
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static JSONNode LoadFromBinaryStream(System.IO.Stream aData)
|
||||||
|
{
|
||||||
|
using (var R = new System.IO.BinaryReader(aData))
|
||||||
|
{
|
||||||
|
return DeserializeBinary(R);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONNode LoadFromBinaryFile(string aFileName)
|
||||||
|
{
|
||||||
|
using (var F = System.IO.File.OpenRead(aFileName))
|
||||||
|
{
|
||||||
|
return LoadFromBinaryStream(F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONNode LoadFromBinaryBase64(string aBase64)
|
||||||
|
{
|
||||||
|
var tmp = System.Convert.FromBase64String(aBase64);
|
||||||
|
var stream = new System.IO.MemoryStream(tmp);
|
||||||
|
stream.Position = 0;
|
||||||
|
return LoadFromBinaryStream(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class JSONArray : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.Array);
|
||||||
|
aWriter.Write(m_List.Count);
|
||||||
|
for (int i = 0; i < m_List.Count; i++)
|
||||||
|
{
|
||||||
|
m_List[i].SerializeBinary(aWriter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class JSONObject : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.Object);
|
||||||
|
aWriter.Write(m_Dict.Count);
|
||||||
|
foreach (string K in m_Dict.Keys)
|
||||||
|
{
|
||||||
|
aWriter.Write(K);
|
||||||
|
m_Dict[K].SerializeBinary(aWriter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class JSONString : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.String);
|
||||||
|
aWriter.Write(m_Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class JSONNumber : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.Number);
|
||||||
|
aWriter.Write(m_Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class JSONBool : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.Boolean);
|
||||||
|
aWriter.Write(m_Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public partial class JSONNull : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
aWriter.Write((byte)JSONNodeType.NullValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal partial class JSONLazyCreator : JSONNode
|
||||||
|
{
|
||||||
|
public override void SerializeBinary(System.IO.BinaryWriter aWriter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
11
Runtime/SimpleJSON/SimpleJSONBinary.cs.meta
Normal file
11
Runtime/SimpleJSON/SimpleJSONBinary.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a777a4fe93c78c246b61a8e9c42ae35e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
516
Runtime/SimpleJSON/SimpleJSONDotNetTypes.cs
Normal file
516
Runtime/SimpleJSON/SimpleJSONDotNetTypes.cs
Normal file
@ -0,0 +1,516 @@
|
|||||||
|
#region License and information
|
||||||
|
/* * * * *
|
||||||
|
*
|
||||||
|
* Extension file for the SimpleJSON framework for better support of some common
|
||||||
|
* .NET types. It does only work together with the SimpleJSON.cs
|
||||||
|
* It provides direct conversion support for types like decimal, char, byte,
|
||||||
|
* sbyte, short, ushort, uint, DateTime, TimeSpan and Guid. In addition there
|
||||||
|
* are conversion helpers for converting an array of number values into a byte[]
|
||||||
|
* or a List<byte> as well as converting an array of string values into a string[]
|
||||||
|
* or List<string>.
|
||||||
|
* Finally there are some additional type conversion operators for some nullable
|
||||||
|
* types like short?, int?, float?, double?, long? and bool?. They will actually
|
||||||
|
* assign a JSONNull value when it's null or a JSONNumber when it's not.
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Markus Göbel (Bunny83)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* * * * */
|
||||||
|
|
||||||
|
#endregion License and information
|
||||||
|
|
||||||
|
namespace SimpleJSON
|
||||||
|
{
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
public partial class JSONNode
|
||||||
|
{
|
||||||
|
#region Decimal
|
||||||
|
public virtual decimal AsDecimal
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
decimal result;
|
||||||
|
if (!decimal.TryParse(Value, out result))
|
||||||
|
result = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Value = value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(decimal aDecimal)
|
||||||
|
{
|
||||||
|
return new JSONString(aDecimal.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator decimal(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsDecimal;
|
||||||
|
}
|
||||||
|
#endregion Decimal
|
||||||
|
|
||||||
|
#region Char
|
||||||
|
public virtual char AsChar
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsString && Value.Length > 0)
|
||||||
|
return Value[0];
|
||||||
|
if (IsNumber)
|
||||||
|
return (char)AsInt;
|
||||||
|
return '\0';
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (IsString)
|
||||||
|
Value = value.ToString();
|
||||||
|
else if (IsNumber)
|
||||||
|
AsInt = (int)value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(char aChar)
|
||||||
|
{
|
||||||
|
return new JSONString(aChar.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator char(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsChar;
|
||||||
|
}
|
||||||
|
#endregion Decimal
|
||||||
|
|
||||||
|
#region UInt
|
||||||
|
public virtual uint AsUInt
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (uint)AsDouble;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AsDouble = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(uint aUInt)
|
||||||
|
{
|
||||||
|
return new JSONNumber(aUInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator uint(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsUInt;
|
||||||
|
}
|
||||||
|
#endregion UInt
|
||||||
|
|
||||||
|
#region Byte
|
||||||
|
public virtual byte AsByte
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (byte)AsInt;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AsInt = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(byte aByte)
|
||||||
|
{
|
||||||
|
return new JSONNumber(aByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator byte(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsByte;
|
||||||
|
}
|
||||||
|
#endregion Byte
|
||||||
|
#region SByte
|
||||||
|
public virtual sbyte AsSByte
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (sbyte)AsInt;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AsInt = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(sbyte aSByte)
|
||||||
|
{
|
||||||
|
return new JSONNumber(aSByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator sbyte(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsSByte;
|
||||||
|
}
|
||||||
|
#endregion SByte
|
||||||
|
|
||||||
|
#region Short
|
||||||
|
public virtual short AsShort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (short)AsInt;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AsInt = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(short aShort)
|
||||||
|
{
|
||||||
|
return new JSONNumber(aShort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator short(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsShort;
|
||||||
|
}
|
||||||
|
#endregion Short
|
||||||
|
#region UShort
|
||||||
|
public virtual ushort AsUShort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (ushort)AsInt;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AsInt = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(ushort aUShort)
|
||||||
|
{
|
||||||
|
return new JSONNumber(aUShort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator ushort(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsUShort;
|
||||||
|
}
|
||||||
|
#endregion UShort
|
||||||
|
|
||||||
|
#region DateTime
|
||||||
|
public virtual System.DateTime AsDateTime
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
System.DateTime result;
|
||||||
|
if (!System.DateTime.TryParse(Value, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
|
||||||
|
result = new System.DateTime(0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Value = value.ToString(CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(System.DateTime aDateTime)
|
||||||
|
{
|
||||||
|
return new JSONString(aDateTime.ToString(CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator System.DateTime(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsDateTime;
|
||||||
|
}
|
||||||
|
#endregion DateTime
|
||||||
|
#region TimeSpan
|
||||||
|
public virtual System.TimeSpan AsTimeSpan
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
System.TimeSpan result;
|
||||||
|
if (!System.TimeSpan.TryParse(Value, CultureInfo.InvariantCulture, out result))
|
||||||
|
result = new System.TimeSpan(0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Value = value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(System.TimeSpan aTimeSpan)
|
||||||
|
{
|
||||||
|
return new JSONString(aTimeSpan.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator System.TimeSpan(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsTimeSpan;
|
||||||
|
}
|
||||||
|
#endregion TimeSpan
|
||||||
|
|
||||||
|
#region Guid
|
||||||
|
public virtual System.Guid AsGuid
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
System.Guid result;
|
||||||
|
System.Guid.TryParse(Value, out result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Value = value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(System.Guid aGuid)
|
||||||
|
{
|
||||||
|
return new JSONString(aGuid.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator System.Guid(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsGuid;
|
||||||
|
}
|
||||||
|
#endregion Guid
|
||||||
|
|
||||||
|
#region ByteArray
|
||||||
|
public virtual byte[] AsByteArray
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.IsNull || !this.IsArray)
|
||||||
|
return null;
|
||||||
|
int count = Count;
|
||||||
|
byte[] result = new byte[count];
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
result[i] = this[i].AsByte;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!IsArray || value == null)
|
||||||
|
return;
|
||||||
|
Clear();
|
||||||
|
for (int i = 0; i < value.Length; i++)
|
||||||
|
Add(value[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(byte[] aByteArray)
|
||||||
|
{
|
||||||
|
return new JSONArray { AsByteArray = aByteArray };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator byte[](JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsByteArray;
|
||||||
|
}
|
||||||
|
#endregion ByteArray
|
||||||
|
#region ByteList
|
||||||
|
public virtual List<byte> AsByteList
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.IsNull || !this.IsArray)
|
||||||
|
return null;
|
||||||
|
int count = Count;
|
||||||
|
List<byte> result = new List<byte>(count);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
result.Add(this[i].AsByte);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!IsArray || value == null)
|
||||||
|
return;
|
||||||
|
Clear();
|
||||||
|
for (int i = 0; i < value.Count; i++)
|
||||||
|
Add(value[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(List<byte> aByteList)
|
||||||
|
{
|
||||||
|
return new JSONArray { AsByteList = aByteList };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator List<byte> (JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsByteList;
|
||||||
|
}
|
||||||
|
#endregion ByteList
|
||||||
|
|
||||||
|
#region StringArray
|
||||||
|
public virtual string[] AsStringArray
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.IsNull || !this.IsArray)
|
||||||
|
return null;
|
||||||
|
int count = Count;
|
||||||
|
string[] result = new string[count];
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
result[i] = this[i].Value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!IsArray || value == null)
|
||||||
|
return;
|
||||||
|
Clear();
|
||||||
|
for (int i = 0; i < value.Length; i++)
|
||||||
|
Add(value[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(string[] aStringArray)
|
||||||
|
{
|
||||||
|
return new JSONArray { AsStringArray = aStringArray };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator string[] (JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsStringArray;
|
||||||
|
}
|
||||||
|
#endregion StringArray
|
||||||
|
#region StringList
|
||||||
|
public virtual List<string> AsStringList
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.IsNull || !this.IsArray)
|
||||||
|
return null;
|
||||||
|
int count = Count;
|
||||||
|
List<string> result = new List<string>(count);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
result.Add(this[i].Value);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!IsArray || value == null)
|
||||||
|
return;
|
||||||
|
Clear();
|
||||||
|
for (int i = 0; i < value.Count; i++)
|
||||||
|
Add(value[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(List<string> aStringList)
|
||||||
|
{
|
||||||
|
return new JSONArray { AsStringList = aStringList };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator List<string> (JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.AsStringList;
|
||||||
|
}
|
||||||
|
#endregion StringList
|
||||||
|
|
||||||
|
#region NullableTypes
|
||||||
|
public static implicit operator JSONNode(int? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONNumber((int)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator int?(JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(float? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONNumber((float)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator float? (JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(double? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONNumber((double)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator double? (JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(bool? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONBool((bool)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator bool? (JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsBool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(long? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONNumber((long)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator long? (JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator JSONNode(short? aValue)
|
||||||
|
{
|
||||||
|
if (aValue == null)
|
||||||
|
return JSONNull.CreateOrGet();
|
||||||
|
return new JSONNumber((short)aValue);
|
||||||
|
}
|
||||||
|
public static implicit operator short? (JSONNode aNode)
|
||||||
|
{
|
||||||
|
if (aNode == null || aNode.IsNull)
|
||||||
|
return null;
|
||||||
|
return aNode.AsShort;
|
||||||
|
}
|
||||||
|
#endregion NullableTypes
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/SimpleJSON/SimpleJSONDotNetTypes.cs.meta
Normal file
11
Runtime/SimpleJSON/SimpleJSONDotNetTypes.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6f1bdd2f47e2a0a4d9f9974a50ce6666
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
462
Runtime/SimpleJSON/SimpleJSONUnity.cs
Normal file
462
Runtime/SimpleJSON/SimpleJSONUnity.cs
Normal file
@ -0,0 +1,462 @@
|
|||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
#region License and information
|
||||||
|
/* * * * *
|
||||||
|
*
|
||||||
|
* Unity extension for the SimpleJSON framework. It does only work together with
|
||||||
|
* the SimpleJSON.cs
|
||||||
|
* It provides several helpers and conversion operators to serialize/deserialize
|
||||||
|
* common Unity types such as Vector2/3/4, Rect, RectOffset, Quaternion and
|
||||||
|
* Matrix4x4 as JSONObject or JSONArray.
|
||||||
|
* This extension will add 3 static settings to the JSONNode class:
|
||||||
|
* ( VectorContainerType, QuaternionContainerType, RectContainerType ) which
|
||||||
|
* control what node type should be used for serializing the given type. So a
|
||||||
|
* Vector3 as array would look like [12,32,24] and {"x":12, "y":32, "z":24} as
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012-2017 Markus Göbel (Bunny83)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* * * * */
|
||||||
|
|
||||||
|
#endregion License and information
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace SimpleJSON
|
||||||
|
{
|
||||||
|
public enum JSONContainerType { Array, Object }
|
||||||
|
public partial class JSONNode
|
||||||
|
{
|
||||||
|
public static byte Color32DefaultAlpha = 255;
|
||||||
|
public static float ColorDefaultAlpha = 1f;
|
||||||
|
public static JSONContainerType VectorContainerType = JSONContainerType.Array;
|
||||||
|
public static JSONContainerType QuaternionContainerType = JSONContainerType.Array;
|
||||||
|
public static JSONContainerType RectContainerType = JSONContainerType.Array;
|
||||||
|
public static JSONContainerType ColorContainerType = JSONContainerType.Array;
|
||||||
|
private static JSONNode GetContainer(JSONContainerType aType)
|
||||||
|
{
|
||||||
|
if (aType == JSONContainerType.Array)
|
||||||
|
return new JSONArray();
|
||||||
|
return new JSONObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region implicit conversion operators
|
||||||
|
public static implicit operator JSONNode(Vector2 aVec)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(VectorContainerType);
|
||||||
|
n.WriteVector2(aVec);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Vector3 aVec)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(VectorContainerType);
|
||||||
|
n.WriteVector3(aVec);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Vector4 aVec)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(VectorContainerType);
|
||||||
|
n.WriteVector4(aVec);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Color aCol)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(ColorContainerType);
|
||||||
|
n.WriteColor(aCol);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Color32 aCol)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(ColorContainerType);
|
||||||
|
n.WriteColor32(aCol);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Quaternion aRot)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(QuaternionContainerType);
|
||||||
|
n.WriteQuaternion(aRot);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(Rect aRect)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(RectContainerType);
|
||||||
|
n.WriteRect(aRect);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
public static implicit operator JSONNode(RectOffset aRect)
|
||||||
|
{
|
||||||
|
JSONNode n = GetContainer(RectContainerType);
|
||||||
|
n.WriteRectOffset(aRect);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator Vector2(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadVector2();
|
||||||
|
}
|
||||||
|
public static implicit operator Vector3(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadVector3();
|
||||||
|
}
|
||||||
|
public static implicit operator Vector4(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadVector4();
|
||||||
|
}
|
||||||
|
public static implicit operator Color(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadColor();
|
||||||
|
}
|
||||||
|
public static implicit operator Color32(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadColor32();
|
||||||
|
}
|
||||||
|
public static implicit operator Quaternion(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadQuaternion();
|
||||||
|
}
|
||||||
|
public static implicit operator Rect(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadRect();
|
||||||
|
}
|
||||||
|
public static implicit operator RectOffset(JSONNode aNode)
|
||||||
|
{
|
||||||
|
return aNode.ReadRectOffset();
|
||||||
|
}
|
||||||
|
#endregion implicit conversion operators
|
||||||
|
|
||||||
|
#region Vector2
|
||||||
|
public Vector2 ReadVector2(Vector2 aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Vector2(this["x"].AsFloat, this["y"].AsFloat);
|
||||||
|
if (IsArray)
|
||||||
|
return new Vector2(this[0].AsFloat, this[1].AsFloat);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Vector2 ReadVector2(string aXName, string aYName)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
return new Vector2(this[aXName].AsFloat, this[aYName].AsFloat);
|
||||||
|
}
|
||||||
|
return Vector2.zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 ReadVector2()
|
||||||
|
{
|
||||||
|
return ReadVector2(Vector2.zero);
|
||||||
|
}
|
||||||
|
public JSONNode WriteVector2(Vector2 aVec, string aXName = "x", string aYName = "y")
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[aXName].AsFloat = aVec.x;
|
||||||
|
this[aYName].AsFloat = aVec.y;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aVec.x;
|
||||||
|
this[1].AsFloat = aVec.y;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Vector2
|
||||||
|
|
||||||
|
#region Vector3
|
||||||
|
public Vector3 ReadVector3(Vector3 aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Vector3(this["x"].AsFloat, this["y"].AsFloat, this["z"].AsFloat);
|
||||||
|
if (IsArray)
|
||||||
|
return new Vector3(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Vector3 ReadVector3(string aXName, string aYName, string aZName)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Vector3(this[aXName].AsFloat, this[aYName].AsFloat, this[aZName].AsFloat);
|
||||||
|
return Vector3.zero;
|
||||||
|
}
|
||||||
|
public Vector3 ReadVector3()
|
||||||
|
{
|
||||||
|
return ReadVector3(Vector3.zero);
|
||||||
|
}
|
||||||
|
public JSONNode WriteVector3(Vector3 aVec, string aXName = "x", string aYName = "y", string aZName = "z")
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[aXName].AsFloat = aVec.x;
|
||||||
|
this[aYName].AsFloat = aVec.y;
|
||||||
|
this[aZName].AsFloat = aVec.z;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aVec.x;
|
||||||
|
this[1].AsFloat = aVec.y;
|
||||||
|
this[2].AsFloat = aVec.z;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Vector3
|
||||||
|
|
||||||
|
#region Vector4
|
||||||
|
public Vector4 ReadVector4(Vector4 aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Vector4(this["x"].AsFloat, this["y"].AsFloat, this["z"].AsFloat, this["w"].AsFloat);
|
||||||
|
if (IsArray)
|
||||||
|
return new Vector4(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, this[3].AsFloat);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Vector4 ReadVector4()
|
||||||
|
{
|
||||||
|
return ReadVector4(Vector4.zero);
|
||||||
|
}
|
||||||
|
public JSONNode WriteVector4(Vector4 aVec)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["x"].AsFloat = aVec.x;
|
||||||
|
this["y"].AsFloat = aVec.y;
|
||||||
|
this["z"].AsFloat = aVec.z;
|
||||||
|
this["w"].AsFloat = aVec.w;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aVec.x;
|
||||||
|
this[1].AsFloat = aVec.y;
|
||||||
|
this[2].AsFloat = aVec.z;
|
||||||
|
this[3].AsFloat = aVec.w;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Vector4
|
||||||
|
|
||||||
|
#region Color / Color32
|
||||||
|
public Color ReadColor(Color aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Color(this["r"].AsFloat, this["g"].AsFloat, this["b"].AsFloat, HasKey("a")?this["a"].AsFloat:ColorDefaultAlpha);
|
||||||
|
if (IsArray)
|
||||||
|
return new Color(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, (Count>3)?this[3].AsFloat:ColorDefaultAlpha);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Color ReadColor()
|
||||||
|
{
|
||||||
|
return ReadColor(Color.clear);
|
||||||
|
}
|
||||||
|
public JSONNode WriteColor(Color aCol)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["r"].AsFloat = aCol.r;
|
||||||
|
this["g"].AsFloat = aCol.g;
|
||||||
|
this["b"].AsFloat = aCol.b;
|
||||||
|
this["a"].AsFloat = aCol.a;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aCol.r;
|
||||||
|
this[1].AsFloat = aCol.g;
|
||||||
|
this[2].AsFloat = aCol.b;
|
||||||
|
this[3].AsFloat = aCol.a;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color32 ReadColor32(Color32 aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Color32((byte)this["r"].AsInt, (byte)this["g"].AsInt, (byte)this["b"].AsInt, (byte)(HasKey("a")?this["a"].AsInt:Color32DefaultAlpha));
|
||||||
|
if (IsArray)
|
||||||
|
return new Color32((byte)this[0].AsInt, (byte)this[1].AsInt, (byte)this[2].AsInt, (byte)((Count>3)?this[3].AsInt:Color32DefaultAlpha));
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Color32 ReadColor32()
|
||||||
|
{
|
||||||
|
return ReadColor32(new Color32());
|
||||||
|
}
|
||||||
|
public JSONNode WriteColor32(Color32 aCol)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["r"].AsInt = aCol.r;
|
||||||
|
this["g"].AsInt = aCol.g;
|
||||||
|
this["b"].AsInt = aCol.b;
|
||||||
|
this["a"].AsInt = aCol.a;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsInt = aCol.r;
|
||||||
|
this[1].AsInt = aCol.g;
|
||||||
|
this[2].AsInt = aCol.b;
|
||||||
|
this[3].AsInt = aCol.a;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Color / Color32
|
||||||
|
|
||||||
|
#region Quaternion
|
||||||
|
public Quaternion ReadQuaternion(Quaternion aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Quaternion(this["x"].AsFloat, this["y"].AsFloat, this["z"].AsFloat, this["w"].AsFloat);
|
||||||
|
if (IsArray)
|
||||||
|
return new Quaternion(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, this[3].AsFloat);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Quaternion ReadQuaternion()
|
||||||
|
{
|
||||||
|
return ReadQuaternion(Quaternion.identity);
|
||||||
|
}
|
||||||
|
public JSONNode WriteQuaternion(Quaternion aRot)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["x"].AsFloat = aRot.x;
|
||||||
|
this["y"].AsFloat = aRot.y;
|
||||||
|
this["z"].AsFloat = aRot.z;
|
||||||
|
this["w"].AsFloat = aRot.w;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aRot.x;
|
||||||
|
this[1].AsFloat = aRot.y;
|
||||||
|
this[2].AsFloat = aRot.z;
|
||||||
|
this[3].AsFloat = aRot.w;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Quaternion
|
||||||
|
|
||||||
|
#region Rect
|
||||||
|
public Rect ReadRect(Rect aDefault)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
return new Rect(this["x"].AsFloat, this["y"].AsFloat, this["width"].AsFloat, this["height"].AsFloat);
|
||||||
|
if (IsArray)
|
||||||
|
return new Rect(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, this[3].AsFloat);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public Rect ReadRect()
|
||||||
|
{
|
||||||
|
return ReadRect(new Rect());
|
||||||
|
}
|
||||||
|
public JSONNode WriteRect(Rect aRect)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["x"].AsFloat = aRect.x;
|
||||||
|
this["y"].AsFloat = aRect.y;
|
||||||
|
this["width"].AsFloat = aRect.width;
|
||||||
|
this["height"].AsFloat = aRect.height;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsFloat = aRect.x;
|
||||||
|
this[1].AsFloat = aRect.y;
|
||||||
|
this[2].AsFloat = aRect.width;
|
||||||
|
this[3].AsFloat = aRect.height;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Rect
|
||||||
|
|
||||||
|
#region RectOffset
|
||||||
|
public RectOffset ReadRectOffset(RectOffset aDefault)
|
||||||
|
{
|
||||||
|
if (this is JSONObject)
|
||||||
|
return new RectOffset(this["left"].AsInt, this["right"].AsInt, this["top"].AsInt, this["bottom"].AsInt);
|
||||||
|
if (this is JSONArray)
|
||||||
|
return new RectOffset(this[0].AsInt, this[1].AsInt, this[2].AsInt, this[3].AsInt);
|
||||||
|
return aDefault;
|
||||||
|
}
|
||||||
|
public RectOffset ReadRectOffset()
|
||||||
|
{
|
||||||
|
return ReadRectOffset(new RectOffset());
|
||||||
|
}
|
||||||
|
public JSONNode WriteRectOffset(RectOffset aRect)
|
||||||
|
{
|
||||||
|
if (IsObject)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this["left"].AsInt = aRect.left;
|
||||||
|
this["right"].AsInt = aRect.right;
|
||||||
|
this["top"].AsInt = aRect.top;
|
||||||
|
this["bottom"].AsInt = aRect.bottom;
|
||||||
|
}
|
||||||
|
else if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
this[0].AsInt = aRect.left;
|
||||||
|
this[1].AsInt = aRect.right;
|
||||||
|
this[2].AsInt = aRect.top;
|
||||||
|
this[3].AsInt = aRect.bottom;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion RectOffset
|
||||||
|
|
||||||
|
#region Matrix4x4
|
||||||
|
public Matrix4x4 ReadMatrix()
|
||||||
|
{
|
||||||
|
Matrix4x4 result = Matrix4x4.identity;
|
||||||
|
if (IsArray)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
result[i] = this[i].AsFloat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public JSONNode WriteMatrix(Matrix4x4 aMatrix)
|
||||||
|
{
|
||||||
|
if (IsArray)
|
||||||
|
{
|
||||||
|
Inline = true;
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
this[i].AsFloat = aMatrix[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion Matrix4x4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
11
Runtime/SimpleJSON/SimpleJSONUnity.cs.meta
Normal file
11
Runtime/SimpleJSON/SimpleJSONUnity.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0794c5fece7ec984192e57c9ecc88720
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
52
Runtime/StringUtil.cs
Normal file
52
Runtime/StringUtil.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Luban
|
||||||
|
{
|
||||||
|
public static class StringUtil
|
||||||
|
{
|
||||||
|
public static string ToStr(object o)
|
||||||
|
{
|
||||||
|
return ToStr(o, new StringBuilder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToStr(object o, StringBuilder sb)
|
||||||
|
{
|
||||||
|
foreach (var p in o.GetType().GetFields())
|
||||||
|
{
|
||||||
|
|
||||||
|
sb.Append($"{p.Name} = {p.GetValue(o)},");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var p in o.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
sb.Append($"{p.Name} = {p.GetValue(o)},");
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ArrayToString<T>(T[] arr)
|
||||||
|
{
|
||||||
|
return "[" + string.Join(",", arr) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string CollectionToString<T>(IEnumerable<T> arr)
|
||||||
|
{
|
||||||
|
return "[" + string.Join(",", arr) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string CollectionToString<TK, TV>(IDictionary<TK, TV> dic)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder('{');
|
||||||
|
foreach (var e in dic)
|
||||||
|
{
|
||||||
|
sb.Append(e.Key).Append(':');
|
||||||
|
sb.Append(e.Value).Append(',');
|
||||||
|
}
|
||||||
|
sb.Append('}');
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/StringUtil.cs.meta
Normal file
11
Runtime/StringUtil.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef82068810e5599439c5346fba3b0f97
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
docs.meta
Normal file
8
docs.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 635b11779b767c54bbbe70f474292aeb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
1
docs/_config.yml
Normal file
1
docs/_config.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
theme: jekyll-theme-slate
|
||||||
7
docs/_config.yml.meta
Normal file
7
docs/_config.yml.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b1e71d5853b6a0f4ea338a9604f4d5be
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
docs/images.meta
Normal file
8
docs/images.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aed25405d59f4494aba189e4b1f072a9
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
docs/images/logo.png
Normal file
BIN
docs/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
121
docs/images/logo.png.meta
Normal file
121
docs/images/logo.png.meta
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2adf4f0248a87f14d9a286c4368a502f
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 12
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 1
|
||||||
|
sRGBTexture: 1
|
||||||
|
linearTexture: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapsPreserveCoverage: 0
|
||||||
|
alphaTestReferenceValue: 0.5
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
isReadable: 0
|
||||||
|
streamingMipmaps: 0
|
||||||
|
streamingMipmapsPriority: 0
|
||||||
|
vTOnly: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 6
|
||||||
|
cubemapConvolution: 0
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: 1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
filterMode: 1
|
||||||
|
aniso: 1
|
||||||
|
mipBias: 0
|
||||||
|
wrapU: 0
|
||||||
|
wrapV: 0
|
||||||
|
wrapW: 0
|
||||||
|
nPOTScale: 1
|
||||||
|
lightmap: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
spriteMode: 0
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
|
alphaUsage: 1
|
||||||
|
alphaIsTransparency: 0
|
||||||
|
spriteTessellationDetail: -1
|
||||||
|
textureType: 0
|
||||||
|
textureShape: 1
|
||||||
|
singleChannelComponent: 0
|
||||||
|
flipbookRows: 1
|
||||||
|
flipbookColumns: 1
|
||||||
|
maxTextureSizeSet: 0
|
||||||
|
compressionQualitySet: 0
|
||||||
|
textureFormatSet: 0
|
||||||
|
ignorePngGamma: 0
|
||||||
|
applyGammaDecoding: 0
|
||||||
|
cookieLightType: 0
|
||||||
|
platformSettings:
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: DefaultTexturePlatform
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Standalone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Android
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
spriteSheet:
|
||||||
|
serializedVersion: 2
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
physicsShape: []
|
||||||
|
bones: []
|
||||||
|
spriteID:
|
||||||
|
internalID: 0
|
||||||
|
vertices: []
|
||||||
|
indices:
|
||||||
|
edges: []
|
||||||
|
weights: []
|
||||||
|
secondaryTextures: []
|
||||||
|
spritePackingTag:
|
||||||
|
pSDRemoveMatte: 0
|
||||||
|
pSDShowRemoveMatteOption: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
20
package.json
Normal file
20
package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "com.code-philosophy.luban",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"displayName": "Luban",
|
||||||
|
"description": "luban is a powerful, easy-to-use, elegant and stable game configuration solution.",
|
||||||
|
"category": "Runtime",
|
||||||
|
"documentationUrl": "https://luban.doc.code-philosophy.com/#/",
|
||||||
|
"changelogUrl": "https://luban.doc.code-philosophy.com/#/other/changelog",
|
||||||
|
"licensesUrl": "https://github.com/focus-creative-games/luban_unity/blob/main/LICENSE",
|
||||||
|
"keywords": [
|
||||||
|
"luban",
|
||||||
|
"focus-creative-games",
|
||||||
|
"code-philosophy"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "Code Philosophy",
|
||||||
|
"email": "luban@code-philosophy.com",
|
||||||
|
"url": "https://code-philosophy.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
package.json.meta
Normal file
7
package.json.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ff12bd64e92ccc647b703701cc341095
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Reference in New Issue
Block a user