예제 #1
0
    static void VersionsDifferenceZipImp(string oldVersionDir, string newVersionDir)
    {
        oldVersionDir = MyFileUtil.DealFilePathSlash(oldVersionDir);
        newVersionDir = MyFileUtil.DealFilePathSlash(newVersionDir);

        List <string> oldFileList = new List <string>();
        List <string> newFileList = new List <string>();

        MyFileUtil.GetFileList(oldVersionDir, ref oldFileList);
        MyFileUtil.GetFileList(newVersionDir, ref newFileList);

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

        foreach (string newFilePath in newFileList)
        {
            int index = oldFileList.IndexOf(newFilePath);
            if (index < 0)
            {
                //添加新的文件
                modificationFileList.Add(newFilePath);
            }
            else
            {
                string oldFilePath = oldFileList[index];
                if (MD5Tool.VerifyFile(newFilePath, oldFilePath) == false)
                {
                    //文件改变
                    modificationFileList.Add(newFilePath);
                }
            }
        }

        //string time = System.DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");

        string modificationDir = MyFileUtil.GetParentDir(newVersionDir) + "update_tmp";

        MyFileUtil.DeleteDir(modificationDir);
        MyFileUtil.CreateDir(modificationDir);

        foreach (string filePath in modificationFileList)
        {
            string newFilePath = filePath.Replace(newVersionDir, modificationDir);
            MyFileUtil.CopyFile(filePath, newFilePath);
        }

        string zipFilePath = modificationDir + ".zip";

        ZIPTool.CompressDirectory(modificationDir, zipFilePath, 0, false);

        Debug.Log("");
    }
예제 #2
0
    public static void BuildAllAssetBundles()
    {
        string assetbundlePath = ResourcesManager.AssetBundlesResDirInStreamingAssetsPath;

        //先删除所有旧文件
        string rootDir = MyFileUtil.GetParentDir(assetbundlePath);

        MyFileUtil.DeleteDir(rootDir);
        MyFileUtil.CreateDir(assetbundlePath);

        //获取文件列表
        List <string> fileList = ResourcesManager.GenerateFileList(ResourcesManager.DirForAssetBundlesBuildFrom);

        //-------------------------------------------------------------//

        List <AssetBundleBuild> bundleList = new List <AssetBundleBuild>();

        for (int i = 0; i < fileList.Count; ++i)
        {
            string filePath = fileList[i];
            if (filePath.EndsWith(".meta"))
            {
                continue;
            }

            List <string> assetList = new List <string>();
            string        assetPath = filePath.Substring(filePath.IndexOf("Assets"));
            assetList.Add(assetPath);

            string dirNameForAssetBundlesBuildFrom = "/" + ResourcesManager.DirNameForAssetBundlesBuildFrom + "/";
            int    startPos = assetPath.IndexOf(dirNameForAssetBundlesBuildFrom) + dirNameForAssetBundlesBuildFrom.Length;
            //int endPos = assetPath.LastIndexOf(".");
            //string assetBundleName = assetPath.Substring(startPos, endPos - startPos);
            string assetBundleName = assetPath.Substring(startPos);

            AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
            assetBundleBuild.assetBundleName = assetBundleName + ResourcesManager.mAssetBundleSuffix;
            //assetBundleBuild.assetBundleVariant = ResourcesManager.mAssetBundleSuffix.Replace(".", "");
            assetBundleBuild.assetNames = assetList.ToArray();

            bundleList.Add(assetBundleBuild);
        }

        BuildPipeline.BuildAssetBundles(assetbundlePath, bundleList.ToArray(), BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);

        Debug.Log("BuildAssetBundles Over");
    }
