|
|
@@ -1,4 +1,4 @@
|
|
|
-/*
|
|
|
+/*
|
|
|
Copyright (c) 2015-2017 topameng(topameng@qq.com)
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
@@ -25,17 +25,18 @@ using UnityEngine;
|
|
|
using LuaInterface;
|
|
|
using System.IO;
|
|
|
using System.Text;
|
|
|
-
|
|
|
-public class LuaResLoader : LuaFileUtils
|
|
|
+namespace LuaInterface
|
|
|
{
|
|
|
- public LuaResLoader()
|
|
|
+ public class LuaResLoader : LuaFileUtils
|
|
|
{
|
|
|
- instance = this;
|
|
|
- beZip = false;
|
|
|
- }
|
|
|
+ public LuaResLoader()
|
|
|
+ {
|
|
|
+ instance = this;
|
|
|
+ beZip = false;
|
|
|
+ }
|
|
|
|
|
|
- public override byte[] ReadFile(string fileName)
|
|
|
- {
|
|
|
+ public override byte[] ReadFile(string fileName)
|
|
|
+ {
|
|
|
#if !UNITY_EDITOR
|
|
|
byte[] buffer = ReadDownLoadFile(fileName);
|
|
|
|
|
|
@@ -49,107 +50,108 @@ public class LuaResLoader : LuaFileUtils
|
|
|
buffer = base.ReadFile(fileName);
|
|
|
}
|
|
|
#else
|
|
|
- byte[] buffer = base.ReadFile(fileName);
|
|
|
+ byte[] buffer = base.ReadFile(fileName);
|
|
|
|
|
|
- if (buffer == null)
|
|
|
- {
|
|
|
- buffer = ReadResourceFile(fileName);
|
|
|
- }
|
|
|
+ if (buffer == null)
|
|
|
+ {
|
|
|
+ buffer = ReadResourceFile(fileName);
|
|
|
+ }
|
|
|
|
|
|
- if (buffer == null)
|
|
|
- {
|
|
|
- buffer = ReadDownLoadFile(fileName);
|
|
|
- }
|
|
|
+ if (buffer == null)
|
|
|
+ {
|
|
|
+ buffer = ReadDownLoadFile(fileName);
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
- return buffer;
|
|
|
- }
|
|
|
-
|
|
|
- public override string FindFileError(string fileName)
|
|
|
- {
|
|
|
- if (Path.IsPathRooted(fileName))
|
|
|
- {
|
|
|
- return fileName;
|
|
|
+ return buffer;
|
|
|
}
|
|
|
|
|
|
- if (Path.GetExtension(fileName) == ".lua")
|
|
|
+ public override string FindFileError(string fileName)
|
|
|
{
|
|
|
- fileName = fileName.Substring(0, fileName.Length - 4);
|
|
|
- }
|
|
|
-
|
|
|
- using (CString.Block())
|
|
|
- {
|
|
|
- CString sb = CString.Alloc(512);
|
|
|
+ if (Path.IsPathRooted(fileName))
|
|
|
+ {
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < searchPaths.Count; i++)
|
|
|
+ if (Path.GetExtension(fileName) == ".lua")
|
|
|
{
|
|
|
- sb.Append("\n\tno file '").Append(searchPaths[i]).Append('\'');
|
|
|
+ fileName = fileName.Substring(0, fileName.Length - 4);
|
|
|
}
|
|
|
|
|
|
- sb.Append("\n\tno file './Resources/").Append(fileName).Append(".lua'")
|
|
|
- .Append("\n\tno file '").Append(LuaConst.luaResDir).Append('/')
|
|
|
- .Append(fileName).Append(".lua'");
|
|
|
- sb = sb.Replace("?", fileName);
|
|
|
+ using (CString.Block())
|
|
|
+ {
|
|
|
+ CString sb = CString.Alloc(512);
|
|
|
+
|
|
|
+ for (int i = 0; i < searchPaths.Count; i++)
|
|
|
+ {
|
|
|
+ sb.Append("\n\tno file '").Append(searchPaths[i]).Append('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+ sb.Append("\n\tno file './Resources/").Append(fileName).Append(".lua'")
|
|
|
+ .Append("\n\tno file '").Append(LuaConst.luaResDir).Append('/')
|
|
|
+ .Append(fileName).Append(".lua'");
|
|
|
+ sb = sb.Replace("?", fileName);
|
|
|
|
|
|
- return sb.ToString();
|
|
|
+ return sb.ToString();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- byte[] ReadResourceFile(string fileName)
|
|
|
- {
|
|
|
- if (!fileName.EndsWith(".lua"))
|
|
|
+ byte[] ReadResourceFile(string fileName)
|
|
|
{
|
|
|
- fileName += ".lua";
|
|
|
- }
|
|
|
+ if (!fileName.EndsWith(".lua"))
|
|
|
+ {
|
|
|
+ fileName += ".lua";
|
|
|
+ }
|
|
|
|
|
|
- byte[] buffer = null;
|
|
|
- string path = "Lua/" + fileName;
|
|
|
- TextAsset text = Resources.Load(path, typeof(TextAsset)) as TextAsset;
|
|
|
+ byte[] buffer = null;
|
|
|
+ string path = "Lua/" + fileName;
|
|
|
+ TextAsset text = Resources.Load(path, typeof(TextAsset)) as TextAsset;
|
|
|
|
|
|
- if (text != null)
|
|
|
- {
|
|
|
- buffer = text.bytes;
|
|
|
- Resources.UnloadAsset(text);
|
|
|
- }
|
|
|
+ if (text != null)
|
|
|
+ {
|
|
|
+ buffer = text.bytes;
|
|
|
+ Resources.UnloadAsset(text);
|
|
|
+ }
|
|
|
|
|
|
- return buffer;
|
|
|
- }
|
|
|
+ return buffer;
|
|
|
+ }
|
|
|
|
|
|
- byte[] ReadDownLoadFile(string fileName)
|
|
|
- {
|
|
|
- byte[] bytes = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
- //string content = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
- //if (null != content)
|
|
|
- //{
|
|
|
- // bytes = Encoding.Default.GetBytes(content);
|
|
|
- //}
|
|
|
- //TextAsset ta = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
- //if (null != ta)
|
|
|
- //{
|
|
|
- // bytes = ta.bytes;
|
|
|
- //}
|
|
|
- return bytes;
|
|
|
- // if (!fileName.EndsWith(".lua"))
|
|
|
- // {
|
|
|
- // fileName += ".lua";
|
|
|
- // }
|
|
|
-
|
|
|
- // string path = fileName;
|
|
|
-
|
|
|
- // if (!Path.IsPathRooted(fileName))
|
|
|
- // {
|
|
|
- // path = string.Format("{0}/{1}", LuaConst.luaResDir, fileName);
|
|
|
- // }
|
|
|
-
|
|
|
- // if (File.Exists(path))
|
|
|
- // {
|
|
|
- //#if !UNITY_WEBPLAYER
|
|
|
- // return File.ReadAllBytes(path);
|
|
|
- //#else
|
|
|
- // throw new LuaException("can't run in web platform, please switch to other platform");
|
|
|
- //#endif
|
|
|
- // }
|
|
|
-
|
|
|
- // return null;
|
|
|
+ byte[] ReadDownLoadFile(string fileName)
|
|
|
+ {
|
|
|
+ byte[] bytes = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
+ //string content = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
+ //if (null != content)
|
|
|
+ //{
|
|
|
+ // bytes = Encoding.Default.GetBytes(content);
|
|
|
+ //}
|
|
|
+ //TextAsset ta = LuaMgr.Instance.GetLuaTextAsset(GetAddLuaSuffix(fileName));
|
|
|
+ //if (null != ta)
|
|
|
+ //{
|
|
|
+ // bytes = ta.bytes;
|
|
|
+ //}
|
|
|
+ return bytes;
|
|
|
+ // if (!fileName.EndsWith(".lua"))
|
|
|
+ // {
|
|
|
+ // fileName += ".lua";
|
|
|
+ // }
|
|
|
+
|
|
|
+ // string path = fileName;
|
|
|
+
|
|
|
+ // if (!Path.IsPathRooted(fileName))
|
|
|
+ // {
|
|
|
+ // path = string.Format("{0}/{1}", LuaConst.luaResDir, fileName);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (File.Exists(path))
|
|
|
+ // {
|
|
|
+ //#if !UNITY_WEBPLAYER
|
|
|
+ // return File.ReadAllBytes(path);
|
|
|
+ //#else
|
|
|
+ // throw new LuaException("can't run in web platform, please switch to other platform");
|
|
|
+ //#endif
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return null;
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|