Пример #1
0
    //[MenuItem("Hugula/export config [Assets\\Config]", false, 13)]
    public static void exportConfig()
    {
        string path = Application.dataPath + "/Config";       //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string>             files     = getAllChildFiles(path + "/", "csv");
        string                    assetPath = "Assets/Config";
        List <UnityEngine.Object> res       = new List <Object>();

        foreach (string name in files)
        {
            string abPath = assetPath + name.Replace(path, "");
            Debug.Log(abPath);
            Object txt = AssetDatabase.LoadAssetAtPath(abPath, typeof(TextAsset));
            res.Add(txt);
        }

        string cname   = "/font1.u3d";
        string outPath = ExportAssetBundles.GetOutPath();
        string tarName = outPath + cname;

        Object[] ress = res.ToArray();
        Debug.Log(ress.Length);
        ExportAssetBundles.BuildAB(null, ress, tarName, BuildAssetBundleOptions.CompleteAssets);
        Debug.Log(tarName + " export");
    }
Пример #2
0
    //public void UpdateAsset(string assetName, string path, string[] depbundle)
    //{
    //    //查找asset
    //    XmlNodeList nodeList = xmlBundle.ChildNodes;
    //    XmlElement assetEle = null;
    //    foreach (XmlNode xn in nodeList)
    //    {
    //        assetEle = (XmlElement)xn;
    //        if (assetEle.GetAttribute("name") == assetName)
    //            break;
    //        assetEle = null;
    //    }

    //    if (assetEle == null)
    //    {
    //        assetEle = xmlDoc.CreateElement("Asset");
    //        xmlBundle.AppendChild(assetEle);
    //    }
    //    else
    //    {
    //        assetEle.RemoveAll();
    //    }

    //    assetEle.SetAttribute("name", assetName);
    //    assetEle.SetAttribute("path", path);

    //    if (depbundle != null)
    //    {
    //        foreach (string dep in depbundle)
    //        {
    //            XmlElement depEle = xmlDoc.CreateElement("Dep");
    //            depEle.InnerText = dep;
    //            assetEle.AppendChild(depEle);
    //        }
    //    }
    //}

    public void Close()
    {
        string path = ExportAssetBundles.GetOutPath() + "/" + ASSETINFO_FILE;

        if (xmlDoc != null)
        {
            xmlDoc.Save(path);
        }

        xmlDoc    = null;
        xmlRoot   = null;
        xmlBundle = null;
    }
Пример #3
0
    public void Open()
    {
        string path = ExportAssetBundles.GetOutPath() + "/" + ASSETINFO_FILE;

        xmlDoc = new XmlDocument();
        if (File.Exists(path))
        {
            xmlDoc.Load(path);
        }

        xmlRoot = xmlDoc.SelectSingleNode("AssetBundles");
        if (xmlRoot == null)
        {
            xmlRoot = xmlDoc.CreateElement("AssetBundles");
            xmlDoc.AppendChild(xmlRoot);
        }
    }
Пример #4
0
    //[MenuItem("Hugula/export language [Assets\\Lan]", false, 14)]
    public static void exportLanguage()
    {
        string assetPath = "Assets/Lan/";
        string path      = Application.dataPath + "/Lan/"; //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path, "csv");

        foreach (string name in files)
        {
            string abPath = assetPath + name.Replace(path, "");
            Debug.Log(abPath);
            Object txt     = AssetDatabase.LoadAssetAtPath(abPath, typeof(TextAsset));
            string cname   = txt.name;
            string outPath = ExportAssetBundles.GetOutPath();
            string tarName = outPath + "/Lan/" + cname + "." + Common.LANGUAGE_SUFFIX;
            CheckDirectory(Application.streamingAssetsPath + "/" + ExportAssetBundles.GetTarget().ToString() + "/Lan/");
            ExportAssetBundles.BuildAB(txt, null, tarName, BuildAssetBundleOptions.CompleteAssets);
        }
    }
Пример #5
0
    public static void exportLanguage()
    {
        string        assetPath = "Assets/Lan/";
        string        path      = Application.dataPath + "/Lan/"; //AssetDatabase.GetAssetPath(obj).Replace("Assets","");
        List <string> files     = getAllChildFiles(path, "csv");

        string outPath = ExportAssetBundles.GetOutPath();

        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath);
        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath + "/Lan");

        foreach (string name in files)
        {
            string abPath = assetPath + name.Replace(path, "");
//            Debug.Log(abPath);
            string tarPath = outPath + "/Lan";
            string abName  = CUtils.GetURLFileName(name) + "." + Common.LANGUAGE_SUFFIX;
            ExportAssetBundles.BuildABs(new string[] { abPath }, tarPath, abName, BuildAssetBundleOptions.CompleteAssets);
            Debug.Log(tarPath + abName + " export");
        }
    }
