少年修仙传客户端代码仓库
client_Wu Xijin
2018-08-15 8b52e103908013769480b30fce2d45267210b407
更新lua脚本,添加luawindow的创建方法。
1 文件已重命名
3个文件已修改
1个文件已删除
1个文件已添加
283 ■■■■ 已修改文件
Core/GameEngine/Login/Launch.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaLaunch.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaLoader.cs 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaUtility.cs 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaWindow.cs 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaWindow.cs.meta 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/GameEngine/Login/Launch.cs
@@ -261,6 +261,7 @@
        OperationLogCollect.Instance.RecordLauchEvent(3);
        OperationLogCollect.Instance.RecordEvent(3);
        LuaUtility.Instance.Init();
        ShaderUtility.WarmUpAll();
        SpeechTranslate.Instance.RequestGetToken();
Lua/LuaLaunch.cs
@@ -7,7 +7,7 @@
    void Awake()
    {
        LuaLoader.Init();
        LuaUtility.Instance.Init();
    }
}
Lua/LuaLoader.cs
File was deleted
Lua/LuaUtility.cs
@@ -2,12 +2,61 @@
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System.IO;
public class LuaUtility
public class LuaUtility : SingletonMonobehaviour<LuaUtility>
{
    internal static LuaEnv env = new LuaEnv();
    internal static float lastGCTime = 0;
    internal const float GCInterval = 1;//1 second
    static float lastGCTime = 0;
    const float GCInterval = 1;//1 second
    static LuaUtility()
    {
        env.AddLoader(new LuaEnv.CustomLoader(LoadAsset));
    }
    public void Init()
    {
        Do("custom.ButtonUtil");
        Do("global.logex");
        lastGCTime = 0f;
    }
    void Update()
    {
        if (Time.time - lastGCTime > GCInterval)
        {
            env.Tick();
            lastGCTime = Time.time;
        }
    }
    public static void Do(string _file, string chunkName = "chunk", LuaTable _table = null)
    {
        var command = string.Format("require '{0}'", _file);
        env.DoString(command, chunkName, _table);
    }
    private static byte[] 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);
        }
        bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
        return bytes;
    }
}
Lua/LuaWindow.cs
New file
@@ -0,0 +1,149 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;
using System.IO;
using Snxxz.UI;
[LuaCallCSharp]
public class LuaWindow : Window
{
    public string fileName;
    public Injection[] injections;
    Action luaOnDestroy;
    Action onBindController;
    Action onAddListeners;
    Action onPreOpen;
    Action onAfterOpen;
    Action onPreClose;
    Action onAfterClose;
    Action onActived;
    Action onLateUpdate;
    private LuaTable scriptEnv;
    bool luaInited = false;
    private void Init()
    {
        scriptEnv = LuaUtility.env.NewTable();
        LuaTable meta = LuaUtility.env.NewTable();
        meta.Set("__index", LuaUtility.env.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();
        scriptEnv.Set("self", this);
        foreach (var injection in injections)
        {
            scriptEnv.Set(injection.name, injection.value);
        }
        LuaUtility.Do(fileName, "LuaWindow", scriptEnv);
        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);
        scriptEnv.Get("OnDestroy", out luaOnDestroy);
    }
    void OnDestroy()
    {
        if (luaOnDestroy != null)
        {
            luaOnDestroy();
        }
        luaOnDestroy = null;
        onBindController = null; ;
        onAddListeners = null; ;
        onPreOpen = null; ;
        onAfterOpen = null; ;
        onPreClose = null;
        onAfterClose = null; ;
        onActived = null;
        onLateUpdate = null;
        scriptEnv.Dispose();
        injections = null;
    }
    protected override void BindController()
    {
        Init();
        if (onBindController != null)
        {
            onBindController();
        }
    }
    protected override void AddListeners()
    {
        if (onAddListeners != null)
        {
            onAddListeners();
        }
    }
    protected override void OnPreOpen()
    {
        if (onPreOpen != null)
        {
            onPreOpen();
        }
    }
    protected override void OnAfterOpen()
    {
        if (onAfterOpen != null)
        {
            onAfterOpen();
        }
    }
    protected override void OnPreClose()
    {
        if (onPreClose != null)
        {
            onPreClose();
        }
    }
    protected override void OnAfterClose()
    {
        if (onAfterClose != null)
        {
            onAfterClose();
        }
    }
    protected override void OnActived()
    {
        base.OnActived();
        if (onActived != null)
        {
            onActived();
        }
    }
    protected override void LateUpdate()
    {
        base.LateUpdate();
        if (onLateUpdate != null)
        {
            onLateUpdate();
        }
    }
}
Lua/LuaWindow.cs.meta
File was renamed from Lua/LuaLoader.cs.meta
@@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: 4ceb42d1dda6d6a47923ef8608e3771e
timeCreated: 1533282621
guid: f203b48cd7ee2084fa734cc0b287c02d
timeCreated: 1534318225
licenseType: Pro
MonoImporter:
  serializedVersion: 2