Beispiel #1
0
    private bool CreateOrExploreButton(string path)
    {
        GUILayoutOption[] options =
        {
            GUILayout.Width(44),
        };
        bool isExistExcelExportDir = Directory.Exists(path);

        if (isExistExcelExportDir)
        {
            if (GUILayout.Button("浏览", options))
            {
                if (Directory.Exists(path))
                {
                    WindowsOSUtility.ExploreFile(path);
                }
            }
        }
        else
        {
            if (File.Exists(path))
            {
                if (GUILayout.Button("查看", options))
                {
                    WindowsOSUtility.ExploreFile(path);
                }
            }
        }
        return(isExistExcelExportDir);
    }
    public static void CheckAssetBundleSize(string path, string ext)
    {
        var files = EditorFileUtility.FilterDirectory(path, new string[] { ext });

        if (files != null)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("大于1m的AssetBundle包(建议AssetBundle的包小于1m,最好不要超过2m)");
            foreach (var file in files)
            {
                FileInfo fi = new FileInfo(file.FullName);
                if (fi.Length / 1024 > 1024)
                {
                    sb.AppendLine("\tAssetBundle文件路径:" + fi.FullName);
                    sb.AppendLine("\t\t文件大小:" + (fi.Length / 1024f / 1024f) + "m");
                }
            }

            File.WriteAllText(path + "/AssetBundleSize.txt", sb.ToString());
            WindowsOSUtility.ExploreFile(path);
        }
    }
