少年修仙传客户端代码仓库
leonard Wu
2018-08-03 be7d8c798ff9bc60819d9493246256ce6303daad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System.IO;
 
public class LuaLoader
{
 
    static LuaLoader()
    {
        LuaUtility.env.AddLoader(new LuaEnv.CustomLoader(LoadAsset));
    }
 
    public static void Init()
    {
        Load("custom.ButtonUtil");
        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[] LoadAsset(ref string _fileName)
    {
        _fileName = _fileName.Replace('.', '/');
 
        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;
    }
}