Ejemplo n.º 1
0
    /// <summary>
    /// 处理Lua代码包
    /// </summary>
    static void HandleLuaBundle()
    {
        string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir;

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

        string[] srcDirs = { CustomSettings.luaDir, CustomSettings.FrameworkPath + "/ToLua/Lua" };
        for (int i = 0; i < srcDirs.Length; i++)
        {
            if (AppConst.LuaByteMode)
            {
                string   sourceDir = srcDirs[i];
                string[] files     = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories);
                int      len       = sourceDir.Length;

                if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\')
                {
                    --len;
                }
                for (int j = 0; j < files.Length; j++)
                {
                    string str  = files[j].Remove(0, len);
                    string dest = streamDir + str + ".bytes";
                    string dir  = Path.GetDirectoryName(dest);
                    Directory.CreateDirectory(dir);
                    EncodeLuaFile(files[j], dest);
                }
            }
            else
            {
                ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], streamDir);
            }
        }
        string[] dirs = Directory.GetDirectories(streamDir, "*", SearchOption.AllDirectories);
        for (int i = 0; i < dirs.Length; i++)
        {
            string name = dirs[i].Replace(streamDir, string.Empty);
            name = name.Replace('\\', '_').Replace('/', '_');
            name = "lua/lua_" + name.ToLower() + AppConst.ExtName;

            string path = "Assets" + dirs[i].Replace(Application.dataPath, "");
            AddBuildMap(name, "*.bytes", path);
        }
        AddBuildMap("lua/lua" + AppConst.ExtName, "*.bytes", "Assets/" + AppConst.LuaTempDir);

        //-------------------------------处理非Lua文件----------------------------------
        string luaPath = AppDataPath + "/StreamingAssets/lua/";

        for (int i = 0; i < srcDirs.Length; i++)
        {
            paths.Clear(); files.Clear();
            string luaDataPath = srcDirs[i].ToLower();
            Recursive(luaDataPath);
            foreach (string f in files)
            {
                if (f.EndsWith(".meta") || f.EndsWith(".lua"))
                {
                    continue;
                }
                string newfile = f.Replace(luaDataPath, "");
                string path    = Path.GetDirectoryName(luaPath + newfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string destfile = path + "/" + Path.GetFileName(f);
                File.Copy(f, destfile, true);
            }
        }
        AssetDatabase.Refresh();
    }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     ToLuaMenu.GenLuaAll();
     Console.Read();
 }
Ejemplo n.º 3
0
 private static void ClearLuaWraps()
 {
     ToLuaMenu.ClearLuaWraps();
 }
Ejemplo n.º 4
0
    public static bool BuildGame(GameBuilderParameter para)
    {
        Debug.Log("Build Game Start and Para is:" + para);

        if (!para.BuildVersion.CheckConstraint())
        {
            Debug.LogError("BuildVersion not pass constraint! version:" + para.BuildVersion.GetVersionString());
            return(false);
        }

        try
        {
            if (para.BuildTarget == BuildTarget.iOS)
            {
                para.UseMono2X = false;
                Debug.Log("ios platform always use IL2ccpp. is not will compiler error");
            }

            // 处理热更url
            if (!HandleHotFix(para))
            {
                return(false);
            }
            Debug.Log("Clear " + Application.streamingAssetsPath);
            FileUtils.ClearDirectoryReadOnly(Application.streamingAssetsPath);
            FileUtils.ClearDirectory(Application.streamingAssetsPath);
            SetupSetting(para);

            // build lua bundle
            Debug.Log("Start MarkBundlesNames ");
            ToLuaMenu.MarkBundlesNames();
            Debug.Log("End MarkBundlesNames ");

            if (para.ApplyAllRule)
            {
                Debug.Log("Start ApplyAllRule ");
                AssetBundleRuleUtils.ApplyAll(null, true);
                Debug.Log("ApplyAllRule finish ");
            }

            string sourcePath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName());
            if (!para.IncreativeBuildAssetBundles)
            {
                Debug.Log("Clear Assetbundle dir:" + sourcePath);
                FileUtils.ClearDirectoryReadOnly(sourcePath);
                FileUtils.ClearDirectory(sourcePath);
                Debug.Log("finish Clear Assetbundle dir:");
            }

            Debug.Log("BuildAssetBundles to " + sourcePath);
            BuildScript.BuildAssetBundles(null, para.BundleCompress ? ToLuaMenu.GetBuildAssetBundleOptions(): BuildAssetBundleOptions.None);
            Debug.Log("BuildAssetBundles finish ");

            Debug.Log("Start CopyDirectory to Streaming");
            FileUtils.CopyDirectory(sourcePath, VersionConst.StreamingVersionPath);
            Debug.Log("Finish CopyDirectory to Streaming");

            // 这个放在下面,不然会被前面的删除掉
            if (para.CopyFmod)
            {
                // -音效引擎相关代码,放在打包资源之后因为会清理打包资源-//
                Debug.Log("CopyToStreamingAssets---------------------------------------");
                //EventManager.DoCopyToStreamingAssets();
                Debug.Log("MasterBankName---------------------------------------");
            }
            Debug.Log("GenHotFixFileListAndCheckConflict");
            AssetBundleRuleUtils.GenHotFixFileListAndCheckConflict();
            bool bOk = true;
            if (para.BuildMode == BuildMode.Patch || para.BuildMode == BuildMode.All)
            {
                Debug.Log("开始生成补丁");
                VersionPatchBuilder patchBuilder = new VersionPatchBuilder(para.BuildTarget, para.BuildVersion, para.BuildNumber);
                if (!patchBuilder.Build())
                {
                    bOk = false;
                }

                Debug.Log("结束生成补丁");
            }

            // 如果要求生成补丁,但补丁失败,则包也
            if (bOk && (para.BuildMode == BuildMode.Package || para.BuildMode == BuildMode.All))
            {
                Debug.Log("开始写入发布时版本信息:" + VersionConst.ReleasedVersionPath);
                // 写入发布版本信息
                SaveReleasedVersionFile(para.BuildVersion, VersionConst.ReleasedVersionPath);
                Debug.Log("结束写入发布时版本信息");

                Debug.Log("开始生成安装包");
                string[] levels = BuilderEditorUtils.GetBuildScenes();
                var      error  = BuildPipeline.BuildPlayer(levels
                                                            , para.OutputPath
                                                            , para.BuildTarget
                                                            , para.BuildOptions);
                if (!string.IsNullOrEmpty(error))
                {
                    Debug.LogError("Build failed: " + error);
                    bOk = false;
                }
                Debug.Log("结束生成安装包");
            }

            return(bOk);
        }
        catch (Exception e)
        {
            Debug.LogError("error BuildGame stderror exception: " + e.Message);
            return(false);
        }
    }