Beispiel #3
0
    private void ShowBuildUI(string platform)
    {
        versionPart = EditorGUILayout.Foldout(versionPart, "已打版本");
        if (versionPart)
        {
            var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
            if (versionList != null && versionList.Count > 0)
            {
                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(20),
                };

                EditorGUILayout.BeginVertical();
                EditorGUILayout.Space();

                foreach (var v in versionList)
                {
                    if (!m_VersionMap.ContainsKey(v.ToString()))
                    {
                        m_VersionMap.Add(v.ToString(), -1);
                    }

                    var selectIndex = m_VersionMap[v.ToString()];
                    selectIndex = GUILayout.SelectionGrid(selectIndex, new string[] { v.ToString() }, 1);
                    m_VersionMap[v.ToString()] = selectIndex;

                    if (selectIndex == 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();

                        if (GUILayout.Button("浏览", options))
                        {
                            WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString());
                        }

                        if (GUILayout.Button("检查ab包大小", options))
                        {
                            AssetBundleBuilder.CheckAssetBundleSize(m_ExportAssetBundleDir + platform + "/Version/" + v, ".pkg");
                        }

                        if (GUILayout.Button("取消查看", options))
                        {
                            m_VersionMap[v.ToString()] = -1;
                            Repaint();
                        }

                        if (GUILayout.Button("拷贝到StreamingAssets", options))
                        {
                            var targetPath = Application.dataPath + "/StreamingAssets/" + UGCoreConfig.MiddleFilePathName;
                            EditorFileUtility.ClearDirectory(targetPath);
                            EditorFileUtility.CopyDirectory(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), targetPath);
                            AssetDatabase.Refresh();
                            WindowsOSUtility.ExploreFile(targetPath);
                        }

                        if (GUILayout.Button("拷贝到persistentDataPath", options))
                        {
                            var targetPath = Application.persistentDataPath + "/" + UGCoreConfig.MiddleFilePathName + "/" + UGCoreConfig.ResourcesFolderName;
                            EditorFileUtility.ClearDirectory(targetPath);
                            EditorFileUtility.CopyDirectory(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), targetPath);
                            AssetDatabase.Refresh();
                            WindowsOSUtility.ExploreFile(targetPath);
                        }

                        if (GUILayout.Button("删除版本", options))
                        {
                            Directory.Delete(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), true);
                            Repaint();
                        }
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }
        }

        patchPart = EditorGUILayout.Foldout(patchPart, "已打补丁");
        if (patchPart)
        {
            var patchList = GetPatches(m_ExportAssetBundleDir + platform + "/Patches");
            if (patchList != null && patchList.Count > 0)
            {
                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(20),
                };

                EditorGUILayout.BeginVertical();
                EditorGUILayout.Space();

                foreach (var p in patchList)
                {
                    if (!m_VersionMap.ContainsKey(p.ToString()))
                    {
                        m_VersionMap.Add(p.ToString(), -1);
                    }

                    var selectIndex = m_VersionMap[p.ToString()];
                    selectIndex = GUILayout.SelectionGrid(selectIndex, new string[] { p.ToString() }, 1);
                    m_VersionMap[p.ToString()] = selectIndex;

                    if (selectIndex == 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();

                        if (GUILayout.Button("浏览", options))
                        {
                            WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Patches/" + p);
                        }

                        if (GUILayout.Button("取消查看", options))
                        {
                            m_VersionMap[p.ToString()] = -1;
                            Repaint();
                        }

                        if (GUILayout.Button("删除补丁", options))
                        {
                            Directory.Delete(m_ExportAssetBundleDir + platform + "/Patches/" + p, true);
                            Repaint();
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }
        }

        GUIContent[] guiBuildObjs =
        {
            new GUIContent("打版本"),
            new GUIContent("打补丁"),
        };

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        m_BuildOperation = (BuildOperation)GUILayout.Toolbar((int)m_BuildOperation, guiBuildObjs);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (m_BuildOperation == BuildOperation.Version)
        {
            m_CreateVersion = EditorGUILayout.TextField("打包版本号:", m_CreateVersion);

            GUILayoutOption[] options =
            {
                GUILayout.Width(150),
                GUILayout.Height(26),
            };
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("重新打包版本(慎用)", options))
            {
                var versionNumber = ValidVersion(m_CreateVersion);
                if (versionNumber == null)
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本名称不符合规范,请重新输入"));
                    return;
                }

                if (!Directory.Exists(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber))
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本号未经过打包,请使用打包版本选项来打包"));
                    return;
                }

                CreateVersion(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber, true);
                WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
            }
            if (GUILayout.Button("打包版本", options))
            {
                var versionNumber = ValidVersion(m_CreateVersion);
                if (versionNumber == null)
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本名称不符合规范,请重新输入"));
                    return;
                }

                if (Directory.Exists(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber))
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本目录已经存在,请选择新的版本号或者清除现有的版本号目录"));
                    return;
                }

                var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
                if (versionList != null && versionList.Count > 0)
                {
                    if (VersionNumber.CompareTo(versionList[versionList.Count - 1], versionNumber) > 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("当前版本号低于最新的版本号,无法打包,请重新选择版本号"));
                        return;
                    }
                }

                CreateVersion(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
                WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
            }
            GUILayout.EndHorizontal();
        }
        else if (m_BuildOperation == BuildOperation.Patch)
        {
            var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
            if (versionList != null && versionList.Count > 0)
            {
                List <string> versionStringList = new List <string>();
                foreach (var v in versionList)
                {
                    versionStringList.Add(v.ToString());
                }
                GUILayout.BeginHorizontal();
                EditorGUILayout.Space();

                GUILayout.BeginVertical();
                EditorGUILayout.LabelField("低版本");
                m_lowVersion = EditorGUILayout.Popup(m_lowVersion, versionStringList.ToArray());
                GUILayout.EndVertical();

                GUILayout.FlexibleSpace();

                GUILayout.BeginVertical();
                EditorGUILayout.LabelField("高版本");
                m_highVersion = EditorGUILayout.Popup(m_highVersion, versionStringList.ToArray());
                GUILayout.EndVertical();

                EditorGUILayout.Space();
                GUILayout.EndHorizontal();

                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(26),
                };
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("打补丁", options))
                {
                    if (VersionNumber.CompareTo(versionList[m_lowVersion], versionList[m_highVersion]) >= 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("低版本号不能大于等于高版本号"));
                        return;
                    }

                    var patchName = versionList[m_lowVersion] + "-" + versionList[m_highVersion];

                    var fileMd5LowVersion =
                        AssetBundleBuilder.GetFilesMD5(
                            m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_lowVersion], ".pkg");

                    var fileMd5HighVersion =
                        AssetBundleBuilder.GetFilesMD5(
                            m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_highVersion], ".pkg");

                    Dictionary <string, string> lowVersionAssets = new Dictionary <string, string>();
                    foreach (var v in fileMd5LowVersion)
                    {
                        var str = v.Key.Replace(Path.GetFullPath(m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_lowVersion] + "/"), "");
                        lowVersionAssets.Add(str, v.Value);
                    }

                    Dictionary <string, string> highVersionAssets = new Dictionary <string, string>();
                    foreach (var v in fileMd5HighVersion)
                    {
                        var str = v.Key.Replace(Path.GetFullPath(m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_highVersion] + "/"), "");
                        highVersionAssets.Add(str, v.Value);
                    }

                    Dictionary <string, string> resultAssets = new Dictionary <string, string>();
                    foreach (var v in highVersionAssets)
                    {
                        if (!lowVersionAssets.ContainsKey(v.Key))
                        {
                            resultAssets.Add(v.Key, v.Value);
                        }
                        else
                        {
                            if (lowVersionAssets[v.Key] != v.Value)
                            {
                                resultAssets.Add(v.Key, v.Value);
                            }
                        }
                    }

                    if (resultAssets.Count == 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("两个版本之间没有差异,无需生成补丁"));
                        return;
                    }

                    EditorFileUtility.ClearDirectory(m_ExportAssetBundleDir + platform + "/Patches/" + patchName);

                    foreach (var v in resultAssets)
                    {
                        var sourceFileName = m_ExportAssetBundleDir + platform + "/Version/" +
                                             versionList[m_highVersion] + "/" + v.Key;
                        var targetFileName = m_ExportAssetBundleDir + platform + "/Patches/" + patchName + "/" + v.Key;
                        if (!Directory.Exists(Path.GetDirectoryName(targetFileName)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                        }

                        File.Copy(sourceFileName, targetFileName);
                    }

                    var targetPath = m_ExportAssetBundleDir + platform + "/Patches/" + patchName + "/";
                    AssetBundleBuilder.PackPatches(targetPath, patchName, targetPath, ".pkg");
                    WindowsOSUtility.ExploreFile(targetPath);
                }
                GUILayout.EndHorizontal();
            }
        }

        if (m_OldBuildOperation != m_BuildOperation)
        {
            m_lowVersion  = 0;
            m_highVersion = 0;
        }

        m_OldBuildOperation = m_BuildOperation;
    }
    public static void CheckResourceReference()
    {
        var filePaths = EditorFileUtility.FilterDirectoryIgnoreExt(Application.dataPath + "/Resources",
                                                                   IgnoreFileExtensionList);

        var rootPath = Path.GetDirectoryName(Application.dataPath);

        rootPath = rootPath.Replace("\\", "/") + "/";

        if (filePaths != null)
        {
            Queue <string> assetQueue = new Queue <string>();
            foreach (var filePath in filePaths)
            {
                var path = filePath.Replace("\\", "/");
                path = path.Replace(rootPath, "");
                assetQueue.Enqueue(path);
            }

            while (assetQueue.Count > 0)
            {
                var path = assetQueue.Dequeue();
                if (GameAssets.ContainsKey(path))
                {
                    continue;
                }

                GetAssetDependences(assetQueue, path);
            }

            Dictionary <string, List <string> > sameAssets = new Dictionary <string, List <string> >();
            foreach (var gameAsset in GameAssets)
            {
                var md5 =
                    EditorFileUtility.GetMD5HashFromFile(Path.GetDirectoryName(Application.dataPath) + "/" +
                                                         gameAsset.Value.Path);
                if (!sameAssets.ContainsKey(md5))
                {
                    sameAssets.Add(md5, new List <string>());
                    sameAssets[md5].Add(gameAsset.Value.Path);
                }
                else
                {
                    sameAssets[md5].Add(gameAsset.Value.Path);
                }
            }

            StringBuilder sb = new StringBuilder();
            foreach (var asset in sameAssets)
            {
                if (asset.Value.Count > 1)
                {
                    sb.AppendLine("MD5: " + asset.Key);
                    foreach (var p in asset.Value)
                    {
                        sb.AppendLine("\t资源路径:" + p);
                        foreach (var gameAsset in GameAssets)
                        {
                            foreach (var cd in gameAsset.Value.ChildDependences)
                            {
                                if (cd == p)
                                {
                                    sb.AppendLine("\t\t引用到它的资源:" + gameAsset.Key);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            sb.AppendLine();

            sb.AppendLine("Resources目录下未被直接引用的资源(可能是代码中引用)");
            foreach (var gameAsset in GameAssets)
            {
                var hasRefer = false;
                foreach (var gameAsset1 in GameAssets)
                {
                    var isRefer = false;
                    foreach (var cd in gameAsset1.Value.ChildDependences)
                    {
                        if (cd == gameAsset.Value.Path)
                        {
                            isRefer = true;
                            break;
                        }
                    }
                    if (isRefer)
                    {
                        hasRefer = true;
                        break;
                    }
                }

                if (!hasRefer)
                {
                    sb.AppendLine("\t资源路径:" + gameAsset.Value.Path);
                }
            }

            File.WriteAllText(Path.GetDirectoryName(Application.dataPath) + "/CheckResourceReference.txt", sb.ToString());
            WindowsOSUtility.ExploreFile(Path.GetDirectoryName(Application.dataPath));
        }
    }