Exemplo n.º 1
0
    static void ProcUIScene(List <string> specialList, string uiscenePath)
    {
        Dictionary <string, Object> textureMap = new Dictionary <string, Object>();
        Dictionary <string, Object> soundMap   = new Dictionary <string, Object>();
        string TextureNomallPath = "";

        string[] textureArr = specialList.ToArray();
        foreach (string texturePath in textureArr)
        {
            if (!textureMap.ContainsKey(texturePath))
            {
                textureMap.Add(texturePath, AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)));
            }
        }

        string uisceneName = uiscenePath.Substring(uiscenePath.LastIndexOf('/') + 1);
        string sectionName = uisceneName.Replace(".unity", "");

        string   configPath = UIWndAssetbundlePath + "UIConfig.txt";
        UIConfig uiConfig   = new UIConfig();

        uiConfig.LoadConfig(configPath, configPath);
        uiConfig.ClearSection(sectionName);

        string[] sceneDepArr = AssetDatabase.GetDependencies(new string[1] {
            uiscenePath
        });
        foreach (string sceneDepPath in sceneDepArr)
        {
            if (IsImageFile(sceneDepPath))
            {
                if (!textureMap.ContainsKey(sceneDepPath))
                {
                    textureMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(Texture2D)));
                }
                if (textureMap[sceneDepPath].name != "Nomall")
                {
                    uiConfig.AddConfig(sectionName, UISubSection.UI_Texture, textureMap[sceneDepPath].name);
                }
            }
            else if (IsSoundFile(sceneDepPath))
            {
                if (!soundMap.ContainsKey(sceneDepPath))
                {
                    soundMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(AudioClip)));
                }

                uiConfig.AddConfig(sectionName, UISubSection.UI_Sound, soundMap[sceneDepPath].name);
            }
        }

        BuildPipeline.PushAssetDependencies();

        foreach (KeyValuePair <string, Object> texturekvp in textureMap)
        {
            string path = UITextureAssetbundlePath + texturekvp.Value.name + ".uit";
            if (texturekvp.Value.name == "Nomall")
            {
                TextureNomallPath = path;
            }

            BuildAssetBundle.Build(texturekvp.Value, null, path, true);
        }

        foreach (KeyValuePair <string, Object> soundkvp in soundMap)
        {
            string path = UISoundAssetbundlePath + soundkvp.Value.name + ".auc";
            BuildAssetBundle.Build(soundkvp.Value, null, path, true);
        }

        string storePath = UIWndAssetbundlePath + uisceneName;

        BuildPipeline.PushAssetDependencies();
        BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { uiscenePath }, storePath, EditorUserBuildSettings.activeBuildTarget);
        BuildPipeline.PopAssetDependencies();

        BuildPipeline.PopAssetDependencies();

        uiConfig.SaveConfig(configPath);

        if (!string.IsNullOrEmpty(TextureNomallPath))
        {
            File.Delete(TextureNomallPath);
        }
    }
Exemplo n.º 2
0
    static void ProcUIScene(List <string> specialList, List <string> uisceneList)
    {
        UIConfig uiConfig = new UIConfig();
        Dictionary <string, Object> textureMap = new Dictionary <string, Object>();
        Dictionary <string, Object> soundMap   = new Dictionary <string, Object>();
        string TextureNomallPath = "";

#if PACKAGE_BASIC
        //添加小包过滤操作
        Dictionary <string, string> deleteTextureMap = new Dictionary <string, string>();
        Dictionary <string, string> deleteSoundMap   = new Dictionary <string, string>();
        List <string> notDelTextureList = new List <string>();
        List <string> notDelSoundList   = new List <string>();
#endif

        string[] textureArr = specialList.ToArray();
        foreach (string texturePath in textureArr)
        {
            if (!textureMap.ContainsKey(texturePath))
            {
                textureMap.Add(texturePath, AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)));
            }
        }

        foreach (string uiscenePath in uisceneList)
        {
            string sectionName = uiscenePath.Substring(uiscenePath.LastIndexOf('/') + 1);
            sectionName = sectionName.Replace(".unity", "");

            string[] sceneDepArr = AssetDatabase.GetDependencies(new string[1] {
                uiscenePath
            });
            foreach (string sceneDepPath in sceneDepArr)
            {
                if (IsImageFile(sceneDepPath))
                {
                    if (!textureMap.ContainsKey(sceneDepPath))
                    {
                        textureMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(Texture2D)));
                    }
#if PACKAGE_BASIC
                    //添加小包过滤操作
                    if (uiscenePath.Contains(UIWndSrcDir) && !deleteTextureMap.ContainsKey(sceneDepPath))
                    {
                        if (specialList.Contains(sceneDepPath))
                        {                        //Check it again.
                            Debug.LogError("Special texture dictionary has same texture,TexturePath=" + sceneDepPath + ".UIScenePath=" + uiscenePath);
                        }
                        else
                        {
                            deleteTextureMap.Add(sceneDepPath, null);
                        }
                    }
                    if (uiscenePath.Contains(UIWndBasicSrcDir) && !notDelTextureList.Contains(sceneDepPath))
                    {
                        notDelTextureList.Add(sceneDepPath);
                    }
#endif
                    if (textureMap[sceneDepPath].name != "Nomall")
                    {
                        uiConfig.AddConfig(sectionName, UISubSection.UI_Texture, textureMap[sceneDepPath].name);
                    }
                }
                else if (IsSoundFile(sceneDepPath))
                {
                    if (!soundMap.ContainsKey(sceneDepPath))
                    {
                        soundMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(AudioClip)));
                    }
