forked from asqbtcupid/lua_hotupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileModifyDetector.cs
More file actions
51 lines (48 loc) · 1.88 KB
/
FileModifyDetector.cs
File metadata and controls
51 lines (48 loc) · 1.88 KB
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
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
public class LuaFastProcessor : AssetPostprocessor
{
protected const string HOT_FIX_STR = "HU.Update()";
public static bool is_on = false;
public static void OnPostprocessAllAssets(string[] importedAsset, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
if (!is_on){
return;
}
if (Application.isPlaying)
{
var luaEnv = LEngine.Base.XLuaTool.Instance().GetLuaEnv();
string path = Application.dataPath + "\\Path\\To\\hotupdatelist.lua";
StringBuilder sb = new StringBuilder();
sb.Append("local FileNameList = {\n");
for (int i = 0; i < importedAsset.Length; i++)
{
bool isLuaFile = importedAsset[i].EndsWith(".lua");
if (isLuaFile)
{
if (luaEnv != null)
{
string strName = importedAsset[i].Replace(".lua", "");
string shortName = strName.Substring(strName.LastIndexOf("/") + 1);
if(shortName == "hotupdatelist" || shortName == "luahotupdate"){
continue;
}
string relativePath = strName.Replace("Assets/", "");
string absolutePath = Application.dataPath + '/' + relativePath;
sb.Append("\"");
sb.Append(absolutePath);
sb.Append("\",");
}
}
}
sb.Append(@"
}
return FileNameList");
File.WriteAllText(path,sb.ToString());
if(luaEnv!=null)
luaEnv.DoString(string.Format(HOT_FIX_STR));
}
}
}