/// <summary>
    /// 预计算预制体配置,最后还要进行合并
    /// </summary>
    private static void PreGeneratePrefabConfig()
    {
        //先刷新一遍资源数据库,把所有的资源都丢进来
        SaveAndRefershAssets();


        DeleteFileHelper(AssetBundleManager.GetPrefabConfigPath());
        DeleteFileHelper(AssetBundleManager.GetDependenicesResConfigPath());

        AssetBundleManager.ClearPrefabConfig();

        AssetBundleImporter.BeginPrefabAssetImport();
        AssetBundleImporter.BeginGenerateUnionRes();
        string[] assetss = AssetDatabase.FindAssets("t:Object", new string[] { AssetBundleImporter.PrefabPatch.Remove(AssetBundleImporter.PrefabPatch.Length - 1, 1),
                                                                               AssetBundleImporter.ArtistCommonAssetsPatch.Remove(AssetBundleImporter.ArtistCommonAssetsPatch.Length - 1, 1) });

        foreach (string patch1 in assetss)
        {
            string patch = AssetDatabase.GUIDToAssetPath(patch1);
            AssetBundleImporter.ImportSinglePrefab(patch, false);
        }

        AssetBundleImporter.EndGenerateUnionRes();
        AssetBundleImporter.EndPrefabAssetImport();
        SaveAndRefershAssets();
    }
Beispiel #2
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        bool bMovedSound  = false;
        bool bImportSound = false;

        //处理的是否是UI文件
        bool bImportUI = false;


        OnPreProcessScheme();

        for (int i = 0; i < importedAssets.Length; i++)
        {
            //看看是不是场景文件
            string s = importedAssets[i];
            AssetBundleManagerEditor.CheckAssetName(s);
            if (isSceneAssets(s))
            {
                MakeSceneAssetBundleInfo(s);
            }
            else if (isShaderAssets(s))
            {
                MakeShaderAssetBundle(s);
            }
            else if (isMeshAssets(s))
            {
                MakeMeshAssetBundle(s);
            }
            else if (isAudioAssets(s))
            {
                bImportSound = true;
                MakeSoundAssetBundleData(s);
            }
            else if (IsFontAsset(s))
            {
                MakeFontBundleData(AssetImporter.GetAtPath(s));
            }
            else if (IsFBXAsset(s))
            {
                MakeFBXAssetBundle(AssetImporter.GetAtPath(s) as ModelImporter);
            }
            else if (IsMaterialAsset(s))
            {
                MakeMaterialAssetBundle(s);
            }
            else if (IsAniClipAsset(s))
            {
                MakeAnimatorClipAssetBundleData(s);
            }
            else if (IsControllerAsset(s))
            {
                MakeAnimatorControllerAssetBundleData(s);
            }
            else if (IsTextureAsset(s))
            {
                MakeTextureAssetBundle(s);
            }
            else if (isSchemeAssets(s))
            {
                MakeSchemeAssetBundleInfo(s);
            }

            string path = importedAssets[i];
            //载入的话弄到表里
            if (path.Contains(UIDynamicAssetPatch))
            {
                if (!IsTextureAsset(path))
                {
                    continue;
                }

                bImportUI = true;
                UFileData data = new UFileData();

                data.configData = MakeTextureAssetBundleFromReference(path, string.Empty);
                if (null != data.configData)
                {
                    PostprocessUITextureToCSV.nEditorInstance.InsetConfig(data);
                }
                else
                {
                    Debug.LogError("取得UI资源失败:" + path);
                }
            }
        }

        //资源移动了
        List <string> movedGUID = new List <string>();

        for (int i = 0; i < movedAssets.Length; i++)
        {
            string str = movedAssets[i];
            AssetBundleManagerEditor.CheckAssetName(movedAssets[i]);
            //先清掉ab
            ClearAssetBundleData(AssetImporter.GetAtPath(str));

            //再根据资源类型来重新生成ab
            //是音效的
            if (isAudioAssets(str))
            {
                MakeSoundAssetBundleData(str);
                movedGUID.Add(AssetBundleManagerEditor.GetAssetGUIDFromMeta(str));
                bMovedSound = true;
            }
            //是贴图
            else if (IsTextureAsset(str))
            {
                MakeTextureAssetBundle(str);
            }
            //是场景
            else if (isSceneAssets(str))
            {
                MakeSceneAssetBundleInfo(str);
            }
            else if (IsFontAsset(str))
            {
                MakeFontBundleData(AssetImporter.GetAtPath(str));
            }
            else if (IsFBXAsset(str))
            {
                CheckFBXInImportTime(str);
                MakeFBXAssetBundle(AssetImporter.GetAtPath(str) as ModelImporter);
            }
            else if (IsMaterialAsset(str))
            {
                MakeMaterialAssetBundle(str);
            }
            else if (IsAniClipAsset(str))
            {
                MakeAnimatorClipAssetBundleData(str);
            }
            else if (IsControllerAsset(str))
            {
                MakeAnimatorControllerAssetBundleData(str);
            }
            else if (isSchemeAssets(str))
            {
                MakeSchemeAssetBundleInfo(str);
            }
            else if (isShaderAssets(str))
            {
                MakeShaderAssetBundle(str);
            }
            else if (isMeshAssets(str))
            {
                MakeMeshAssetBundle(str);
            }
            string path = movedAssets[i];
            if (path.Contains(UIDynamicAssetPatch))
            {
                bImportUI = true;
                AssetImporter assetImporter = AssetImporter.GetAtPath(path);

                PostprocessUITextureToCSV.nEditorInstance.RemoveConfig(PostprocessUITextureToCSV.GetGUID(assetImporter.assetPath));
            }
        }

        if (SoundSystem.SoundSystemEditorWindow.EditorInstance)
        {
            if (bMovedSound || bImportSound)
            {
                if (bMovedSound)
                {
                    SoundSystem.SoundSystemEditorWindow.RefrshAudioClipSource(movedGUID);
                }
                else
                {
                    SoundSystem.SoundSystemEditorWindow.RefrshAudioClipSource();
                }
            }
        }

        //UI的处理完保存配置
        if (bImportUI)
        {
            PostprocessUITextureToCSV.nEditorInstance.ExportConfig();
        }

        OnPostProcessScheme();

        if (!AssetBundleManagerEditor.isBuildingPackage && !AssetBundleManagerEditor.isCleaningAssets)
        {
            AssetBundleManager.LoadPrefabConfig();

            for (int i = 0; i < movedAssets.Length; i++)
            {
                string str = movedAssets[i];
                if (IsPrefabAssets(movedFromAssetPaths[i]))
                {
                    ClearSinglePrefab(str);
                }

                if (IsPrefabAssets(str))
                {
                    ImportSinglePrefab(str, true);
                }
            }


            for (int i = 0; i < importedAssets.Length; i++)
            {
                ImportSinglePrefab(importedAssets[i], true);
            }

            SchemeExport.Export_PrefabScheme();
            AssetBundleManager.ClearPrefabConfig();
        }


        //进入播放模式的时候会调用一次这个postallasets,所以要加载一次配置
        if (Application.isPlaying)
        {
            AssetBundleManager.LoadPrefabConfig();
        }

        if (movedAssets.Length > 0)
        {
            AssetDatabase.Refresh();
        }
        //移除无用的ab名
        AssetDatabase.RemoveUnusedAssetBundleNames();
    }