예제 #3
0
    //-----------------------------------------------------------------------------------//

    //检查安装包中版本号和本地版本号--可能在游戏重新安装时缓存文件没被清理
    public void CheckInstallationPackageVersionWithLocal(Action callback = null)
    {
        MyFileUtil.ReadConfigDataInCacheDirAsync(VersionInfoFilePath, (outText) =>
        {
            if (outText == null)
            {
                if (callback != null)
                {
                    callback();
                }
                return;
            }

            //判断本地版本号和包体内部版本号
            MyFileUtil.ReadConfigDataInStreamingAssetsAsync(VersionInfoFilePath, (innerText) =>
            {
                VersionInfo innerVersionInfo = VersionInfo.ParseData(innerText);

                VersionInfo outVersionInfo = VersionInfo.ParseData(outText);

                if (innerVersionInfo.ProgramVersion > outVersionInfo.ProgramVersion)
                {
                    //清空本地资源
                    MyFileUtil.DeleteDir(MyFileUtil.CacheDir);
                    MyFileUtil.CreateDir(MyFileUtil.CacheDir);
                }

                /*
                 * foreach(var item in innerVersionInfo.dictRes)
                 * {
                 *  if(outVersionInfo.dictRes.ContainsKey(item.Key))
                 *  {
                 *      ResInfo outResInfo = outVersionInfo.dictRes[item.Key];
                 *  }
                 * }
                 */

                Debug.Log("VersionManager.CheckLocalLuaCodeVersion");
                if (callback != null)
                {
                    callback();
                }
            });
        });
    }
예제 #4
0
    static void GenerateResZipImp(string rootDir)
    {
        string dirRemove = rootDir + "Assets/StreamingAssets";

        string publishDir = rootDir + "Publish/" +
                            MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
                            + "/";

        // if (PackageWizard.m_wizard)
        // {
        //     publishDir += PackageWizard.m_wizard.version;
        // }

        MyFileUtil.DeleteDir(publishDir);
        MyFileUtil.CreateDir(publishDir);

        List <ResInfo> listResInfo = new List <ResInfo>();

        //----------------------------------------------------//

        List <ZipResConfig> listZipConfig = ZipResConfig.GetConfigList();

        foreach (ZipResConfig zipConfig in listZipConfig)
        {
            //生成Zip资源包
            List <string> fileList = new List <string>();

            if (string.IsNullOrEmpty(zipConfig.resDir) == false)
            {
                string fileDir = rootDir + zipConfig.resDir;

                if (fileDir.Contains("@Platform"))
                {
                    fileDir = fileDir.Replace("@Platform", ResourcesManager.GetPlatformDir());
                }

                if (fileDir.Contains("@Version"))
                {
                    // fileDir = fileDir.Replace("@Version", SDKConfig.GetCurrentVersionResPath().ToLower());
                    fileDir = fileDir.Replace("@Version", "test");
                }

                if (Directory.Exists(fileDir))
                {
                    List <string> ignoreFileTypeList = new List <string>();
                    ignoreFileTypeList.Add(".meta");
                    MyFileUtil.GetFileList(fileDir, ref fileList, zipConfig.listResSuffix, ignoreFileTypeList);
                }
            }

            //特殊文件
            foreach (string specialResPath in zipConfig.listSpecialResPath)
            {
                string newFilePath = rootDir + specialResPath;
                if (File.Exists(newFilePath))
                {
                    fileList.Add(newFilePath);
                }
            }

            if (fileList.Count == 0)
            {
                continue;
            }

            //zip中不记录文件的时间
            string zipResFilePath;
            // if (PackageWizard.m_wizard)
            // {
            //     zipResFilePath = rootDir + "Publish/" +
            //     MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
            //     + "/" + PackageWizard.m_wizard.version + "/" + zipConfig.resZipName;
            // }
            // else
            // {
            zipResFilePath = rootDir + "Publish/" +
                             MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
                             + "/" + zipConfig.resZipName;
            // }
            ZIPTool.CompressFiles(fileList, dirRemove, zipResFilePath, 0, false, true);

            //资源信息
            ResInfo resInfo = new ResInfo();
            resInfo.resName      = zipConfig.resZipName;
            resInfo.resMD5       = MD5Tool.GetByFilePath(zipResFilePath);
            resInfo.resSize      = (int)MyFileUtil.GetFileSize(zipResFilePath);
            resInfo.resRequireID = zipConfig.resRequireID;
            // if (PackageWizard.m_wizard)
            // {
            //     resInfo.resURL = PackageWizard.m_wizard.serverAddress + resInfo.resName;
            // }
            // else
            // {
            resInfo.resURL = resInfo.resName;
            // }

            listResInfo.Add(resInfo);
        }

        //----------------------------------------------------//
        //写到发布目录
        string xmlContent = VersionInfo.SerializeInEditor(listResInfo);
        string xmlFilePath;

        // if (PackageWizard.m_wizard)
        // {
        //     xmlFilePath = rootDir + "Publish/" +
        //     MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
        //     + "/" + PackageWizard.m_wizard.version + "/VersionInfo.xml";
        // }
        // else
        // {
        xmlFilePath = rootDir + "Publish/" +
                      MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/VersionInfo.xml";
        // }

        File.WriteAllText(xmlFilePath, xmlContent);

        listResInfo.RemoveAll(r => r.resRequireID > 0);
        xmlContent = VersionInfo.SerializeInEditor(listResInfo);
        //写到工程目录
        string xmlFileInProjectPath = rootDir + "Assets/StreamingAssets/Config/" + VersionManager.VersionInfoFilePath + MyFileUtil.EncryptXMLFileSuffix;

        byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(xmlContent);
        data = MyFileUtil.EncryptData(data);
        File.WriteAllBytes(xmlFileInProjectPath, data);
        Debug.Log("生成资源包结束");
    }
