少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-22 0f0c48714089fab030974d7215bc13fc3596b722
3335 更新lua库
2个文件已修改
3个文件已添加
178 ■■■■ 已修改文件
Core/NetworkPackage/DTCFile/ClientPack.meta 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaBehaviour.cs 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaBehaviour.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaUtility.cs 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaWindow.cs 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/DTCFile/ClientPack.meta
New file
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 722e5e3d30096674e811f5bd191246a0
folderAsset: yes
timeCreated: 1539228128
licenseType: Pro
DefaultImporter:
  userData:
  assetBundleName:
  assetBundleVariant:
Lua/LuaBehaviour.cs
New file
@@ -0,0 +1,90 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;
using System.IO;
[LuaCallCSharp]
public class LuaBehaviour : MonoBehaviour
{
    public string fileName;
    private Action luaOnEnable;
    private Action luaStart;
    private Action luaUpdate;
    private Action luaOnDisable;
    private Action luaOnDestroy;
    private LuaTable table;
    void Awake()
    {
        table = LuaUtility.GetNewTable();
        var meta = LuaUtility.GetNewTable();
        meta.Set("__index", LuaUtility.Global);
        table.SetMetaTable(meta);
        meta.Dispose();
        table.Set("this", this);
        LuaUtility.DoString(fileName, "LuaBehaviour", table);
        var luaAwake = table.Get<Action>("Awake");
        table.Get("OnEnable", out luaOnEnable);
        table.Get("Start", out luaStart);
        table.Get("Update", out luaUpdate);
        table.Get("OnDisable", out luaOnDisable);
        table.Get("OnDestroy", out luaOnDestroy);
        if (luaAwake != null)
        {
            luaAwake();
        }
    }
    private void OnEnable()
    {
        if (luaOnEnable != null)
        {
            luaOnEnable();
        }
    }
    void Start()
    {
        if (luaStart != null)
        {
            luaStart();
        }
    }
    void Update()
    {
        if (luaUpdate != null)
        {
            luaUpdate();
        }
    }
    private void OnDisable()
    {
        if (luaOnDisable != null)
        {
            luaOnDisable();
        }
    }
    void OnDestroy()
    {
        if (luaOnDestroy != null)
        {
            luaOnDestroy();
        }
        luaOnDisable = null;
        luaOnEnable = null;
        luaOnDestroy = null;
        luaUpdate = null;
        luaStart = null;
        table.Dispose();
    }
}
Lua/LuaBehaviour.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 028ad9d0c327569419d2e22210b67d2d
timeCreated: 1540173220
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Lua/LuaUtility.cs
@@ -6,13 +6,22 @@
public class LuaUtility : SingletonMonobehaviour<LuaUtility>
{
    internal static LuaEnv env = new LuaEnv();
    public readonly static LuaEnv env = new LuaEnv();
    static float lastGCTime = 0;
    const float GCInterval = 1;//1 second 
    static LuaUtility()
    {
        env.AddLoader(new LuaEnv.CustomLoader(LoadAsset));
        env.AddLoader(new LuaEnv.CustomLoader(LoadAssetBytes));
    }
    public static LuaTable GetNewTable()
    {
        return env.NewTable();
    }
    public static LuaTable Global {
        get { return env.Global; }
    }
    public void Init()
@@ -41,25 +50,31 @@
        env.DoString(command, chunkName, _table);
    }
    private static byte[] LoadAsset(ref string _fileName)
    public static void DoString(string _file, string chunkName = "chunk", LuaTable _table = null)
    {
        var content = LoadAsset(ref _file);
        env.DoString(content, chunkName, _table);
    }
    private static string LoadAsset(ref string _fileName)
    {
        _fileName = _fileName.Replace('.', '/');
        var path = string.Empty;
        byte[] bytes = null;
        if (AssetSource.luaFromEditor)
        {
            path = ResourcesPath.LUA_FODLER + "/" + _fileName + ".lua";
        }
        else
        {
            var assetVersion = AssetVersionUtility.GetAssetVersion(StringUtility.Contact("lua/", _fileName, ".lua"));
            path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, assetVersion.relativePath);
            path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact("lua/", _fileName, ".lua"));
        }
        bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
        return bytes;
        return File.ReadAllText(path);
    }
    private static byte[] LoadAssetBytes(ref string _fileName)
    {
        return System.Text.Encoding.UTF8.GetBytes(LoadAsset(ref _fileName));
    }
}
Lua/LuaWindow.cs
@@ -20,28 +20,28 @@
    Action onActived;
    Action onLateUpdate;
    private LuaTable scriptEnv;
    private LuaTable table;
    private void Init()
    {
        scriptEnv = LuaUtility.env.NewTable();
        LuaTable meta = LuaUtility.env.NewTable();
        meta.Set("__index", LuaUtility.env.Global);
        scriptEnv.SetMetaTable(meta);
        table = LuaUtility.GetNewTable();
        var meta = LuaUtility.GetNewTable();
        meta.Set("__index", LuaUtility.Global);
        table.SetMetaTable(meta);
        meta.Dispose();
        LuaUtility.Do(string.Format("window.{0}", this.gameObject.name), this.gameObject.name, scriptEnv);
        LuaUtility.Do(string.Format("window.{0}", this.gameObject.name), this.gameObject.name, table);
        scriptEnv.Get("BindController", out onBindController);
        scriptEnv.Get("AddListeners", out onAddListeners);
        scriptEnv.Get("OnPreOpen", out onPreOpen);
        scriptEnv.Get("OnAfterOpen", out onAfterOpen);
        scriptEnv.Get("OnPreClose", out onPreClose);
        scriptEnv.Get("OnAfterClose", out onAfterClose);
        scriptEnv.Get("OnActived", out onActived);
        scriptEnv.Get("LateUpdate", out onLateUpdate);
        table.Get("BindController", out onBindController);
        table.Get("AddListeners", out onAddListeners);
        table.Get("OnPreOpen", out onPreOpen);
        table.Get("OnAfterOpen", out onAfterOpen);
        table.Get("OnPreClose", out onPreClose);
        table.Get("OnAfterClose", out onAfterClose);
        table.Get("OnActived", out onActived);
        table.Get("LateUpdate", out onLateUpdate);
        scriptEnv.Get("OnDestroy", out luaOnDestroy);
        table.Get("OnDestroy", out luaOnDestroy);
    }
    void OnDestroy()
@@ -61,9 +61,9 @@
        onActived = null;
        onLateUpdate = null;
        if (scriptEnv != null)
        if (table != null)
        {
            scriptEnv.Dispose();
            table.Dispose();
        }
    }