static int LoadAsset(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(NTGResourceController), typeof(string), typeof(string)))
            {
                NTGResourceController obj = (NTGResourceController)ToLua.ToObject(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                UnityEngine.GameObject o = obj.LoadAsset(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(NTGResourceController), typeof(string), typeof(string), typeof(string)))
            {
                NTGResourceController obj = (NTGResourceController)ToLua.ToObject(L, 1);
                string             arg0   = ToLua.ToString(L, 2);
                string             arg1   = ToLua.ToString(L, 3);
                string             arg2   = ToLua.ToString(L, 4);
                UnityEngine.Object o      = obj.LoadAsset(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: NTGResourceController.LoadAsset"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 public object[] LuaDoFile(string scriptName)
 {
     if (lua != null && Initialized)
     {
         return(lua.DoFile(NTGResourceController.LuaPath(scriptName)));
     }
     return(null);
 }
예제 #3
0
    private void Awake()
    {
        if (_instance == null)
        {
            _instance = this;

            //InitBundleDependencies();
        }
    }
 static int BattlePostClearAssetBundle(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         NTGResourceController obj = (NTGResourceController)ToLua.CheckObject(L, 1, typeof(NTGResourceController));
         obj.BattlePostClearAssetBundle();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int InitBundleDependencies(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         NTGResourceController obj = (NTGResourceController)ToLua.CheckObject(L, 1, typeof(NTGResourceController));
         obj.InitBundleDependencies();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int GetFileMD5(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         string arg0 = ToLua.CheckString(L, 1);
         string o    = NTGResourceController.GetFileMD5(arg0);
         LuaDLL.lua_pushstring(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteAllText(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         string arg0 = ToLua.CheckString(L, 1);
         string arg1 = ToLua.CheckString(L, 2);
         NTGResourceController.WriteAllText(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int set_BattleLoadingBundles(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            NTGResourceController obj = (NTGResourceController)o;
            string[] arg0             = ToLua.CheckStringArray(L, 2);
            obj.BattleLoadingBundles = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index BattleLoadingBundles on a nil value" : e.Message));
        }
    }
    static int get_BattleLoadingBundles(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            NTGResourceController obj = (NTGResourceController)o;
            string[] ret = obj.BattleLoadingBundles;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index BattleLoadingBundles on a nil value" : e.Message));
        }
    }
예제 #10
0
 static int UnloadAssetBundle(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         NTGResourceController obj = (NTGResourceController)ToLua.CheckObject(L, 1, typeof(NTGResourceController));
         string arg0 = ToLua.CheckString(L, 2);
         bool   arg1 = LuaDLL.luaL_checkboolean(L, 3);
         bool   arg2 = LuaDLL.luaL_checkboolean(L, 4);
         bool   o    = obj.UnloadAssetBundle(arg0, arg1, arg2);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #11
0
        public virtual string FindFileError(string fileName)
        {
            if (Path.IsPathRooted(fileName))
            {
                return(fileName);
            }

            StringBuilder sb = StringBuilderCache.Acquire();

            if (fileName.EndsWith(".lua"))
            {
                fileName = fileName.Substring(0, fileName.Length - 4);
            }

            for (int i = 0; i < searchPaths.Count; i++)
            {
                sb.AppendFormat("\n\tno file '{0}'", searchPaths[i]);
            }

            sb = sb.Replace("?", fileName);

            sb.AppendFormat("\n\tno file '{0}'", NTGResourceController.LuaPath(fileName));

            if (beZip)
            {
                int    pos    = fileName.LastIndexOf('/');
                string bundle = "";

                if (pos > 0)
                {
                    bundle = fileName.Substring(0, pos);
                    bundle = bundle.Replace('/', '_');
                    bundle = string.Format("lua_{0}.unity3d", bundle);
                }
                else
                {
                    bundle = "lua.unity3d";
                }

                sb.AppendFormat("\n\tno file '{0}' in {1}", fileName, bundle);
            }

            return(StringBuilderCache.GetStringAndRelease(sb));
        }
예제 #12
0
        public string FindFile(string fileName)
        {
            if (fileName == string.Empty)
            {
                return(string.Empty);
            }

            if (Path.IsPathRooted(fileName))
            {
                if (!fileName.EndsWith(".lua"))
                {
                    fileName += ".lua";
                }

                return(fileName);
            }

            if (fileName.EndsWith(".lua"))
            {
                fileName = fileName.Substring(0, fileName.Length - 4);
            }

            string fullPath = null;

            for (int i = 0; i < searchPaths.Count; i++)
            {
                fullPath = searchPaths[i].Replace("?", fileName);

                if (File.Exists(fullPath))
                {
                    return(fullPath);
                }
            }

            fullPath = NTGResourceController.LuaPath(fileName);
            if (File.Exists(fullPath))
            {
                return(fullPath);
            }

            return(null);
        }
    private IEnumerator doUpdateResources()
    {
        if (!NTGApplicationConfig.ResourceUpdateEnabled)
        {
            StartGameManager();
            yield break;
        }

        LuaCall("UpdateResourceAPI", "ShowUpdateInfo", UpdateResourcePanelApi, 1, 0);

        string dataPath = NTGResourceController.DataPath; //数据目录
        string url      = NTGApplicationConfig.ResourceUpdateUrl_Android;

        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXEditor)
        {
            url = NTGApplicationConfig.ResourceUpdateUrl_IOS;
        }

        WWW www = new WWW(url + "files.txt");

        yield return(www);

        if (www.error != null)
        {
            Debug.LogError("Update Resources Failed! :" + www.error.ToString());
            StartGameManager();
            yield break;
        }

        var updateUrls  = new ArrayList();
        var updateFiles = new ArrayList();

        File.WriteAllBytes(dataPath + "files.txt", www.bytes);
        string[] files = www.text.Split('\n');
        for (int i = 0; i < files.Length; i++)
        {
            var file = files[i];
            if (string.IsNullOrEmpty(file))
            {
                continue;
            }

            string[] keyValue  = file.Split('|');
            string   filename  = keyValue[0];
            string   localfile = (dataPath + filename).Trim();
            string   path      = Path.GetDirectoryName(localfile);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string fileUrl    = url + filename;
            bool   needUpdate = !File.Exists(localfile);
            if (!needUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = NTGResourceController.GetFileMD5(localfile);
                needUpdate = !remoteMd5.Equals(localMd5);
            }

            if (needUpdate)
            {
                updateUrls.Add(fileUrl);
                updateFiles.Add(localfile);
            }
        }

        LuaCall("UpdateResourceAPI", "ShowUpdateInfo", UpdateResourcePanelApi, 2, 0);
        LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, 0, 0);
        for (int i = 0; i < updateFiles.Count; i++)
        {
            File.Delete((string)updateFiles[i]);

            var downloader = new NTGResourceController.FileDownloder();

            Debug.Log("Updating File:>" + updateUrls[i]);
            //LuaCall("UpdateResourceAPI", "DebugText", UpdateResourcePanelApi, "下载:" + keyValue[0]);

            downloader.DownloadFile((string)updateUrls[i], (string)updateFiles[i]);
            while (!downloader.DownloadComplete)
            {
                yield return(null);

                LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, downloader.DownloadingSpeed, ((float)i) / updateUrls.Count);
            }

            LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, downloader.DownloadingSpeed, ((float)i + 1) / updateUrls.Count);
            yield return(null);
        }

        StartGameManager();
    }
예제 #14
0
 public void Close()
 {
     rc     = null;
     Asset  = null;
     bundle = null;
 }
예제 #15
0
 public AssetLoader()
 {
     this.rc = NTGResourceController.Instance;
 }
예제 #16
0
    /// <summary>
    /// 生成绑定素材
    /// </summary>
    public static void BuildAssetResource(BuildTarget target, bool isWin)
    {
        string dataPath = NTGResourceController.DataPath;

        if (Directory.Exists(dataPath))
        {
            Directory.Delete(dataPath, true);
        }
        string assetfile = string.Empty; //素材文件名
        string resPath   = AppDataPath + "/StreamingAssets/";

        if (!Directory.Exists(resPath))
        {
            Directory.CreateDirectory(resPath);
        }

        BuildPipeline.BuildAssetBundles(resPath, BuildAssetBundleOptions.None, target);

        string luaPath = resPath + "/lua/";

        //----------复制Lua文件----------------
        if (Directory.Exists(luaPath))
        {
            Directory.Delete(luaPath, true);
        }
        Directory.CreateDirectory(luaPath);

        paths.Clear();
        files.Clear();
        string luaDataPath = Application.dataPath + "/Lua/".ToLower();

        Recursive(luaDataPath);
        int n = 0;

        foreach (string f in files)
        {
            if (f.EndsWith(".meta"))
            {
                continue;
            }
            string newfile = f.Replace(luaDataPath, "");
            string newpath = luaPath + newfile;
            string path    = Path.GetDirectoryName(newpath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (File.Exists(newpath))
            {
                File.Delete(newpath);
            }
            if (NTGApplicationConfig.LuaEncode)
            {
                UpdateProgress(n++, files.Count, newpath);
                EncodeLuaFile(f, newpath, isWin);
            }
            else
            {
                File.Copy(f, newpath, true);
            }
        }

        paths.Clear();
        files.Clear();
        luaDataPath = Application.dataPath + "/ToLua/Lua/".ToLower();
        Recursive(luaDataPath);
        n = 0;
        foreach (string f in files)
        {
            if (f.EndsWith(".meta"))
            {
                continue;
            }
            string newfile = f.Replace(luaDataPath, "");
            string newpath = luaPath + newfile;
            string path    = Path.GetDirectoryName(newpath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (File.Exists(newpath))
            {
                File.Delete(newpath);
            }
            if (NTGApplicationConfig.LuaEncode)
            {
                UpdateProgress(n++, files.Count, newpath);
                EncodeLuaFile(f, newpath, isWin);
            }
            else
            {
                File.Copy(f, newpath, true);
            }
        }

        EditorUtility.ClearProgressBar();

        ///----------------------创建文件列表-----------------------
        string newFilePath = resPath + "/files.txt";

        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear();
        files.Clear();
        Recursive(resPath);

        FileStream   fs = new FileStream(newFilePath, FileMode.CreateNew);
        StreamWriter sw = new StreamWriter(fs);

        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (file.EndsWith(".meta") || file.Contains(".DS_Store"))
            {
                continue;
            }

            string md5   = NTGResourceController.GetFileMD5(file);
            string value = file.Replace(resPath, string.Empty);
            sw.WriteLine(value + "|" + md5);
        }
        sw.Close();
        fs.Close();
        AssetDatabase.Refresh();
    }