Beispiel #1
0
        void CheckChildren()
        {
            string[] subFolders    = AssetDatabase.GetSubFolders(assetsPath);
            var      checkerConfig = new AddressableCheckerConfig();

            foreach (string f in subFolders)
            {
                var packPath = AssetBundleUtility.AssetsPathToPackagePath(f);

                if (config.Type == AddressableDispatcherFilterType.ChildrenFilesOnly &&
                    !File.Exists(f))
                {
                    //continue;
                }
                else if (config.Type == AddressableDispatcherFilterType.ChildrenFoldersOnly &&
                         File.Exists(f))
                {
                    //continue;
                }

                checkerConfig.CheckerFilters = config.CheckerFilters;
                checkerConfig.PackagePath    = packPath;
                AddressableChecker.Run(checkerConfig);
            }
        }
Beispiel #2
0
        void DrawAssetDispatcherConfig()
        {
            GUILayoutUtils.BeginContents(false);

            GUILayoutUtils.DrawProperty("Path:", AssetBundleUtility.AssetsPathToPackagePath(targetAssetPath), 300f, 80f);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("FilterType:", GUILayout.MaxWidth(80f));
            var selectType = (AssetBundleDispatcherFilterType)EditorGUILayout.EnumPopup(filterType);

            if (selectType != filterType)
            {
                filterType = selectType;
                MarkChanged();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            var filtersCount = dispatcherConfig.CheckerFilters.Count;

            if (GUILayoutUtils.DrawSubHeader(0, "CheckerFilters:", inspectorSate, "CheckerFilters", filtersCount.ToString()))
            {
                DrawFilterTypesList(dispatcherConfig.CheckerFilters);
            }

            Color color = GUI.color;

            if (configChanged)
            {
                GUI.color = color * new Color(1, 1, 0.5f);
            }
            EditorGUILayout.Separator();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Apply"))
            {
                Apply();
            }
            GUI.color = new Color(1, 0.5f, 0.5f);
            if (GUILayout.Button("Remove"))
            {
                ConfirmRemove();
            }
            GUI.color = color;
            GUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            GUILayoutUtils.EndContents(false);
        }
Beispiel #3
0
        void Initialize()
        {
            configChanged   = false;
            filterType      = AssetBundleDispatcherFilterType.Root;
            targetAssetPath = AssetDatabase.GetAssetPath(target);
            if (!AssetBundleUtility.IsPackagePath(targetAssetPath))
            {
                return;
            }

            packagePath       = AssetBundleUtility.AssetsPathToPackagePath(targetAssetPath);
            databaseAssetPath = AssetBundleInspectorUtils.AssetPathToDatabasePath(targetAssetPath);
            dispatcherConfig  = AssetDatabase.LoadAssetAtPath <AssetBundleDispatcherConfig>(databaseAssetPath);
            if (dispatcherConfig != null)
            {
                dispatcherConfig.Load();
                filterType = dispatcherConfig.Type;
            }
        }
        public static void BuildPathMapping(AssetBundleManifest manifest)
        {
            mappingList.Clear();
            string outputFilePath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.AssetsPathMapFileName);

            string[] allAssetbundles = manifest.GetAllAssetBundles();
            string[] allVariants     = manifest.GetAllAssetBundlesWithVariant();

            List <string> assetbundlesWithoutVariant = null;
            List <string> variantWithoutDeplicate    = null;

            ProsessVariant(allAssetbundles, allVariants, out assetbundlesWithoutVariant, out variantWithoutDeplicate);

            // 处理所有不带variants的assetbundle
            foreach (string assetbundle in assetbundlesWithoutVariant)
            {
                // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如:
                // Assets/AssetsPackage/UI/Prefabs/View/UILoading.prefab
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle);
                foreach (string assetPath in assetPaths)
                {
                    string packagePath = AssetBundleUtility.AssetsPathToPackagePath(assetPath);
                    if (!addressList.Contains(packagePath))
                    {
                        addressList.Add(packagePath);
                    }
                    string mappingItem = string.Format("{0}{1}{2}", assetbundle, PATTREN, packagePath);
                    mappingList.Add(mappingItem);
                }
            }
            // 处理带variants的assetbundle(已经去重)
            // string variant = "[" + AssetBundleConfig.VariantMapParttren + "]";
            foreach (string assetbundle in variantWithoutDeplicate)
            {
                // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如:
                // Assets/AssetsPackage/UI/Prefabs/Language/[Chinese]/TestVariant.prefab
                // Assets/AssetsPackage/UI/Prefabs/Language/[English]/TestVariant.prefab
                // 由于已经去重,以上条目有且仅有一条出现
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle);
                if (assetPaths == null || assetPaths.Length == 0)
                {
                    UnityEngine.Debug.LogError("Empty assetbundle with variant : " + assetbundle);
                    continue;
                }
                // 自本节点向上找到Assetbundle所在
                AssetBundleImporter assetbundleImporter = AssetBundleImporter.GetAtPath(assetPaths[0]);
                while (assetbundleImporter != null && string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    assetbundleImporter = assetbundleImporter.GetParent();
                }
                if (assetbundleImporter == null || string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    UnityEngine.Debug.LogError("Can not find assetbundle with variant : " + assetbundle);
                    continue;
                }
                string assetbundlePath = assetbundleImporter.assetPath;
                if (assetbundlePath.EndsWith("/"))
                {
                    assetbundlePath = assetbundlePath.Substring(0, assetbundlePath.Length - 1);
                }
                // 将拿掉[Variant]目录名如:
                // Assets/AssetsPackage/UI/Prefabs/Language/TestVariant.prefab
                // 用此种方式可以统一路径,使加载Assetbundle时的路径与具体激活的variant无关
                string nowRoot = GameUtility.FormatToUnityPath(System.IO.Path.GetDirectoryName(assetbundlePath));
                foreach (string assetPath in assetPaths)
                {
                    string nowAsset     = assetPath.Replace(assetbundlePath, "");
                    string nowAssetPath = nowRoot + nowAsset;
                    string packagePath  = AssetBundleUtility.AssetsPathToPackagePath(nowAssetPath);
                    if (!addressList.Contains(packagePath))
                    {
                        addressList.Add(packagePath);
                    }
                    string mappingItem = string.Format("{0}{1}{2}", RemoveVariantSuffix(assetbundle), PATTREN, packagePath);
                    mappingList.Add(mappingItem);
                }
            }
            mappingList.Sort();
            addressList.Sort();
            if (!GameUtility.SafeWriteAllLines(outputFilePath, mappingList.ToArray()))
            {
                Debug.LogError("BuildPathMapping failed!!! try rebuild it again!");
            }
            else
            {
                AssetDatabase.Refresh();
                AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFilePath);
                Debug.Log("BuildPathMapping success...");
            }
            AssetDatabase.Refresh();
        }