#if PACKAGE_BASIC
                    //添加小包过滤操作
                    if (uiscenePath.Contains(UIWndSrcDir) && !deleteSoundMap.ContainsKey(sceneDepPath))
                    {
                        deleteSoundMap.Add(sceneDepPath, null);
                    }
                    if (uiscenePath.Contains(UIWndBasicSrcDir) && !notDelSoundList.Contains(sceneDepPath))
                    {
                        notDelSoundList.Add(sceneDepPath);
                    }
#endif
                    uiConfig.AddConfig(sectionName, UISubSection.UI_Sound, soundMap[sceneDepPath].name);
                }
            }
        }

#if PACKAGE_BASIC
        //过滤小包中用到的资源
        foreach (string notPath in notDelTextureList)
        {
            if (deleteTextureMap.ContainsKey(notPath))
            {
                deleteTextureMap.Remove(notPath);
            }
        }
        foreach (string notPath in notDelSoundList)
        {
            if (deleteSoundMap.ContainsKey(notPath))
            {
                deleteSoundMap.Remove(notPath);
            }
        }
#endif

        BuildPipeline.PushAssetDependencies();

        foreach (KeyValuePair <string, Object> texturekvp in textureMap)
        {
            string path = UITextureAssetbundlePath + texturekvp.Value.name + ".uit";

            if (texturekvp.Value.name == "Nomall")
            {
                TextureNomallPath = path;
            }
#if PACKAGE_BASIC
            //添加小包过滤操作
            if (deleteTextureMap.ContainsKey(texturekvp.Key))
            {
                deleteTextureMap[texturekvp.Key] = path;
            }
#endif
            BuildAssetBundle.Build(texturekvp.Value, null, path, true);
        }

        foreach (KeyValuePair <string, Object> soundkvp in soundMap)
        {
            string path = UISoundAssetbundlePath + soundkvp.Value.name + ".auc";
#if PACKAGE_BASIC
            //添加小包过滤操作
            if (deleteSoundMap.ContainsKey(soundkvp.Key))
            {
                deleteSoundMap[soundkvp.Key] = path;
            }
#endif
            BuildAssetBundle.Build(soundkvp.Value, null, path, true);
        }

        string storePath = UIWndAssetbundlePath + "UI.unity";
        BuildPipeline.BuildStreamedSceneAssetBundle(uisceneList.ToArray(), storePath, EditorUserBuildSettings.activeBuildTarget);
        BuildPipeline.PopAssetDependencies();

        uiConfig.SaveConfig(UIWndAssetbundlePath + "UIConfig.txt");

        if (!string.IsNullOrEmpty(TextureNomallPath))
        {
            File.Delete(TextureNomallPath);
        }
#if PACKAGE_BASIC
        //添加小包过滤操作
        foreach (string path in deleteTextureMap.Values)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Build basic package error, can not delete unuse texture");
            }
            else
            {
                File.Delete(path);
            }
        }
        foreach (string path in deleteSoundMap.Values)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Build basic package error, can not delete unuse sound");
            }
            else
            {
                File.Delete(path);
            }
        }
#endif
    }