Пример #6
0
    public static void exportConfig()
    {
        string path = Application.dataPath + "/Config";       //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files     = getAllChildFiles(path + "/", "csv");
        string        assetPath = "Assets/Config";
        List <string> res       = new List <string>();

        foreach (string name in files)
        {
            string abPath = assetPath + name.Replace(path, "");
            Debug.Log(abPath);
            res.Add(abPath);
        }

        string cname   = "font1.u3d";
        string outPath = ExportAssetBundles.GetOutPath();
        string tarName = outPath + "/" + cname;

        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath);

        ExportAssetBundles.BuildABs(res.ToArray(), outPath, cname, BuildAssetBundleOptions.CompleteAssets);
        Debug.Log(tarName + " export");
    }
Пример #7
0
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua/"; //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //refresh directory
        DirectoryDelete(Application.dataPath + OutLuaPath);
        CheckDirectory(Application.dataPath + OutLuaPath);
        //CheckDirectory(Application.dataPath.Replace("Assets","")+outPath);

        List <string> exportNames    = new List <string> ();

        foreach (string filePath in childrens)
        {
            fileName    = CUtils.GetURLFileName(filePath);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            exportNames.Add("Assets" + OutLuaPath + crypName);
            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath; // luac
            File.Copy(filePath, outfilePath, true);     // source code copy
#else
            arg = "-b " + filePath + " " + outfilePath; //for jit
            //Debug.Log(arg);
            //System.Diagnostics.Process.Start(luacPath, arg);//jit
            File.Copy(filePath, outfilePath, true);// source code copy
#endif
        }
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");
        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //u5 打包
        string outPath = ExportAssetBundles.GetOutPath();
        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath);
        ExportAssetBundles.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.CompleteAssets);

        //Encrypt
        string tarName     = Application.dataPath + OutLuaPath + "luaout.bytes";
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        byte[] Encrypt     = CryptographHelper.Encrypt(by, GetKey(), GetIV());
        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }
Пример #8
0
    //[MenuItem("Hugula/export lua [Assets\\Lua]", false, 12)]
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua";  //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        DirectoryDelete(Application.dataPath + OutLuaPath);

        foreach (string filePath in childrens)
        {
            fileName = CUtils.GetURLFileName(filePath);
            //crypName=CryptographHelper.CrypfString(fileName);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "/");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            checkLuaChildDirectory(outfilePath);

            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath;
            File.Copy(filePath, outfilePath, true);
#else
            arg = "-b " + filePath + " " + outfilePath;             //for jit
            Debug.Log(arg);

            System.Diagnostics.Process.Start(luacPath, arg);//arg -b hello1.lua hello1.out
#endif
        }
        Debug.Log(sb.ToString());
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //打包成assetbundle
        string luaOut = Application.dataPath + OutLuaPath;
        Debug.Log(luaOut);
        List <string>             luafiles       = getAllChildFiles(luaOut + "/", Common.LUA_LC_SUFFIX);
        string                    assetPath      = "Assets" + OutLuaPath;
        List <UnityEngine.Object> res            = new List <Object>();
        string                    relatePathName = "";
        foreach (string name in luafiles)
        {
            relatePathName = name.Replace(luaOut, "");
            string abPath = assetPath + relatePathName;
            Debug.Log(abPath);
            Debug.Log(relatePathName);
            Object txt = AssetDatabase.LoadAssetAtPath(abPath, typeof(TextAsset));
            txt.name = relatePathName.Replace(@"\", @".").Replace("/", "").Replace("." + Common.LUA_LC_SUFFIX, "");
            Debug.Log(txt.name);
            res.Add(txt);
        }

        string   cname   = "/luaout.bytes";
        string   outPath = luaOut;        //ExportAssetBundles.GetOutPath();
        string   tarName = outPath + cname;
        Object[] ress    = res.ToArray();
        Debug.Log(ress.Length);
        ExportAssetBundles.BuildAB(null, ress, tarName, BuildAssetBundleOptions.CompleteAssets);
//         Debug.Log(tarName + " export");
        AssetDatabase.Refresh();

        //Directory.CreateDirectory(luaOut);
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        Debug.Log(by);
        byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV());

        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }