少年修仙传客户端代码仓库
leonard Wu
2018-08-03 be7d8c798ff9bc60819d9493246256ce6303daad
lua基础脚本修改
5个文件已修改
67 ■■■■■ 已修改文件
Core/Common/ResourcesPath.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/Config/AssetSource.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/GameEngine/Model/ConfigManager.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaLoader.cs 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaUtility.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/Common/ResourcesPath.cs
@@ -39,6 +39,7 @@
    public static readonly string CONFIG_FODLER = ResourcesOutPath + "refdata/Config";
    public static readonly string AUDIO_SUFFIX = "Audio/";
    public static readonly string LUA_FODLER = ResourcesOutPath + "Lua";
    #endregion
Core/Config/AssetSource.cs
@@ -146,4 +146,22 @@
        }
    }
    static bool m_LuaFromEditor = false;
    public static bool luaFromEditor {
        get {
#if UNITY_EDITOR
            return LocalSave.GetBool("Asset_LuaFromEditor", true);
#else
            return false;
#endif
        }
        set {
#if UNITY_EDITOR
            LocalSave.SetBool("Asset_LuaFromEditor", value);
#else
            luaFromEditor=value;
#endif
        }
    }
}
Core/GameEngine/Model/ConfigManager.cs
@@ -665,6 +665,7 @@
        return config as T;
    }
    [XLua.LuaCallCSharp]
    public T GetTemplate<T>(int _dwTemplateID) where T : ConfigBase, new()
    {
        return GetTemplate<T>(_dwTemplateID.ToString());
Lua/LuaLoader.cs
@@ -9,7 +9,7 @@
    static LuaLoader()
    {
        LuaUtility.env.AddLoader(new LuaEnv.CustomLoader(OnLoadFile));
        LuaUtility.env.AddLoader(new LuaEnv.CustomLoader(LoadAsset));
    }
    public static void Init()
@@ -18,17 +18,53 @@
        Load("global.logex");
    }
    public static TextAsset LoadRawFile(string _fileName)
    {
        _fileName = _fileName.Replace('.', '/');
        TextAsset textAsset = null;
        if (AssetSource.luaFromEditor)
        {
#if UNITY_EDITOR
            var path = ResourcesPath.ResourcesOutAssetPath + "Lua/" + _fileName + ".lua.txt";
            textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path);
#endif
        }
        else
        {
            var pathArray = _fileName.Split('/');
            var bundleName = StringUtility.Contact("lua/", pathArray[0].ToLower());
            var assetInfo = new AssetInfo(bundleName, pathArray[1].ToLower());
            textAsset = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as TextAsset;
        }
        return textAsset;
    }
    public static void Load(string _file)
    {
        var command = string.Format("require '{0}'", _file);
        LuaUtility.env.DoString(command);
    }
    private static byte[] OnLoadFile(ref string _fileName)
    private static byte[] LoadAsset(ref string _fileName)
    {
        _fileName = _fileName.Replace('.', '/');
        var path = Application.dataPath + "/Lua/" + _fileName + ".lua.txt";
        var bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
        var path = string.Empty;
        byte[] bytes = null;
        if (AssetSource.luaFromEditor)
        {
            path = ResourcesPath.LUA_FODLER + "/" + _fileName + ".lua.txt";
        }
        else
        {
            var assetVersion = AssetVersionUtility.GetAssetVersion(StringUtility.Contact("lua/", _fileName, ".lua.txt"));
            path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, assetVersion.relativePath);
        }
        bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
        return bytes;
    }
}
Lua/LuaUtility.cs
@@ -7,6 +7,7 @@
{
    internal static LuaEnv env = new LuaEnv();
    internal static float lastGCTime = 0;
    internal const float GCInterval = 1;//1 second
}