Ejemplo n.º 5
0
    static void HandleLuaBundle(ref List <AssetBundleBuild> buildList)
    {
        // 先把lua文件拷贝到临时目录
        string tempLuaDir = Application.dataPath + tempLua;

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

        string[] srcDirs = { Application.dataPath + "/Lua", Application.dataPath + "/ToLua/Lua" };
        for (int i = 0; i < srcDirs.Length; i++)
        {
            if (AppDefine.LuaByteMode)
            {
                string   sourceDir = srcDirs[i];
                string[] files     = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories);
                int      len       = sourceDir.Length;

                if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\')
                {
                    --len;
                }
                for (int j = 0; j < files.Length; j++)
                {
                    string str  = files[j].Remove(0, len);
                    string dest = tempLuaDir + str + ".bytes";
                    string dir  = Path.GetDirectoryName(dest);
                    Directory.CreateDirectory(dir);
                    EncodeLuaFile(files[j], dest);
                }
            }
            else
            {
                ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], tempLuaDir);
            }
        }

        // 对临时目录的每个子文件夹的lua按文件夹打包
        string[] dirs = Directory.GetDirectories(tempLuaDir, "*", SearchOption.AllDirectories);
        for (int i = 0; i < dirs.Length; i++)
        {
            string name = dirs[i].Replace(tempLuaDir, string.Empty);
            name = name.Replace('\\', '_').Replace('/', '_');
            name = "lua/lua_" + name.ToLower() + ".unity3d";

            string path = "Assets" + dirs[i].Replace(Application.dataPath, "");
            AddBuildMap(ref buildList, name, "*.bytes", path);
        }
        // 对临时目录根部的lua打一个包
        AddBuildMap(ref buildList, "lua/lua" + ".unity3d", "*.bytes", "Assets" + tempLua);

        //-------------------------------处理非Lua文件----------------------------------
        string luaTargetPath = AppDataPath + "/StreamingAssets/lua/";

        for (int i = 0; i < srcDirs.Length; i++)
        {
            string        luaDataPath = srcDirs[i].ToLower();
            List <string> paths       = new List <string>();
            List <string> files       = new List <string>();
            Recursive(luaDataPath, ref paths, ref files);
            foreach (string f in files)
            {
                if (f.EndsWith(".meta") || f.EndsWith(".lua"))
                {
                    continue;
                }
                string newfile  = f.Replace(luaDataPath, "");
                string destPath = Path.GetDirectoryName(luaTargetPath + newfile);
                if (!Directory.Exists(destPath))
                {
                    Directory.CreateDirectory(destPath);
                }

                string destfile = destPath + "/" + Path.GetFileName(f);
                File.Copy(f, destfile, true);
            }
        }
        AssetDatabase.Refresh();
    }
 public static void clearAndBuild()
 {
     PlayerPrefs.SetInt("clearAndBuild", 1);
     ToLuaMenu.ClearLuaWraps();
 }