예제 #5
0
    static void BuildImp(bool isBuildAssetBundle)
    {
        //清理缓存目录
        MyFileUtil.DeleteDir(MyFileUtil.CacheDir);
        MyFileUtil.CreateDir(MyFileUtil.CacheDir);
        //if(MyFileUtil.IsFileExsit(Application.dataPath + "/../Publish/"))
        //{

        MyFileUtil.CreateDir(Application.dataPath + "/../Publish/" +
                             MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/");
        //}
        //清理publish目录
        string publishDir = Application.dataPath + "/../Publish/" +
                            MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/";

        // MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/" + PackageWizard.m_wizard.version + "/";
        MyFileUtil.DeleteDir(publishDir);
        MyFileUtil.CreateDir(publishDir);

        //警告————首先加密配置文件
        //加密配置文件
        EncodeConfigFile();

        //生成图集信息文件
        GenerateAtlasInfoFile();

        //加密Lua代码
        EncryptLuaCode();

        //编译资源
        if (isBuildAssetBundle)
        {
            BuildAllAssetBundles();
        }

        //拷贝工程
        CopyProject();

        //删除不需要资源
        ClearRes();

        //生成拷贝工程资源列表
        GenerateCopyProjectFileList();

        //生成资源包
        GenerateTargetProjectResZip();


#if UNITY_ANDROID
        //删除目标工程的子游戏bundle
        MyFileUtil.DeleteDir(string.Format("{0}Assets/StreamingAssets/AssetBundles/{1}/qile/games", CopyProjectTargetDir, ResourcesManager.GetPlatformDir()));
#elif UNITY_IPHONE
        var subGameParentDir = string.Format("{0}Assets/StreamingAssets/AssetBundles/{1}/qile/games", CopyProjectTargetDir, ResourcesManager.GetPlatformDir());
        var subGameDirs      = new List <string>
        {
            subGameParentDir + "/commonddz",
            subGameParentDir + "/commonpdk",
            subGameParentDir + "/commonpoker",
            subGameParentDir + "/csmj",
            subGameParentDir + "/ddz",
            subGameParentDir + "/ddz3r",
            subGameParentDir + "/emmj",
            subGameParentDir + "/fpf",
            subGameParentDir + "/gymj",
            subGameParentDir + "/jsmj",
            subGameParentDir + "/lxmj",
            subGameParentDir + "/niuniu",
            subGameParentDir + "/njmj",
            subGameParentDir + "/pdk",
            subGameParentDir + "/ssz",
            subGameParentDir + "/ybmj",
            subGameParentDir + "/zzmj"
        };

        foreach (var dir in subGameDirs)
        {
            MyFileUtil.DeleteDir(dir);
        }
#endif

        AssetDatabase.Refresh();
        Debug.Log("打包准备结束");
    }
예제 #6
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        {
            GUILayout.Label(generatePath, EditorStyles.numberField);
            if (GUILayout.Button("select", GUILayout.Width(window.position.width / 10)))
            {
                generatePath = EditorUtility.OpenFolderPanel("MVC View Code Path", generatePath, "");
                generatePath = string.IsNullOrEmpty(generatePath) ? Application.streamingAssetsPath : generatePath;
                PlayerPrefs.SetString("MVC View Code Path", generatePath);
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        {
            GUILayout.Label("Name:", GUILayout.Width(window.position.width / 10));
            viewName = EditorGUILayout.TextField(viewName, GUILayout.Width(window.position.width * 4 / 10));
            GUILayout.Label("Layer:", GUILayout.Width(window.position.width / 10));
            layerIndex = EditorGUILayout.Popup(layerIndex, new string[] { "Noraml	Layer", "Top	Layer"}, GUILayout.Width(window.position.width * 4 / 10));
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Generate Code"))
        {
            if (string.IsNullOrEmpty(viewName))
            {
                EditorUtility.DisplayDialog("Tips", "No View Name", "OK");
                return;
            }
            var dir = generatePath + "/" + viewName + "/";
            MyFileUtil.CreateDir(dir);
            var newPath = dir.Substring(dir.IndexOf("Assets")).Replace(LuaConst.luaDir.Substring(LuaConst.luaDir.IndexOf("Assets")) + "/", "");
            Debug.Log("dir:" + dir.Substring(dir.IndexOf("Assets")));

            Debug.Log("LuaConst.luaDir:" + LuaConst.luaDir.Substring(LuaConst.luaDir.IndexOf("Assets")));
            Debug.Log("newPath:" + newPath);
            //head
            var headFilePath = dir + viewName + "Head.lua";
            MyFileUtil.CopyFile(TemplateHeadLuaFilePath, headFilePath);
            var headLua = MyFileUtil.ReadFileText(headFilePath);
            headLua = headLua.Replace(PATH, newPath);
            headLua = headLua.Replace(NAME, viewName);
            headLua = headLua.Replace(SNAME, viewName.ToLower());
            headLua = headLua.Replace(UILAYER, UILAYERS[layerIndex]);
            MyFileUtil.WriteFile(headFilePath, headLua);

            //view
            var viewFilePath = dir + viewName + "View.lua";
            MyFileUtil.CopyFile(TemplateViewLuaFilePath, viewFilePath);
            var viewLua = MyFileUtil.ReadFileText(viewFilePath);
            viewLua = viewLua.Replace(NAME, viewName);
            viewLua = viewLua.Replace(SNAME, viewName.ToLower());
            MyFileUtil.WriteFile(viewFilePath, headLua);

            //controller
            var controllerFilePath = dir + viewName + "Controller.lua";
            MyFileUtil.CopyFile(TemplateControllerLuaFilePath, controllerFilePath);
            var controllerLua = MyFileUtil.ReadFileText(controllerFilePath);
            controllerLua = controllerLua.Replace(NAME, viewName);
            controllerLua = controllerLua.Replace(SNAME, viewName.ToLower());
            MyFileUtil.WriteFile(controllerFilePath, controllerLua);

            //model
            var modelFilePath = dir + viewName + "Model.lua";
            MyFileUtil.CopyFile(TemplateModelLuaFilePath, modelFilePath);
            var modelLua = MyFileUtil.ReadFileText(modelFilePath);
            modelLua = modelLua.Replace(NAME, viewName);
            modelLua = modelLua.Replace(SNAME, viewName.ToLower());
            MyFileUtil.WriteFile(modelFilePath, modelLua);
            AssetDatabase.Refresh();
            EditorUtility.DisplayDialog("Tips", "Generate Code Over!", "OK");
        }
    }