Пример #1
0
    public static void MarkAssetLabels()
    {
        DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/" + Paths.GameResRoot);

        foreach (DirectoryInfo childDir in dir.GetDirectories())
        {
            string         buildConfigPath = string.Format("Assets/" + Paths.GameResRoot + "/{0}/BuildConfigs.asset", childDir.Name);
            ABBuildConfigs configs         = AssetDatabase.LoadAssetAtPath <ABBuildConfigs>(buildConfigPath);

            ABMarkConfig[] paths = configs.OneFloderOneBundle;
            foreach (var p in paths)
            {
                AssetImporter ai = AssetImporter.GetAtPath(p.AssetPath);
                ai.SetAssetBundleNameAndVariant(p.GamePath, Def.AssetBundleSuffix);
            }

            paths = configs.SubFloderOneBundle;
            foreach (var p in paths)
            {
                DirectoryInfo assetDir = new DirectoryInfo(p.AssetPath);
                foreach (DirectoryInfo subDir in assetDir.GetDirectories())
                {
                    AssetImporter ai = AssetImporter.GetAtPath(p.AssetPath + "/" + subDir.Name);
                    ai.SetAssetBundleNameAndVariant(p.GamePath + "/" + subDir.Name, Def.AssetBundleSuffix);
                }
            }

            paths = configs.OneAssetOneBundle;
            foreach (var p in paths)
            {
                AssetImporter ai = AssetImporter.GetAtPath(p.AssetPath);
                ai.SetAssetBundleNameAndVariant(p.GamePath, Def.AssetBundleSuffix);
            }
        }
    }
Пример #2
0
    public static void RefreshResConfig()
    {
        DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/" + Paths.GameResRoot);

        foreach (DirectoryInfo childDir in dir.GetDirectories())
        {
            List <SingleResCfg> configList = new List <SingleResCfg>();
            string         buildConfigPath = string.Format("Assets/" + Paths.GameResRoot + "/{0}/BuildConfigs.asset", childDir.Name);
            ABBuildConfigs configs         = AssetDatabase.LoadAssetAtPath <ABBuildConfigs>(buildConfigPath);
            ABMarkConfig[] paths           = configs.OneFloderOneBundle;
            foreach (var p in paths)
            {
                string        abName       = (p.GamePath + "." + Def.AssetBundleSuffix).ToLower();
                DirectoryInfo childRootDir = new DirectoryInfo(p.AssetPath);
                FileInfo[]    files        = childRootDir.GetFiles("*", SearchOption.AllDirectories);
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i];
                    if (file.Extension.Equals(".meta") || file.Extension.Equals(".DS_Store"))
                    {
                        continue;
                    }
                    configList.Add(new SingleResCfg(file.Name.Replace(file.Extension, ""), file.Extension, abName, "Assets/" + file.FullName.Replace("\\", "/").Replace(Application.dataPath + "/", "")));
                }
            }

            paths = configs.SubFloderOneBundle;
            foreach (var p in paths)
            {
                DirectoryInfo assetDir = new DirectoryInfo(p.AssetPath);
                foreach (DirectoryInfo subDir in assetDir.GetDirectories())
                {
                    string     abName = (p.GamePath + "/" + subDir.Name + "." + Def.AssetBundleSuffix).ToLower();
                    FileInfo[] files  = subDir.GetFiles("*", SearchOption.AllDirectories);
                    for (int i = 0; i < files.Length; i++)
                    {
                        FileInfo file = files[i];
                        if (file.Extension.Equals(".meta") || file.Extension.Equals(".DS_Store"))
                        {
                            continue;
                        }
                        configList.Add(new SingleResCfg(file.Name.Replace(file.Extension, ""), file.Extension, abName, "Assets/" + file.FullName.Replace("\\", "/").Replace(Application.dataPath + "/", "")));
                    }
                }
            }

            paths = configs.OneAssetOneBundle;
            foreach (var p in paths)
            {
                string abName = (p.GamePath + "." + Def.AssetBundleSuffix).ToLower();
                if (Directory.Exists(Application.dataPath + "/" + p.GamePath))
                {
                    DirectoryInfo assetDir = new DirectoryInfo(p.AssetPath);
                    FileInfo[]    files    = assetDir.GetFiles("*", SearchOption.AllDirectories);
                    for (int i = 0; i < files.Length; i++)
                    {
                        FileInfo file = files[i];
                        if (file.Extension.Equals(".meta") || file.Extension.Equals(".DS_Store"))
                        {
                            continue;
                        }
                        configList.Add(new SingleResCfg(file.Name.Replace(file.Extension, ""), file.Extension, abName, "Assets/" + file.FullName.Replace("\\", "/").Replace(Application.dataPath + "/", "")));
                    }
                }
                else
                {
                    FileInfo file = new FileInfo(p.AssetPath);
                    configList.Add(new SingleResCfg(file.Name.Replace(file.Extension, ""), file.Extension, abName, "Assets/" + file.FullName.Replace("\\", "/").Replace(Application.dataPath + "/", "")));
                }
            }

            string          path  = childDir.Name + "/ResConfig/ResConfig";
            ResourcesConfig asset = Resources.Load <ResourcesConfig>(path);
            if (asset == null)
            {
                asset = ScriptableObject.CreateInstance <ResourcesConfig>();
                path  = "Assets/" + Paths.GameResRoot + "/" + childDir.Name + "/ResConfig/ResConfig.asset";
                AssetDatabase.CreateAsset(asset, path);
            }
            asset.configs = configList.ToArray();
            EditorUtility.SetDirty(asset);
        }
    }