Commit 4da75b2d authored by 潘梓豪's avatar 潘梓豪

更新通知栏

parent 9a9ed526
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!221 &22100000
AnimatorOverrideController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New Animator Override Controller
m_Controller: {fileID: 0}
m_Clips: []
fileFormatVersion: 2
guid: 00c1b4fc534a3b141ad1930f8fade1e8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 22100000
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d5354c40707f67249a73e6f123ba92cf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9cd62bafd75e7604daf2b561b80d136d
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 084116138e3349d48bdf50214aebefc5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6c76d1cfa11c6b741ba30b24d36cbcf2
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
platformData:
- first:
Android: Android
second:
enabled: 1
settings:
CPU: ARM64
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b8d0cd0f5702f0144af2498bce3ee3e9
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6e1b2e17cce240d4c8ff5457ac996e0d
timeCreated: 1451443249
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 1
settings:
CPU: ARMv7
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 079ea0ed741ff194a80cce029630b5ac
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 038a89637b659e346a7a712ce0c9271b
timeCreated: 1451443249
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 1
settings:
CPU: x86
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
......@@ -38,6 +38,8 @@ MonoBehaviour:
- HighlightingSystem
- SplineMeshRenderer
- RTVoice
- Xlua.Core
- Xlua.Core.Editor
showAdvancedSettings: 0
addMgrToSceneAutomatically: 0
autoUpdateReferences: 1
......
fileFormatVersion: 2
guid: 9f21eb6fdfabde148baa62a0099ab0fa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e6375603a0a1e2647b0c426b27646eb7
folderAsset: yes
timeCreated: 1490146877
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: cb3d94d8757d66b40b20f0386b52d01d
timeCreated: 1490146878
licenseType: Free
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
WindowsStoreApps:
enabled: 1
settings:
CPU: ARM
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bb7408ba78d6c984faa01af51e3a9c8f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 61b7a98d0d7fa7547bfeccc24ee36192
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4d5a7116d7e9a33409205303635b8635
folderAsset: yes
timeCreated: 1490146877
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a73864467778862409da51f9feb60004
timeCreated: 1490146878
licenseType: Free
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
WindowsStoreApps:
enabled: 1
settings:
CPU: x64
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6e0f35de38a8ed24fa8b20d444c9ee5e
folderAsset: yes
timeCreated: 1490146877
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3fd23a6414095674493657a67a8043a1
timeCreated: 1489995544
licenseType: Free
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
WindowsStoreApps:
enabled: 1
settings:
CPU: x86
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: be28a771453cd644cb81ab1f6ba7fc42
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
extern "C" {
#include "../../../WebGLPlugins/lapi.c"
#include "../../../WebGLPlugins/lauxlib.c"
#include "../../../WebGLPlugins/lbaselib.c"
#include "../../../WebGLPlugins/lbitlib.c"
#include "../../../WebGLPlugins/lcode.c"
#include "../../../WebGLPlugins/lcorolib.c"
#include "../../../WebGLPlugins/lctype.c"
#include "../../../WebGLPlugins/ldblib.c"
#include "../../../WebGLPlugins/ldebug.c"
#include "../../../WebGLPlugins/ldo.c"
#include "../../../WebGLPlugins/ldump.c"
#include "../../../WebGLPlugins/lfunc.c"
#include "../../../WebGLPlugins/lgc.c"
#include "../../../WebGLPlugins/linit.c"
#include "../../../WebGLPlugins/liolib.c"
#include "../../../WebGLPlugins/llex.c"
#include "../../../WebGLPlugins/lmathlib.c"
#include "../../../WebGLPlugins/lmem.c"
#include "../../../WebGLPlugins/loadlib.c"
#include "../../../WebGLPlugins/lobject.c"
#include "../../../WebGLPlugins/lopcodes.c"
#include "../../../WebGLPlugins/loslib.c"
#include "../../../WebGLPlugins/lparser.c"
#include "../../../WebGLPlugins/lstate.c"
#include "../../../WebGLPlugins/lstring.c"
#include "../../../WebGLPlugins/lstrlib.c"
#include "../../../WebGLPlugins/ltable.c"
#include "../../../WebGLPlugins/ltablib.c"
#include "../../../WebGLPlugins/ltm.c"
#include "../../../WebGLPlugins/lundump.c"
#include "../../../WebGLPlugins/lutf8lib.c"
#include "../../../WebGLPlugins/lvm.c"
#include "../../../WebGLPlugins/lzio.c"
#include "../../../WebGLPlugins/i64lib.c"
#include "../../../WebGLPlugins/perflib.c"
#include "../../../WebGLPlugins/xlua.c"
}
fileFormatVersion: 2
guid: 92f9773841d5ffd44b794b9b584a5c05
timeCreated: 1504062948
licenseType: Pro
PluginImporter:
serializedVersion: 2
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
data:
first:
Any:
second:
enabled: 0
settings: {}
data:
first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
data:
first:
Facebook: WebGL
second:
enabled: 1
settings: {}
data:
first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 00e39ac7f26a9a24586e1cb7186555e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 27cd65c4cc42b42f49caa94f462466de
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 0
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: ARM64
DefaultValueInitialized: true
OS: AnyOS
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 1
settings:
CPU: ARM64
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: x86_64
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c2dd93e84d2c4834d8b79b34b078a46f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
#include <stddef.h>
#include <stdlib.h>
int* xlua_hotfix_flags = NULL;
int xlua_hotfix_flags_len = 0;
extern "C" {
int xlua_get_hotfix_flag(int idx) {
if (idx >= xlua_hotfix_flags_len) {
return 0;
} else {
return xlua_hotfix_flags[idx];
}
}
void xlua_set_hotfix_flag(int idx, int flag) {
int i = 0;
int* new_hotfix_flags = NULL;
if (idx >= xlua_hotfix_flags_len) {
if (xlua_hotfix_flags == NULL) {
xlua_hotfix_flags = (int*)malloc((idx + 1) * sizeof(int));
} else {
new_hotfix_flags = (int*)realloc(xlua_hotfix_flags, (idx + 1) * sizeof(int));
if (NULL == new_hotfix_flags) { // just skip operation
return;
}
xlua_hotfix_flags = new_hotfix_flags;
}
for(i = xlua_hotfix_flags_len; i < (idx + 1); i++) {
xlua_hotfix_flags[i] = 0;
}
xlua_hotfix_flags_len = idx + 1;
}
xlua_hotfix_flags[idx] = flag;
}
}
fileFormatVersion: 2
guid: ef0ed550afe43d449b58d883fad0585c
timeCreated: 1498103331
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
iOS:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 2d65468f3356ca741b3fbebea91dfb6c
timeCreated: 1451443249
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
iOS:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8b104577afc987b45acf6ee5cb2cd57c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9f19d785ae44ddc478a08a87ccd9dbb2
timeCreated: 1488352111
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: x86
DefaultValueInitialized: true
OS: AnyOS
Linux:
enabled: 1
settings:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: None
LinuxUniversal:
enabled: 1
settings:
CPU: x86
OSXIntel:
enabled: 0
settings:
CPU: None
OSXIntel64:
enabled: 0
settings:
CPU: None
OSXUniversal:
enabled: 0
settings:
CPU: None
WP8:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
Win:
enabled: 1
settings:
CPU: AnyCPU
Win64:
enabled: 0
settings:
CPU: None
WindowsStoreApps:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
SDK: AnySDK
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 79f5c811b2e4e444ab2d97cad5cfd934
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: x86
DefaultValueInitialized: true
OS: Windows
Linux:
enabled: 1
settings:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: None
LinuxUniversal:
enabled: 0
settings:
CPU: x86
OSXIntel:
enabled: 1
settings:
CPU: AnyCPU
OSXIntel64:
enabled: 0
settings:
CPU: None
OSXUniversal:
enabled: 0
settings:
CPU: x86
WP8:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
Win:
enabled: 1
settings:
CPU: AnyCPU
Win64:
enabled: 0
settings:
CPU: None
WindowsStoreApps:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
SDK: AnySDK
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b1827a4a6649eb04d8f233b9a0e73a0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1055830ddb882704fa71275ed9b2a78d
timeCreated: 1488352111
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: x86_64
DefaultValueInitialized: true
OS: AnyOS
Linux:
enabled: 0
settings:
CPU: None
Linux64:
enabled: 1
settings:
CPU: x86_64
LinuxUniversal:
enabled: 1
settings:
CPU: x86_64
OSXIntel:
enabled: 0
settings:
CPU: None
OSXIntel64:
enabled: 0
settings:
CPU: None
OSXUniversal:
enabled: 0
settings:
CPU: None
WP8:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
Win:
enabled: 0
settings:
CPU: None
Win64:
enabled: 1
settings:
CPU: AnyCPU
WindowsStoreApps:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
SDK: AnySDK
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: abe4c5ca91772ea4fae0ae15603c10e4
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: x86_64
DefaultValueInitialized: true
OS: Windows
Linux:
enabled: 0
settings:
CPU: None
Linux64:
enabled: 1
settings:
CPU: x86_64
LinuxUniversal:
enabled: 0
settings:
CPU: x86_64
OSXIntel:
enabled: 0
settings:
CPU: None
OSXIntel64:
enabled: 1
settings:
CPU: AnyCPU
OSXUniversal:
enabled: 0
settings:
CPU: x86_64
WP8:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
Win:
enabled: 0
settings:
CPU: None
Win64:
enabled: 1
settings:
CPU: AnyCPU
WindowsStoreApps:
enabled: 0
settings:
CPU: AnyCPU
DontProcess: False
PlaceholderPath:
SDK: AnySDK
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f069902e2c4dee7409d0a63fdd1b100d
folderAsset: yes
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
DefaultValueInitialized: true
- first:
Standalone: OSXUniversal
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7e4b7549f5e4a4e71806e3ec8e428b15
folderAsset: yes
timeCreated: 1457422691
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15G31</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>xlua</string>
<key>CFBundleIdentifier</key>
<string>com.xlua</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>xlua</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>7D1014</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>15E60</string>
<key>DTSDKName</key>
<string>macosx10.11</string>
<key>DTXcode</key>
<string>0731</string>
<key>DTXcodeBuild</key>
<string>7D1014</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright @2017 THL A29 Limited, a Tencent company. All rights reserved.</string>
</dict>
</plist>
fileFormatVersion: 2
guid: ac30af4fb2add4d41a9f50fe4f8292a3
timeCreated: 1457422749
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c9d8e68fa0fd1465294f1255f6ed8563
folderAsset: yes
timeCreated: 1457422691
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6f3b1cda03ac84924b1ee0595fc019f5
timeCreated: 1457422749
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -65,6 +65,7 @@ public class ZeusHub_Manager : MonoBehaviour
public GameObject downloadpage;
public GameObject noticePage;
IEnumerator Start()
{
manager = this;
......
using System.Windows.Forms;
using TMPro;
using UnityEngine;
using XLua;
public class NoticeData : MonoBehaviour
{
// Start is called before the first frame update
public string id;
public TMP_Text notice_area;
public TMP_Text title;
public TMP_Text date;
public string html;
public ZeusHub_Manager manager;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void setHtml()
{
Debug.Log(manager);
Debug.Log(manager.noticePage);
manager.noticePage.SetActive(true);
manager.noticePage.GetComponent<NoticeData>().notice_area.text = html;
}
}
fileFormatVersion: 2
guid: 3f16f783c36e1d04ab3a177221b8d8f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using LitJson;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class NoticeRowData : MonoBehaviour
{
// Start is called before the first frame update
public GameObject RowPrefab;
public GameObject content;
public ZeusHub_Manager manager;
public AnalysisHtml5Tools analysisHtml5 = new AnalysisHtml5Tools();
void Start()
{
/* while (!manager)
{
manager = ZeusHub_Manager.manager;
break;
}*/
}
// Update is called once per frame
void Update()
{
}
public void setData()
{
StartCoroutine(getlist("/zeus/zeushub/getnoticeList"));
}
public IEnumerator getlist(string api)
{
del();
yield return null;
Debug.Log(api);
var rq = UnityWebRequest.Get(Setting.IP + api);
using (rq)
{
if (manager.token != null)
{
rq.SetRequestHeader("Authorization", manager.token);
}
rq.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
yield return rq.SendWebRequest();
if (string.IsNullOrEmpty(rq.error))
{
JsonData jd = JsonMapper.ToObject<JsonData>(rq.downloadHandler.text);
Debug.Log(rq.downloadHandler.text);
if (jd != null && jd.ContainsKey("rows"))
{
foreach (JsonData item in jd["rows"])
{
var newObj = Instantiate(RowPrefab) as GameObject;
newObj.transform.SetParent(content.transform);
NoticeData noticeData = newObj.GetComponent<NoticeData>();
noticeData.title.text = item["title"].ToString();
noticeData.date.text = item["created"].ToString();
//noticeData.html = item["field_notice_info"].ToString();
noticeData.manager = this.manager;
noticeData.html = analysisHtml5.AnalysisRichTextMethod(item["field_notice_info"].ToString());
newObj.transform.localScale = new Vector3(1, 1, 1);
}
}
}
else
{
Debug.Log(rq.error);
//OnReceiveMsg.Invoke(new PlanData() { code = 0, result = new PlanData.Result() { planIncompleteCount = 10,planTotalCount=12 } }, $"{type},{time}");
}
}
}
void del()
{
if (content.transform.childCount > 0)
{
for (int j = 0; j < content.transform.childCount; j++)
{
Destroy(content.transform.GetChild(j).gameObject);
}
}
}
}
fileFormatVersion: 2
guid: 908ed5a116b9dde4ba7d9f37556d8d72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;
public class AnalysisHtml5Tools
{
public delegate string AnalysisRichText(string richText);
// Start is called before the first frame update
void Start()
{
}
/// <summary>
/// 解析html富文本的方法
/// </summary>
/// <param name="richText">html富文本字符串</param>
/// <returns>解析后字符串</returns>
public string AnalysisRichTextMethod(string richText)
{
LuaEnv luaEnv = new LuaEnv();
luaEnv.AddLoader(myLoader);
//string text1 = "<p><br/></p><p style=\"text-align: center;\"><strong>课程介绍</strong></p><p><strong><br/></strong></p><p style=\"text-align: center;\">一起来创作吧~</p>";
luaEnv.DoString("require 'main'");
AnalysisRichText func1 = luaEnv.Global.Get<AnalysisRichText>("Test");
//去掉开头的换行
//richText = richText.Substring(11);
//string exText = richText;
//手动去掉style样式的方法
string[] parames = richText.Split('"');
int index = 0;
string tem = "";
foreach (string parame in parames)
{
if (index % 2 == 0 && !parame.Contains("text"))
{
tem += parame;
}
}
//去掉style=
string[] tem1 = tem.Split(' ');
string tem2 = "";
foreach (string parame in tem1)
{
if (parame.Contains("style"))
{
tem2 += parame.Substring(parame.IndexOf("style") + 6, parame.Length - 6);
}
else tem2 += parame;
}
string luaText = func1(tem2);
return luaText;
}
public byte[] myLoader(ref string filePath)
{
string path = Application.streamingAssetsPath + "/" + filePath + ".lua";
return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
}
}
fileFormatVersion: 2
guid: e3b1553658179f24c899746a221e2e63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
--[[
Author: 石英男
Github: https://gitee.com/anshun_xun_yu_network/doudizhu3d_client.git
Date: 2021-07-08 10:18:25
LastEditors: 石英男
LastEditTime: 2021-07-09 17:54:07
Description:
--]]
local HtmlTool = {}
--以P标签进行分段存储的字符串
local pTab = {}
local spanIndexTab = {}
local SpecialSymbolsTab = {
{specialSymbols = "%&lt;", rightStr = "<"},
{specialSymbols = "%&gt;", rightStr = ">"},
{specialSymbols = "%&amp;", rightStr = "&"},
{specialSymbols = "%&quot;", rightStr = "“"},
{specialSymbols = "%&reg;", rightStr = "®"},
{specialSymbols = "%&copy;", rightStr = "©"},
{specialSymbols = "%&trade;", rightStr = "™"},
{specialSymbols = "<br/>", rightStr = "\n"},
{specialSymbols = "&nbsp;", rightStr = ""},
{specialSymbols = "<strong>", rightStr = "<b>"},
{specialSymbols = "</strong>", rightStr = "</b>"}
}
local specialSymbolsIndex = 1
function Test(richText)
local result = ""
result = HtmlTool:HtmlToLua(richText)
return result
end
--[[
@description: 将传入的html格式的语言转换成unity可识别的富文本string
@param {tempStr 传入的string 值}
@return {*}
--]]
function HtmlTool:HtmlToLua(tempStr)
local result = ""
pTab = {}
self:SubStrByPFlag(tempStr)
if next(pTab) == nil then
return tempStr
end
for index, value in ipairs(pTab) do
result = string.gsub(result .. self:Justgsub(value), "<p>", "")
result = string.gsub(result, "</p>", "\n")
result = self:GSubSpecialSymbols(result)
end
return result
end
--[[
@description: 以P标签进行分段
@param {*}
@return {*}
--]]
function HtmlTool:SubStrByPFlag(tempStr)
if string.len(tempStr) <= 0 then
return
end
local startIndex = string.find(tempStr, "<p>")
local endIndex = string.find(tempStr, "</p>")
if startIndex == nil then
return
end
if endIndex == nil then
DebugError("不存在</p>,请检查格式不存在</p>,请检查格式不存在</p>,请检查格 式不存在</p>,请检查格式不 存在</p>,请检查 格式 不存在</p>,请检查格式")
return
end
local temp = string.sub(tempStr, startIndex, endIndex + 3)
local leftStr = string.sub(tempStr, endIndex + 4, -1)
table.insert(pTab, temp)
self:SubStrByPFlag(leftStr)
end
local typeStr1 = ' class="ql%-size%-small"'
local typeStr2 = ' class="ql%-size%-large"'
local typeStr3 = ' class="ql%-size%-huge"'
local typeStr4 = ' style="color: rgb%([0-9]+, [0-9]+, [0-9]+%);"'
local spanTable = {
{spanStr = "<span" .. typeStr1 .. ">", spanType = 1, rightStr = "<size=10>", typeName = "</size>"},
{spanStr = "<span" .. typeStr2 .. ">", spanType = 1, rightStr = "<size=18>", typeName = "</size>"},
{spanStr = "<span" .. typeStr3 .. ">", spanType = 1, rightStr = "<size=32>", typeName = "</size>"},
{
spanStr = "<span" .. typeStr4 .. ">",
spanType = 2,
rightStr = "",
typeName = "</color>"
},
{
spanStr = "<span" .. typeStr1 .. typeStr4 .. ">",
spanType = 12,
rightStr = "<size=10>",
typeName = "</color></size>"
},
{
spanStr = "<span" .. typeStr2 .. typeStr4 .. ">",
spanType = 12,
rightStr = "<size=14>",
typeName = "</color></size>"
},
{
spanStr = "<span" .. typeStr3 .. typeStr4 .. ">",
spanType = 12,
rightStr = "<size=18>",
typeName = "</color></size>"
},
{
spanStr = "<span" .. typeStr4 .. typeStr1 .. ">",
spanType = 21,
rightStr = "<size=10>",
typeName = "</size></color>"
},
{
spanStr = "<span" .. typeStr4 .. typeStr2 .. ">",
spanType = 21,
rightStr = "<size=14>",
typeName = "</size></color>"
},
{
spanStr = "<span" .. typeStr4 .. typeStr3 .. ">",
spanType = 21,
rightStr = "<size=18>",
typeName = "</size></color>"
}
}
--[[
@description: 递归的替换html中的span标签
@param {*}
@return {*}
--]]
function HtmlTool:Justgsub(tempStr)
if string.len(tempStr) <= 0 then
return
end
local type0 = string.find(tempStr, "</span>")
local result = tempStr
if type0 == nil then
return result
end
return self:func2(tempStr, result, type0)
-- return self:func1(tempStr, result, type0)
end
--[[
@description: 遍历数组去找
@param {*}
@return {*}
--]]
function HtmlTool:func2(tempStr, result, type0)
for index, value in ipairs(spanTable) do
local tempType = string.find(tempStr, value.spanStr)
if tempType then
if type0 > tempType then
if value.spanType == 1 then
result = string.gsub(tempStr, value.spanStr, value.rightStr, 1)
table.insert(spanIndexTab, {typeName = value.typeName, index = tempType})
end
if value.spanType == 2 then
local finallynum = ""
finallynum= self:GetColor(tempStr,value.spanStr)
result = string.gsub(tempStr, value.spanStr, finallynum .. ">", 1)
table.insert(spanIndexTab, {typeName = "</color>", index = tempType})
end
if value.spanType == 12 then
local finallynum = ""
finallynum= self:GetColor(tempStr,typeStr4)
result = string.gsub(tempStr, value.spanStr, value.rightStr .. finallynum .. ">", 1)
table.insert(spanIndexTab, {typeName = "</color></size>", index = tempType})
end
if value.spanType == 21 then
local finallynum = ""
finallynum= self:GetColor(tempStr,typeStr4)
result = string.gsub(tempStr, value.spanStr, finallynum .. ">" .. value.rightStr, 1)
table.insert(spanIndexTab, {typeName = "</size></color>", index = tempType})
end
return self:Justgsub(result)
else
if next(spanIndexTab) ~= nil then
result = string.gsub(tempStr, "</span>", table.remove(spanIndexTab, 1).typeName, 1)
end
end
else
if next(spanIndexTab) ~= nil then
result = string.gsub(tempStr, "</span>", table.remove(spanIndexTab, 1).typeName, 1)
end
end
end
return self:Justgsub(result)
end
--[[
@description: 得到颜色的16位表达结果
@param {*}
@return {*}
--]]
function HtmlTool:GetColor(tempStr,spanStr)
local colorStr = string.match(tempStr,spanStr)
local numStr = string.match(colorStr, "[0-9]+, [0-9]+, [0-9]+")
local strList = string.split(numStr, ", ")
local finallynum = "<color=#"
for index, value in ipairs(strList) do
finallynum = finallynum .. string.format("%02X", value)
end
return finallynum
end
--[[
@description: 替换特殊符号
@param {*}
@return {*}
--]]
function HtmlTool:GSubSpecialSymbols(tempStr)
if specialSymbolsIndex > #SpecialSymbolsTab then
specialSymbolsIndex = 1
return tempStr
end
if string.find(tempStr, SpecialSymbolsTab[specialSymbolsIndex].specialSymbols) then
tempStr =
string.gsub(
tempStr,
SpecialSymbolsTab[specialSymbolsIndex].specialSymbols,
SpecialSymbolsTab[specialSymbolsIndex].rightStr
)
else
specialSymbolsIndex = specialSymbolsIndex + 1
end
return self:GSubSpecialSymbols(tempStr)
end
--[[
@description: 替换字符
@param {*}
@return {*}
--]]
function HtmlTool:String_conversion(value)
local path = ""
for i = 1, #value do
--获取当前下标字符串
local tmp = string.sub(value, i, i)
--如果为'\\'则替换
if tmp == "\\" then
path = path .. "/"
elseif tmp == '"' then
path = path .. ""
else
path = path .. tmp
end
end
return path
end
return HtmlTool
fileFormatVersion: 2
guid: 9c25899c11be733419329735a4851b44
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: af1c80a0c1726a34d90b4eba95e29446
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: be3fe4ee249c5274693e7b6f8053e861
timeCreated: 1470364015
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 67edfc4b640373846b14362bf8769576
folderAsset: yes
DefaultImporter:
userData:
## What & Why
XLua's currently built-in extension libraries:
* LuaJIT support for 64-bit integers;
* Positioning tool for function call times and memory leaks;
* LuaSocket library for supporting ZeroBraneStudio;
* tdr 4 lua;
With the increasing extensiveness and intensiveness of project use, the current extension libraries have been unable to meet the project team needs. Since various projects require very different extension libraries, and since mobile phone platforms are sensitive to the size of the installation package, xLua is unable to meet these needs through pre-integration. That is why we are offering this tutorial.
In this tutorial, we will use lua-rapidjson as an example to explain step by step how to add C/C++ extensions to xLua. Once you know how to add them, you will also know how to delete them naturally. The project team can delete those pre-integrated extensions if they are not used any more.
## How it is done
There are three steps:
1. Modify the build file and project settings. Compile the extensions you want to integrate into the XLua Plugin directory.
2. Call the C# APIs on xLua so that the extensions can be loaded as needed (when required in the Lua code).
3. (Optional) If you need to use 64-bit integers in your extensions, you can use xLua's 64-bit extension library to work with C#.
### First, add extensions & compile.
Preparations
1. Extract the xLua’s C source code package to the same level directory as the Assets of your Unity project.
Download the lua-rapidjson code and place it anywhere you like. In this tutorial, we place the rapidjson header file in the $UnityProj\build\lua-rapidjson\include directory, and place the extended source code rapidjson.cpp in the $UnityProj\build\lua-rapidjson\source directory (Note: $UnityProj refers to your project directory).
2. Add extensions to CMakeLists.txt
xLua’s platform Plugins are compiled using CMake. The advantage of this is that the compilations of all platforms are written in a makefile, and most compilation processing logic is cross-platform.
XLua's CMakeLists.txt provides extension points (all lists) for third-party extensions:
1. THIRDPART_INC: Third-party extension header search path.
2. THIRDPART_SRC: Third-party extended source code.
3. THIRDPART_LIB: The library on which third-party extensions rely.
The following is added with RapidJSON:
#begin lua-rapidjson
set (RAPIDJSON_SRC lua-rapidjson/source/rapidjson.cpp)
set_property(
SOURCE ${RAPIDJSON_SRC}
APPEND
PROPERTY COMPILE_DEFINITIONS
LUA_LIB
)
list(APPEND THIRDPART_INC lua-rapidjson/include)
set (THIRDPART_SRC ${THIRDPART_SRC} ${RAPIDJSON_SRC})
#end lua-rapidjson
See the attachment for the complete code.
3. Compile platforms
All compiled scripts are named with this format: make_platform_lua version.extension name.
For example, the name of the Windows 64-bit Lua 5.3 version is make_win64_lua53.bat, and the name of the Android LuaJIT version is make_android_luajit.sh. you can execute the corresponding script to compile the target version.
The compiled scripts are automatically copied to the plugin_lua53 or plugin_luajit directory. The former is for Lua 5.3 and the latter for LuaJIT.
The supporting Android script is used on Linux. The NDK path at the beginning of the script must be modified accordingly.
### Second, C# side integration:
Each C extension library on Lua will provide a function, luaopen_xxx, where xxx is the name of the dynamic library. For example, the function for the Lua-RapidJSON library is luaopen_rapidjson. Such functions are automatically called by the Lua virtual machine when loading the dynamic library. In the mobile platform, we cannot load the dynamic library due to iOS restrictions. They are compiled directly into the process instead.
For this purpose, xLua provides an API to replace this feature (LuaEnv's member methods):
public void AddBuildin(string name, LuaCSFunction initer)
Parameters:
Name: name of the buildin module, a parameter entered during require;
initer: the initialization function; Its prototype is public delegate int lua_CSFunction(IntPtr L); This must be a static function and be modified with the property MonoPInvokeCallbackProperty; This API will check these two conditions.
We use calling luaopen_rapidjson to show how to use it.
Extend the LuaDLL.Lua type, export luaopen_rapidjson to C# via pinvoke, and then write a static function that satisfies the definition of lua_CSFunction. You can write initialization work in it, such as calling luaopen_rapidjson. Here is the complete code:
namespace LuaDLL
{
public partial class Lua
{
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_rapidjson(System.IntPtr L);
[MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
public static int LoadRapidJson(System.IntPtr L)
{
return luaopen_rapidjson(L);
}
}
}
Then call AddBuildin:
luaenv.AddBuildin("rapidjson", LuaDLL.Lua.LoadRapidJson);
After this, it should work properly. Try the extension in the Lua code:
local rapidjson = require('rapidjson')
local t = rapidjson.decode('{"a":123}')
print(t.a)
t.a = 456
local s = rapidjson.encode(t)
print('json', s)
### Third, 64-bit transformation
Include the i64lib.h file in a file that requires a 64-bit transformation.
The header file include these APIs:
//Place an int64 on stack/uint64
void lua_pushint64(lua_State* L, int64_t n);
void lua_pushuint64(lua_State* L, uint64_t n);
//Judge whether int64 is at the pos position on stack/uint64
int lua_isint64(lua_State* L, int pos);
int lua_isuint64(lua_State* L, int pos);
//Get an int64 from the pos position on stack/uint64
int64_t lua_toint64(lua_State* L, int pos);
uint64_t lua_touint64(lua_State* L, int pos);
The usage of these APIs varies depending on the actual situation. See the attached file (rapidjson.cpp file).
Compile project related modifications
fileFormatVersion: 2
guid: 0ae08314c9c889249bbd484254109060
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
# XLua configuration
All xLua configurations support three methods: tagging, static lists, and dynamic lists.
There are two requirements and two recommended items for configuration:
* List mode must use static fields/properties.
* List mode must be placed in a static type.
* Using tagging is not recommended.
* Placing the list mode configuration in the Editor directory is recommended.
**Tagging**
xLua uses a whitelist to indicate which code is to be generated, and the whitelist is configured via attributes. For example, if you want to call a C# type from Lua or you want to generate the adaptation code, you can add a LuaCallCSharp tag for this type:
~~~csharp
[LuaCallCSharp]
publicclassA
{
}
~~~
This mode is convenient, but it will increase the code on the il2cpp and therefore is not recommended.
**Static list**
Sometimes we cannot directly tag a type, such as a system API, a library without source code, or an instantiated generic type. In this case, you can declare a static field in a static type. This field can be any type except for BlackList and AdditionalProperties, as long as IEnumerable&lt;Type&gt; is implemented (these two exceptions will be specifically described later). Then add a tag to this field:
~~~csharp
[LuaCallCSharp]
public static List<Type> mymodule_lua_call_cs_list = new List<Type>()
{
typeof(GameObject),
typeof(Dictionary<string, int>),
};
~~~
This field needs to be placed in a **static type** and placing it in the **Editor directory** is recommended.
**Dynamic list**
Declare a static property and tag it accordingly.
~~~csharp
[Hotfix]
public static List<Type> by_property
{
get
{
return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
where type.Namespace == "XXXX"
select type).ToList();
}
}
~~~
Getter is code. You can use it to implement a lot of results, such as configuration by namespace, configuration by assembly, and so on.
This property needs to be placed in a **static type** and placing it in the **Editor directory** is recommended.
### XLua.LuaCallCSharp
When adding this configuration for a C# type, xLua will generate the adapter code for this type (including constructing an instance for the type, and accessing its member properties & methods and static properties & methods). Otherwise, it will try to gain access using the reflection mode with lower performance.
Adding this configuration to the Extension Methods of a type will also generate the adaptation code and append it to the member methods of the extended type.
XLua will only generate the type loaded with this configuration. It will not automatically generate the adaptation code of its parent type. When accessing the parent type method of the child type object, if the parent type has the LuaCallCSharp configuration, the parent type's adaptation code will be executed. Otherwise it will try to gain access using the reflection mode.
The reflection mode access not only has poor performance, but also may cause failed access on the il2cpp due to code stripping. This problem can be avoided through the ReflectionUse tag, which is described below.
### XLua.ReflectionUse
When adding this configuration to a C# type, xLua generates a link.xml to block code stripping on the il2cpp.
For extension methods, you must add LuaCallCSharp or ReflectionUse to make them accessible.
It is recommended that all types to be accessed in Lua have the LuaCallCSharp or ReflectionUse tag, to insure their proper operation on all platforms.
### XLua.DoNotGen
This indicates that some of the functions, fields, and properties in a type do not generate code and are accessed through the reflection mode.
Only the fields or properties in the standard Dictionary<Type, List<string>> can be used. The key indicates the effective type. Value is a list. The name of the functions, fields, and properties with no code generated are configured.
The differences from ReflectionUse are: 1. ReflectionUse specifies the entire type; 2. Upon the first access to a function (field, property), ReflectionUse will wrap the entire type, while DoNotGen will only wrap the function (field, property). In other words, DoNotGen is lazier.
The differences from BlackList are: 1. BlackList cannot be used when it is configured. 2. BlackList can specify an overloaded function, while DoNotGen cannot.
### XLua.CSharpCallLua
This allows you to adapt a Lua function to a C# delegate (one scenario is various callbacks at the C# side: UI events, delegate parameters, such as List&lt;T&gt;:ForEach; another scenario is to use the Get function of LuaTable to indicate that a Lua function is bound to a delegate), or to adapt a Lua table to a C# interface. The delegate or interface needs this configuration.
### XLua.GCOptimize
A C# pure value type (Note: It refers to a struct that contains only the value type, and it can nest other structs that contain only the value type) or a C# enumerated value has this configuration. xLua generates gc-optimized code for this type. The result is that the value type is passed between Lua and C# with no (C#)gc alloc generated, and that no gc is generated during array access to this type. For various GC-free scenarios, refer to the 05\_NoGc example.
Any type except enumeration (including the complex types that contain parameterless constructors) will generate Lua tables for that type, as well as the conversion code of a one-dimensional array with modified type. This will optimize the performance of this conversion, including fewer gc allocs.
### XLua.AdditionalProperties
This is GCOptimize's extended configuration. Sometimes, some structs want to make the field private and access the field through the property. In this case, you need to use this configuration (by default, GCOptimize only packetizes/depacketizes the public field).
The tagging mode is relatively simple and the configuration mode is complicated. The requirements are that Dictionary&lt;Type, List&lt;string&gt;&gt; type, and the Key of the Dictionary are effective types; and value is the list of property names. See xLua's configuration of several UnityEngine value types and the SysGCOptimize type.
### XLua.BlackList
If you do not want to generate an adaption code for a member of a type, you can implement it with this configuration.
The tagging method is relatively simple, and the corresponding member can be added.
Considering that it may be necessary to add one of the overloaded functions to the blacklist, the configuration is more complicated. The type is List&lt;List&lt;string&gt;&gt;. For each member, the first-level list has only one entry and the second-level list is a string list. The first string is the full path name of the type, the second string is the member name. If the member is a method, you also need to list the full path of the type of its parameters starting from the third string.
For example, the following adds a property of GameObject and a method of FileInfo to the blacklist:
~~~csharp
[BlackList]
public static List<List<string>> BlackList = new List<List<string>>() {
new List<string>(){"UnityEngine.GameObject", "networkView"},
//new List<string>(){ typeof(UnityEngine.GameObject).FullName, "networkView"},
new List<string>(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
//new List<string>(){ typeof(System.IO.FileInfo).FullName, "GetAccessControl",typeof(System.Security.AccessControl.AccessControlSections).FullName },
};
~~~
### The following is the generator configuration, which must be placed in the Editor directory.
### CSObjectWrapEditor.GenPath
Configures the path of the generated code, with the type being a string. By default, it is plated in &quot;Assets/XLua/Gen/&quot;.
### CSObjectWrapEditor.GenCodeMenu
This configuration is used for secondary development of the build engine. When adding this tag to a parameterless function, it will trigger calling the function when executing the &quot;XLua/Generate Code&quot; menu.
fileFormatVersion: 2
guid: 198070d8475ff3043b6c72a906feebee
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
## Secondary development of the build engine
xLua's build engine supports secondary development, and you can use it to generate some text files (for example, code and configuration files). The xLua's link.xml file is generated by the build engine plugin. Other application scenarios (such as generating a Lua IDE auto configuration file) can also be accomplished using this feature.
## Overview
The plugin needs to provide two things: 1. a template for generated files, 2. a callback function that accepts the user configuration and returns the data that needs to be injected into the template and the output stream of the files.
## Template syntax
The template syntax is simple, with only three elements:
* eval: The syntax is <%=exp%>. Exp is an arbitrary expression that will calculate and output the value of exp as a string.
* Code: The syntax is <% if true then end%>. The blue part is any Lua code that will be executed.
* Literal: This contains the parts other than eval and code. Literal means output as it is.
Example:
~~~xml
<%
require "TemplateCommon"
%>
<linker>
<%ForEachCsList(assembly_infos, function(assembly_info)%>
<assembly fullname="<%=assembly_info.FullName%>">
<%ForEachCsList(assembly_info.Types, function(type)
%><type fullname="<%=type:ToString()%>" preserve="all"/>
<%end)%>
</assembly>
<%end)%>
</linker>
~~~
TemplateCommon has some predefined functions that can be used (for example ForEachCsList). You can search in TemplateCommon.lua.txt of the project to see which functions are available. For ordinary Lua, you can write one.
## API
~~~csharp
public static void CSObjectWrapEditor.Generator.CustomGen(string template_src, GetTasks get_tasks)
~~~
* template_src: template source code
* get_tasks: This is a callback function. The type is GetTasks. This function is used to accept the user configuration and return the data that needs to be injected into the template and the output stream of the files.
~~~csharp
public delegate IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg);
~~~
* lua_env: This is a LuaEnv object. Because the returned template data needs to be placed in LuaTable, LuaEnv.NewTable is required.
* user_cfg: user configuration
* return: Among the returned values, CustomGenTask represents a generated file, and IEnumerable type indicates that the same template can generate multiple files.
~~~csharp
public struct UserConfig
{
public IEnumerable<Type> LuaCallCSharp;
public IEnumerable<Type> CSharpCallLua;
public IEnumerable<Type> ReflectionUse;
}
~~~
~~~csharp
public struct CustomGenTask
{
public LuaTable Data;
public TextWriter Output;
}
~~~
Example:
~~~csharp
public static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg)
{
LuaTable data = lua_env.NewTable();
var assembly_infos = (from type in user_cfg.ReflectionUse
group type by type.Assembly.GetName().Name into assembly_info
select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList();
data.Set("assembly_infos", assembly_infos);
yield return new CustomGenTask
{
Data = data,
Output = new StreamWriter(GeneratorConfig.common_path + "/link.xml",
false, Encoding.UTF8)
};
}
~~~
* Only one file is generated here, so only one CustomGenTask is returned.
* data is the data to be used in the template. There is an assembly_infos field included. See the template section for how to use this field.
## Tag
Generally speaking, you can use MenuItem to create a menu to trigger a custom generate operation. However, sometimes you may want the generate operation to be triggered directly by the xLua "Generate Code" menu. In this situation, you will need to use CSObjectWrapEditor.GenCodeMenu
Example:
~~~csharp
[GenCodeMenu]//加到Generate Code菜单里头
public static void GenLinkXml()
{
Generator.CustomGen(ScriptableObject.CreateInstance<LinkXmlGen>().Template.text, GetTasks);
}
~~~
PS: All the code related to the content above is in the XLua\Src\Editor\LinkXmlGen directory, which is also the implementation of the link.xml generation function that was explained at the beginning.
fileFormatVersion: 2
guid: c0765c3c416e8f746bf142b05be65ea7
timeCreated: 1529661500
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 7b6232183a3c52f4f9af4b68f8a687cc
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 7919d0bddff7ee340852008d36cd68ec
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ee1eae11fbe87b04193ab2c3d15ba2b3
folderAsset: yes
timeCreated: 1481715983
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: logo
m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 6b9f4e2e38c36db40bc5bdfe20038d94, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats: []
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: 953e2ba39b9a2d54388919b75877efb7
NativeFormatImporter:
userData:
fileFormatVersion: 2
guid: f05e875da3e1b3844b2360d177d617c9
DefaultImporter:
userData:
## C# API
### LuaEnv类
#### object[] DoString(string chunk, string chunkName = "chuck", LuaTable env = null)
描述:
执行一个代码块。
参数:
chunk: Lua代码的字符串;
chunkName: 发生error时的debug显示信息中使用,指明某某代码块的某行错误;
env :这个代码块的环境变量;
返回值:
代码块里return语句的返回值;
比如:return 1, “hello”,DoString返回将包含两个object的数组, 一个是double类型的1, 一个是string类型的“hello”
例如:
LuaEnv luaenv = new LuaEnv();
object[] ret = luaenv.DoString("print(‘hello’)\r\nreturn 1")
UnityEngine.Debug.Log("ret="+ret[0]);
luaenv.Dispose()
#### T LoadString<T>(string chunk, string chunkName = "chunk", LuaTable env = null)
描述:
加载一个代码块,但不执行,只返回类型可以指定为一个delegate或者一个LuaFunction
参数:
chunk: Lua代码的字符串;
chunkName: 发生error时的debug显示信息中使用,指明某某代码块的某行错误;
env :这个代码块的环境变量;
返回值:
代表该代码块的delegate或者LuaFunction类;
#### LuaTable Global;
描述:
代表lua全局环境的LuaTable
### void Tick()
描述:
清除Lua的未手动释放的LuaBase对象(比如:LuaTable, LuaFunction),以及其它一些事情。
需要定期调用,比如在MonoBehaviour的Update中调用。
### void AddLoader(CustomLoader loader)
描述:
增加一个自定义loader
参数:
loader:一个包括了加载函数的委托,其类型为delegate byte[] CustomLoader(ref string filepath),当一个文件被require时,这个loader会被回调,其参数是调用require所使用的参数,如果该loader找到文件,可以将其读进内存,返回一个byte数组。如果需要支持调试的话,而filepath要设置成IDE能找到的路径(相对或者绝对都可以)
#### void Dispose()
描述:
Dispose该LuaEnv。
> LuaEnv的使用建议:全局就一个实例,并在Update中调用GC方法,完全不需要时调用Dispose
### LuaTable类
#### T Get<T>(string key)
描述:
获取在key下,类型为T的value,如果不存在或者类型不匹配,返回null;
#### T GetInPath<T>(string path)
描述:
和Get的区别是,这个函数会识别path里头的“.”,比如var i = tbl.GetInPath<int>(“a.b.c”)相当于在lua里头执行i = tbl.a.b.c,避免仅为了获取中间变量而多次调用Get,执行效率更高。
#### void SetInPath<T>(string path, T val)
描述:
和GetInPaht<T>对应的setter;
#### void Get<TKey, TValue>(TKey key, out TValue value)
描述:
上面的API的Key都只能是string,而这个API无此限制;
#### void Set<TKey, TValue>(TKey key, TValue value)
描述:
对应Get<TKey, TValue>的setter;
#### T Cast<T>()
描述:
把该table转成一个T指明的类型,可以是一个加了CSharpCallLua声明的interface,一个有默认构造函数的class或者struct,一个Dictionary,List等等。
#### void SetMetaTable(LuaTable metaTable)
描述:
设置metaTable为table的metatable
### LuaFunction类
> 注意:用该类访问Lua函数会有boxing,unboxing的开销,为了性能考虑,需要频繁调用的地方不要用该类。建议通过table.Get<ABCDelegate>获取一个delegate再调用(假设ABCDelegate是C#的一个delegate)。在使用使用table.Get<ABCDelegate>之前,请先把ABCDelegate加到代码生成列表。
#### object[] Call(params object[] args)
描述:
以可变参数调用Lua函数,并返回该调用的返回值。
#### object[] Call(object[] args, Type[] returnTypes)
描述:
调用Lua函数,并指明返回参数的类型,系统会自动按指定类型进行转换。
#### void SetEnv(LuaTable env)
描述:
相当于lua的setfenv函数。
## Lua API
### CS对象
#### CS.namespace.class(...)
描述:
调用一个C#类型的构造函数,并返回类型实例
例如:
local v1=CS.UnityEngine.Vector3(1,1,1)
#### CS.namespace.class.field
描述:
访问一个C#静态成员
例如:
Print(CS.UnityEngine.Vector3.one)
#### CS.namespace.enum.field
描述:
访问一个枚举值
#### typeof函数
描述:
类似C#里头的typeof关键字,返回一个Type对象,比如GameObject.AddComponent其中一个重载需要一个Type参数
例如:
newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))
#### 无符号64位支持
##### uint64.tostring
描述:
无符号数转字符串。
##### uint64.divide
描述:
无符号数除法。
##### uint64.compare
描述:
无符号比较,相对返回0,大于返回正数,小于返回负数。
##### uint64.remainder
描述:
无符号数取模。
##### uint64.parse
描述:
字符串转无符号数。
#### xlua.structclone
描述:
克隆一个c#结构体
#### xlua.private_accessible(class)
描述:
让一个类的私有字段,属性,方法等可用
例子:
xlua.private_accessible(CS.UnityEngine.GameObject)
#### xlua.get_generic_method
描述:
获取一个泛型方法
例子:
~~~lua
local foo_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Foo')
local bar_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Bar')
local foo = foo_generic(CS.System.Int32, CS.System.Double)
local bar = bar_generic(CS.System.Double, CS.UnityEngine.GameObject)
-- call instance method
local o = CS.GetGenericMethodTest()
local ret = foo(o, 1, 2)
print(ret)
-- call static method
bar(2, nil)
~~~
#### cast函数
描述:
指明以特定的接口访问对象,这在实现类无法访问的时候(比如internal修饰)很有用,这时可以这么来(假设下面的calc对象实现了C#的PerformentTest.ICalc接口)
例子:
cast(calc, typeof(CS.PerformentTest.ICalc))
然后就木有其它API了
访问csharp对象和访问一个table一样,调用函数跟调用lua函数一样,也可以通过操作符访问c#的操作符,下面是一个例如:
local v1=CS.UnityEngine.Vector3(1,1,1)
local v2=CS.UnityEngine.Vector3(1,1,1)
v1.x = 100
v2.y = 100
print(v1, v2)
local v3 = v1 + v2
print(v1.x, v2.x)
print(CS.UnityEngine.Vector3.one)
print(CS.UnityEngine.Vector3.Distance(v1, v2))
## 类型映射
### 基本数据类型
|C#类型|Lua类型|
|-|-|
|sbyte,byte,short,ushort,int,uint,double,char,float|number|
|decimal|userdata|
|long,ulong|userdata/lua_Integer(lua53)|
|bytes[]|string|
|bool|boolean|
|string|string|
### 复杂数据类型
|C#类型|Lua类型|
|-|-|
|LuaTable|table|
|LuaFunction|function|
|class或者 struct的实例|userdata,table|
|method,delegate|function|
#### LuaTable:
C#侧指明从Lua侧输入(包括C#方法的输入参数或者Lua方法的返回值)LuaTable类型,则要求Lua侧为table。或者Lua侧的table,在C#侧未指明类型的情况下转换成LuaTable。
#### LuaFunction:
C#侧指明从Lua侧输入(包括C#方法的输入参数或者Lua方法的返回值)LuaFunction类型,则要求Lua侧为function。或者Lua侧的function,在C#侧未指明类型的情况下转换成LuaFunction。
#### LuaUserData:
对应非C# Managered对象的lua userdata。
#### class或者 struct的实例:
从C#传一个class或者struct的实例,将映射到Lua的userdata,并通过__index访问该userdata的成员
C#侧指明从Lua侧输入指定类型对象,Lua侧为该类型实例的userdata可以直接使用;如果该指明类型有默认构造函数,Lua侧是table则会自动转换,转换规则是:调用构造函数构造实例,并用table对应字段转换到c#对应值后赋值各成员。
#### method, delegate:
成员方法以及delegate都是对应lua侧的函数。
C#侧的普通参数以及引用参数,对应lua侧函数参数;C#侧的返回值对应于Lua的第一个返回值;引用参数和out参数则按序对应于Lua的第2到第N个参数。
## 宏
#### HOTFIX_ENABLE
打开hotfix功能。
#### NOT_GEN_WARNING
反射时打印warning。
#### GEN_CODE_MINIMIZE
以偏向减少代码段的方式生成代码。
fileFormatVersion: 2
guid: d97e183eaa307684b9b99ded9005b181
timeCreated: 1518577405
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
## C# APIs
### LuaEnv type
#### object[] DoString(string chunk, string chunkName = "chuck", LuaTable env = null)
Description:
Executes a code block.
Parameter:
chunk: Lua code string;
chunkName: This is used in the debug message when an error occurs, indicating a certain line in a certain code block has an error.
env: This is the environment variable of this code block.
Returned value:
The returned value of the return statement in the code block.
For example: return 1, "hello". DoString returns an array that will contain two objects. One is 1 of the double type, and the other is the string "hello".
For example:
LuaEnv luaenv = new LuaEnv();
object[] ret = luaenv.DoString("print(‘hello’)\r\nreturn 1")
UnityEngine.Debug.Log("ret="+ret[0]);
luaenv.Dispose()
#### T LoadString<T>(string chunk, string chunkName = "chunk", LuaTable env = null)
Description:
This loads a code block, but does not execute it. It only returns the type can be specified as a delegate or a LuaFunction.
Parameter:
chunk: Lua code string;
chunkName: This is used in the debug message when an error occurs, indicating a certain line in a certain code block has an error.
env: This is the environment variable of this code block.
Returned Value:
This is the delegate or LuaFunction type that represents the code block.
#### LuaTable Global;
Description:
This is the LuaTable representing the Lua global environment.
### void Tick()
Description:
This clears Lua's LuaBase objects that have not been manually released (for example LuaTable, LuaFunction), and other things.
This needs to be called periodically, for example in the Update of MonoBehaviour.
### void AddLoader(CustomLoader loader)
Description:
Adds a custom loader
Parameter:
loader: A delegate that includes the loaded function. The type is delegate byte[] CustomLoader(ref string filepath). When a file is required, the loader will be called back. Its parameters are the parameters used to call require. If the loader finds the file, it reads it into memory and returns a byte array. If debug support is required, the filepath should be set to one the IDE can find (relative or absolute).
#### void Dispose()
Description:
This disposes the LuaEnv.
> LuaEnv usage suggestion: use only one instance globally. Call the GC method in Update, and call Dispose when it is not required.
### LuaTable type
#### T Get<T>(string key)
Description:
Gets the value of type T on key. Null is returned if it does not exist or the type does not match.
#### T GetInPath<T>(string path)
Description:
The difference from Get is that this function will identify the "." in the path. For example, var i = tbl.GetInPath<int>(“a.b.c”) is equivalent to executing i = tbl.abc in Lua. This avoids calling Get multiple times and obtaining intermediate variables. It has higher execution efficiency.
#### void SetInPath<T>(string path, T val)
Description:
Setter corresponding to SetInPath<T>;
#### void Get<TKey, TValue>(TKey key, out TValue value)
Description:
The key of the APIs described above can only be a string, but this API has no such restriction.
#### void Set<TKey, TValue>(TKey key, TValue value)
Description:
This is the setter corresponding to Get<TKey, TValue>.
#### T Cast<T>()
Description:
Converts the table to a type specified by T. It can be an interface with a CSharpCallLua declaration, a type or struct with a default constructor, a Dictionary, a List, and so on.
#### void SetMetaTable(LuaTable metaTable)
Description:
Sets metatable to a table metatable
### LuaFunction type
> Note: Accessing Lua functions with this type will result in overhead from boxing and unboxing. For the sake of performance, do not use this type if frequent calls are required. It is recommended that you use table.Get<ABCDelegate> to get a delegate and then call it (assuming ABCDelegate is a delegate of C#). Before using table.Get<ABCDelegate>, add ABCDelegate to the list of generated code.
#### object[] Call(params object[] args)
Description:
This calls the Lua function with the variable parameters and returns the returned value of the call.
#### object[] Call(object[] args, Type[] returnTypes)
Description:
This calls the Lua function and specifies the type of the returned parameter. The system will automatically convert the specified type.
#### void SetEnv(LuaTable env)
Description:
Equivalent to Lua's setfenv function.
## Lua API
### CS objects
#### CS.namespace.class(...)
Description:
This calls a C# type constructor and returns a type instance.
For Example:
local v1=CS.UnityEngine.Vector3(1,1,1)
#### CS.namespace.class.field
Description:
This accesses a C# static member.
For Example:
Print(CS.UnityEngine.Vector3.one)
#### CS.namespace.enum.field
Description:
This accesses an enumerated value.
#### Typeof Functions
Description:
This is similar to the typeof keyword in C#: a Type object is returned. For example, in GameObject.AddComponent, one overload requires a Type parameter.
For Example:
newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))
#### Unsigned 64-bit is supported
##### uint64.tostring
Description:
Unsigned number to string.
##### uint64.divide
Description:
Unsigned number division.
##### uint64.compare
Description:
Unsigned comparison: 0 is returned for equal, positive for greater than, and negative for less than.
##### uint64.remainder
Description:
Unsigned modulus.
##### uint64.parse
Description:
String to unsigned number.
#### xlua.structclone
Description:
This clones a c# structure.
#### xlua.private_accessible(class)
Description:
This makes the private fields, properties, methods of a type available.
#### Cast Function
Description:
This indicates that the object is accessed with a specific interface, which is useful when the implementation type is inaccessible (such as internal modification). Use it in the following way (assuming that the following calc object implements C#'s PerformentTest.ICalc interface):
For Example:
cast(calc, typeof(CS.PerformentTest.ICalc))
Then, no other APIs are available.
Accessing a csharp object is like accessing a table. Calling a function is like calling the Lua function. Operators can also be used to access the C# operator. Here is an example:
local v1=CS.UnityEngine.Vector3(1,1,1)
local v2=CS.UnityEngine.Vector3(1,1,1)
v1.x = 100
v2.y = 100
print(v1, v2)
local v3 = v1 + v2
print(v1.x, v2.x)
print(CS.UnityEngine.Vector3.one)
print(CS.UnityEngine.Vector3.Distance(v1, v2))
## Type mapping
### Basic data type
|C# type|Lua type|
|-|-|
|sbyte, byte, short, ushort, int ,uint ,double ,char ,float|number|
|decimal|userdata|
|long ,ulong|userdata/lua_Integer(lua53)|
|bytes[]|string|
|bool|boolean|
|string|string|
### Complex data type
|C# type|Lua type|
|-|-|
|LuaTable|table|
|LuaFunction|function|
|class or struct instance|userdata, table|
|method, delegate|function|
#### LuaTable:
If C# specifies inputting the LuaTable type (including the input parameters of the C# method or the returned value of the Lua method) from Lua, then it must be a table in Lua. Or, if C# does not specify the type, the table in Lua should be converted to LuaTable .
#### LuaFunction:
If C# specifies inputting the LuaFunction type (including the input parameters of the C# method or the returned value of the Lua method) from Lua, then it must be a function in Lua. Or, if C# does not specify the type, the function on Lua should be converted to LuaFunction.
#### LuaUserData:
This is Lua userdata corresponding to the non-C# Managered object.
#### Class or struct instance:
This transfers a class or struct instance from C#, maps it to Lua userdata, and accesses the member of the userdata via __index.
If C# specifies inputting objects of the specified type from Lua, then the userdata of the type instance is used directly in Lua. If the specified type has a default constructor, the table in Lua is automatically converted. The conversion rule is: call the constructor to construct an instance, and convert the field corresponding to table to each setter member in C#.
#### Method and delegate:
Both member methods and delegates correspond to the Lua functions.
The ordinary parameters and reference parameters on C# correspond to the Lua function parameters. The returned value on C# corresponds to the first returned value on Lua. The reference parameters and out parameters correspond to the 2nd to Nth parameters on Lua in sequence.
## Macros
#### HOTFIX_ENABLE
This enables the hotfix function.
#### NOT_GEN_WARNING
This prints warning when there is reflection.
#### GEN_CODE_MINIMIZE
Generates code in a way that minimizes the code segments.
fileFormatVersion: 2
guid: 563bce1ceae59334c860773faa7b3a7a
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 76e3df78477813b47bb62712878a2f62
timeCreated: 1529661499
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 40e0633beaaf4dd49aca86e58539a814
timeCreated: 1469709930
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
## What&Why
XLua目前内置的扩展库:
* 针对luajit的64位整数支持;
* 函数调用耗时以及内存泄漏定位工具;
* 用于支持ZeroBraneStudio的luasocket库;
* tdr 4 lua;
随着使用项目的增加以及项目使用的深入程度,仅有这几个扩展已经没法满足项目组了,而由于各个项目对扩展差异化比较大,以及手机平台对安装包大小的敏感,XLua是无法通过预集成去满足这些需求,这也是这篇教程的由来。
这篇教程,将以lua-rapidjson为例,一步步的讲述怎么往xLua添加c/c++扩展,当然,会添加了,自然删除也就会了,项目组可以自行删除不需要用到的预集成扩展。
## How
分三步
1. 修改build文件、工程设置,把要集成的扩展编译到XLua Plugin里头;
2. 调用xLua的C# API,使得扩展可以被按需(在lua代码里头require的时候)加载;
3. 可选,如果你的扩展里头需要用到64位整数,你可以通过XLua的64位扩展库来实现和C#的配合。
### 一、添加扩展&编译
准备工作
1. 把xLua的C源码包解压到你Unity工程的Assets同级目录下。
下载lua-rapidjson代码,按你的习惯放置。本教程是把rapidjson头文件放到$UnityProj\build\lua-rapidjson\include目录下,而扩展的源码rapidjson.cpp放到$UnityProj\build\lua-rapidjson\source目录下(注:$UnityProj指的是你工程的目录)
2. 在CMakeLists.txt加入扩展
xLua的各平台Plugins编译使用cmake编译,好处是所有平台的编译都写在一个makefile,大部分编译处理逻辑是跨平台的。
xLua配套的CMakeLists.txt为第三方扩展提供了扩展点(都是list):
1. THIRDPART_INC:第三方扩展的头文件搜索路径。
2. THIRDPART_SRC:第三方扩展的源代码。
3. THIRDPART_LIB:第三方扩展依赖的库。
如下是rapidjson的加法
#begin lua-rapidjson
set (RAPIDJSON_SRC lua-rapidjson/source/rapidjson.cpp)
set_property(
SOURCE ${RAPIDJSON_SRC}
APPEND
PROPERTY COMPILE_DEFINITIONS
LUA_LIB
)
list(APPEND THIRDPART_INC lua-rapidjson/include)
set (THIRDPART_SRC ${THIRDPART_SRC} ${RAPIDJSON_SRC})
#end lua-rapidjson
完整代码请见附件。
3. 各平台编译
所有编译脚本都是按这个方式命名:make_平台_lua版本.后缀。
比如windows 64位lua53版本是make_win64_lua53.bat,android的luajit版本是make_android_luajit.sh,要编译哪个版本就执行相应的脚本即可。
执行完编译脚本会自动拷贝到plugin_lua53或者plugin_luajit目录,前者是lua53版本放置路径,后者是luajit。
配套的android脚本是在linux下使用的,脚本开头的NDK路径要根据实际情况修改。
### 二、C#侧集成
所有lua的C扩展库都会提供个luaopen_xxx的函数,xxx是动态库的名字,比如lua-rapidjson库该函数是luaopen_rapidjson,这类函数由lua虚拟机在加载动态库时自动调用,而在手机平台,由于ios的限制我们加载不了动态库,而是直接编译进进程里头。
为此,XLua提供了一个API来替代这功能(LuaEnv的成员方法):
public void AddBuildin(string name, LuaCSFunction initer)
参数:
name:buildin模块的名字,require时输入的参数;
initer:初始化函数,原型是这样的public delegate int lua_CSFunction(IntPtr L),必须是静态函数,而且带MonoPInvokeCallbackAttribute属性修饰,这个api会检查这两个条件。
我们以luaopen_rapidjson的调用来看看怎么使用。
扩展LuaDLL.Lua类,用pinvoke把luaopen_rapidjson导出到C#,然后写一个符合lua_CSFunction定义的静态函数,你可以在里头做写初始化工作,比如luaopen_rapidjson的调用,以下是完整代码:
namespace LuaDLL
{
public partial class Lua
{
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_rapidjson(System.IntPtr L);
[MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
public static int LoadRapidJson(System.IntPtr L)
{
return luaopen_rapidjson(L);
}
}
}
然后调用AddBuildin:
luaenv.AddBuildin("rapidjson", LuaDLL.Lua.LoadRapidJson);
然后就ok了,在lua代码中试试该扩展:
local rapidjson = require('rapidjson')
local t = rapidjson.decode('{"a":123}')
print(t.a)
t.a = 456
local s = rapidjson.encode(t)
print('json', s)
### 三、64位改造
把i64lib.h文件include到需要64位改造的文件里头。
该头文件的API就以下几个:
//往栈上放一个int64/uint64
void lua_pushint64(lua_State* L, int64_t n);
void lua_pushuint64(lua_State* L, uint64_t n);
//判断栈上pos位置是否是int64/uint64
int lua_isint64(lua_State* L, int pos);
int lua_isuint64(lua_State* L, int pos);
//从栈上pos位置取一个int64/uint64
int64_t lua_toint64(lua_State* L, int pos);
uint64_t lua_touint64(lua_State* L, int pos);
这些API的使用依情况而定,可以看看本文附带的附件(rapidjson.cpp文件)
编译工程相关修改
\ No newline at end of file
fileFormatVersion: 2
guid: 6a5e50ce3ca4b6140858bd4eb6efc2e9
timeCreated: 1518577405
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 11d97e567c78f3147b86070c103f3d2d
timeCreated: 1472455442
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
## 复杂值类型的gc问题
xLua复杂值类型(struct)的默认传递方式是引用传递,这种方式要求先对值类型boxing,传递给lua,lua使用后释放该引用。由于值类型每次boxing将产生一个新对象,当lua侧使用完毕释放该对象的引用时,则产生一次gc。
为此,xLua实现了一套struct的gc优化方案,您只要通过简单的配置,则可以实现满足条件的struct传递到lua侧无gc。
## struct需要满足什么条件?
1. struct允许嵌套其它struct,但它以及它嵌套的struct只能包含这几种基本类型:byte、sbyte、short、ushort、int、uint、long、ulong、float、double;例如UnityEngine定义的大多数值类型:Vector系列,Quaternion,Color。。。均满足条件,或者用户自定义的一些struct
2. 该struct配置了GCOptimize属性(对于常用的UnityEngine的几个struct,Vector系列,Quaternion,Color。。。均已经配置了该属性),这个属性可以通过配置文件或者C# Attribute实现;
3. 使用到该struct的地方,需要添加到生成代码列表;
## 如何配置?
`XLua的配置.md`的GCOptimize章节。
\ No newline at end of file
fileFormatVersion: 2
guid: 688574fb2ae996243b1cb02ec3a78bee
timeCreated: 1518577405
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5e83c211c4c43834b9c8027b7480ab5f
timeCreated: 1462265117
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment