Пример #1
0
        public void Process(Component @object)
        {
            var label = (UILabel)@object;

            // 图片字体! 打包字
            if (label.bitmapFont != null)
            {
                string uiFontPath = KDepBuild_NGUI.BuildUIFont(label.bitmapFont);
                //CResourceDependencies.Create(label, CResourceDependencyType.BITMAP_FONT, uiFontPath);
                KAssetDep.Create <KBitmapFontDep>(label, uiFontPath);

                label.bitmapFont = null;
            }
            else if (label.trueTypeFont != null)
            {
                string fontPath = KDependencyBuild.BuildFont(label.trueTypeFont);

                //CResourceDependencies.Create(label, CResourceDependencyType.FONT, fontPath);
                KAssetDep.Create <KUILabelDep>(label, fontPath);
                label.trueTypeFont = null; // 挖空依赖的数据
            }
            else
            {
                Logger.LogWarning("找不到Label的字体: {0}, 场景: {1}", label.name, EditorApplication.currentScene);
            }
        }
Пример #2
0
    public void Process(Component @object)
    {
        var image = @object as Image;

        if (image.sprite != null)
        {
            string spritePath = KDepBuild_UGUI.BuildSprite(image.sprite);
            KAssetDep.Create <KImageDep>(image, spritePath);
            image.sprite = null;
        }
    }
Пример #3
0
    public void Process(Component @object)
    {
        var text = @object as Text;

        if (text.font != null)
        {
            var fontPath = KDependencyBuild.BuildFont(text.font);
            KAssetDep.Create <KTextDep>(text, fontPath);
            text.font = null; // 挖空依赖的数据
        }
        else
        {
            Logger.LogWarning("UISprite null Atlas: {0}", text.name);
        };
    }
Пример #4
0
    public void Process(Component @object)
    {
        var renderer = @object as SpriteRenderer;

        if (renderer.sprite != null)
        {
            var spritePath = KDepBuild_UGUI.BuildSprite(renderer.sprite);
            KAssetDep.Create <KSpriteRendererDep>(renderer, spritePath);
            renderer.sprite = null; // 挖空依赖的数据
        }
        else
        {
            Logger.LogWarning("SpriteRenderer null sprite: {0}", renderer.name);
        }
    }
Пример #5
0
    public void Process(Component @object)
    {
        var audioSource = @object as AudioSource;

        if (audioSource.clip != null)
        {
            string audioPath = BuildAudioClip(audioSource.clip);
            KAssetDep.Create <KAudioSourceDep>(audioSource, audioPath);
            audioSource.clip = null;
        }
        else
        {
            Logger.LogWarning("找不到AudioClip在AudioSource... {0}", audioSource.name);
        }
    }
Пример #6
0
        public void Process(Component @object)
        {
            var sprite = (UISprite)@object;

            if (sprite.atlas != null)
            {
                string atlasPath = KDepBuild_NGUI.BuildUIAtlas(sprite.atlas);
                //CResourceDependencies.Create(sprite, CResourceDependencyType.UI_SPRITE, atlasPath);
                KAssetDep.Create <KUISpriteDep>(sprite, atlasPath);
                sprite.atlas = null;
            }
            else
            {
                Logger.LogWarning("UISprite null Atlas: {0}, Scene: {1}", sprite.name, EditorApplication.currentScene);
            }
        }
Пример #7
0
    public void Process(Component @object)
    {
        var particleCom = (ParticleSystem)@object;
        var particle    = particleCom;

        if (particle.renderer.sharedMaterial != null)
        {
            string matPath = KDepBuild_Material.BuildDepMaterial(particle.renderer.sharedMaterial);
            //CResourceDependencies.Create(particle, CResourceDependencyType.PARTICLE_SYSTEM, matPath);
            KAssetDep.Create <KParticleSystemDep>(particle, matPath);

            particle.renderer.sharedMaterial = null;
        }
        else
        {
            Logger.LogWarning("没有Material的粒子: {0}", particle.gameObject.name);
        }
    }
Пример #8
0
        public void Process(Component @object)
        {
            var tex = (UITexture)@object;

            if (tex.mainTexture != null)
            {
                string texPath = KDependencyBuild.BuildDepTexture(tex.mainTexture, 1f);
                //CResourceDependencies.Create(tex, CResourceDependencyType.UI_TEXTURE, texPath);
                KAssetDep.Create <KUITextureDep>(tex, texPath);
                tex.mainTexture = null; // 挖空依赖的数据

                // UITexture的有bug,强行缩放有问题的!
                tex.border *= KResourceModule.TextureScale;
            }
            else
            {
                //Logger.Log("缺少Texture的UiTexture: {0}", tex.name);
            }
        }
Пример #9
0
    static CDepCollectInfo ProcessSkeletonAnimation(SkeletonAnimation sa)
    {
        if (sa.skeletonDataAsset == null)
        {
            Log.Error("SkeletonAnimation {0}缺少DataAsset,无法打包", sa.gameObject.name);
            return(null);
        }
        else
        {
            if (sa.skeletonDataAsset.spriteCollection == null)
            {
                Log.Error("SkeletonDataAsset {0}缺少SpriteCollection,无法打包", sa.skeletonDataAsset.name);
                return(null);
            }
            if (sa.skeletonDataAsset.skeletonJSON == null)
            {
                Log.Error("SkeletonDataAsset {0}缺少Json,无法打包", sa.skeletonDataAsset.name);
                return(null);
            }

            var spineDataResult = GetBuildSpineData(sa.skeletonDataAsset);  // 依赖SpineData
            //CResourceDependencies.Create(sa, CResourceDependencyType.SPINE_ANIMATION, spineDataPath);
            spineDataResult.AssetDep = KAssetDep.Create <CSpineAnimationDep>(sa, spineDataResult.Path);

            sa.skeletonDataAsset = null; // 挖空依赖的数据

            // 如果存在MeshFilter和MeshRenderer也挖空... 理论上skeletonDataAsset变空会改变,但这里可能存在对象为disable导致无法自动挖空
            var mesh = sa.gameObject.GetComponent <MeshFilter>();
            if (mesh != null)
            {
                mesh.sharedMesh = null;
            }
            var meshRend = sa.gameObject.GetComponent <MeshRenderer>();
            if (meshRend != null)
            {
                meshRend.sharedMaterial = null; // 挖空
            }
            return(spineDataResult);
        }
    }
    static void ProcessBaseSprite(tk2dSprite baseSprite)
    {
        if (baseSprite.Collection == null)
        {
            Log.Error("Null sprite Collection: {0}", baseSprite.gameObject.name);
            return;
        }
        string spriteCollectionPath = BuildSpriteCollection(baseSprite.Collection);

        if (!string.IsNullOrEmpty(spriteCollectionPath))
        {
            //CResourceDependencies.Create(sprite, CResourceDependencyType.TK2D_SPRITE, spriteCollectionPath);
            KAssetDep.Create <CTk2dSpriteDep>(baseSprite, spriteCollectionPath);
        }

        baseSprite.Collection = null;

        foreach (Renderer rend in baseSprite.gameObject.GetComponents <Renderer>())  // 挖空材质
        {
            rend.sharedMaterials = new Material[0];
        }
    }
Пример #11
0
        /// <summary>
        /// NGUI 的字体集
        /// </summary>
        public static string BuildUIFont(UIFont uiFont)
        {
            CDepCollectInfo result;

            if (KDepCollectInfoCaching.HasCache(uiFont))
            {
                result = KDepCollectInfoCaching.GetCache(uiFont);
                return(result.Path);
            }
            if (uiFont.atlas == null)
            {
                Logger.LogError("[BuildUIFont]uiFont Null Atlas: {0}, Scene: {1}", uiFont.name, EditorApplication.currentScene);
                return("");
            }
            string uiFontPrefabPath = AssetDatabase.GetAssetPath(uiFont.gameObject);
            bool   needBuild        = KAssetVersionControl.TryCheckNeedBuildWithMeta(uiFontPrefabPath);

            if (needBuild)
            {
                KAssetVersionControl.TryMarkBuildVersion(uiFontPrefabPath);
            }

            var copyUIFontObj = GameObject.Instantiate(uiFont.gameObject) as GameObject;
            var copyUIFont    = copyUIFontObj.GetComponent <UIFont>();

            var uiAtlas = BuildUIAtlas(copyUIFont.atlas); // 依赖的UI Atlas

            copyUIFont.atlas    = null;                   // 清空依赖
            copyUIFont.material = null;
            //CResourceDependencies.Create(copyUIFont, CResourceDependencyType.NGUI_UIFONT, uiAtlas);
            KAssetDep.Create <KUIFontDep>(copyUIFont, uiAtlas);

            result = KDependencyBuild.DoBuildAssetBundle("UIFont/UIFont_" + uiFont.name, copyUIFontObj, needBuild);

            GameObject.DestroyImmediate(copyUIFontObj);
            KDepCollectInfoCaching.SetCache(uiFont, result);
            return(result.Path);
        }
    // Prefab build, 单次build缓存
    public static string BuildSpriteCollection(tk2dSpriteCollectionData data)
    {
        if (data == null)
        {
            Log.Error("[BuildSpriteColleccion]Null SpriteCol Data!!!");
            return("");
        }
        GameObject spriteColPrefab = PrefabUtility.FindPrefabRoot(data.gameObject) as GameObject;

        Log.Assert(spriteColPrefab);

        string path = AssetDatabase.GetAssetPath(spriteColPrefab);  // prefab只用来获取路径,不打包不挖空

        if (string.IsNullOrEmpty(path))
        {
            Log.Info("Null Sprite Collection {0}", path);
            return("");   // !!! SpriteCollection可能动态生成的,不打包它
        }
        bool needBuild = BuildTools.CheckNeedBuild(path);

        if (needBuild)
        {
            BuildTools.MarkBuildVersion(path);
        }

        path = __GetPrefabBuildPath(path);

        GameObject copySpriteColObj            = GameObject.Instantiate(spriteColPrefab) as GameObject;
        tk2dSpriteCollectionData spriteColData = copySpriteColObj.GetComponent <tk2dSpriteCollectionData>();

        foreach (Material mat in spriteColData.materials) // many materials
        {
            string matPath = BuildDepMaterial(mat, GameDef.PictureScale);
            if (!string.IsNullOrEmpty(matPath))  // 材质可能动态创建的,无需打包
            //CResourceDependencies.Create(spriteColData, CResourceDependencyType.SPRITE_COLLECTION, matPath);
            {
                KAssetDep.Create <CTk2dSpriteCollectionDep>(spriteColData, matPath);
            }
        }

        spriteColData.materials = new Material[0]; // 挖空spriteCollections
        spriteColData.textures  = new Texture[0];
        foreach (var def in spriteColData.spriteDefinitions)
        {
            def.material = null;
            // 进行缩放!
            //if (def.positions != null)
            //{
            //    // position!  size!
            //    for (var ip = 0; ip < def.positions.Length; ip++)
            //    {
            //        def.positions[ip] = def.positions[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.untrimmedBoundsData.Length; ip++)
            //    {
            //        def.untrimmedBoundsData[ip] = def.untrimmedBoundsData[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.boundsData.Length; ip++)
            //    {
            //        def.boundsData[ip] = def.boundsData[ip] / GameDef.PictureScale;
            //    }
            //}
        }

        var result = DoBuildAssetBundle(DepBuildToFolder + "/Col_" + path, copySpriteColObj, needBuild);  // Build主对象, 被挖空Material了的

        GameObject.DestroyImmediate(copySpriteColObj);

        return(result.Path);
    }
Пример #13
0
        /// <summary>
        /// 图集 打包结果缓存起来加速
        /// </summary>
        /// <param name="atlas"></param>
        /// <returns></returns>
        public static string BuildUIAtlas(UIAtlas atlas)
        {
            CDepCollectInfo result;

            // 使用缓存,确保Atlas不会重复处理,浪费性能
            if (KDepCollectInfoCaching.HasCache(atlas))
            {
                result = KDepCollectInfoCaching.GetCache(atlas);
                return(result.Path);
            }
            var        scale       = 1f; // TODO: scale read
            GameObject atlasPrefab = PrefabUtility.FindPrefabRoot(atlas.gameObject) as GameObject;

            Logger.Assert(atlasPrefab);
            string path      = AssetDatabase.GetAssetPath(atlasPrefab); // prefab只用来获取路径,不打包不挖空
            bool   needBuild = KAssetVersionControl.TryCheckNeedBuildWithMeta(path);

            if (needBuild)
            {
                KAssetVersionControl.TryMarkBuildVersion(path);
            }

            Logger.Assert(path);

            path = KDependencyBuild.__GetPrefabBuildPath(path);

            GameObject copyAtlasObj = GameObject.Instantiate(atlasPrefab) as GameObject;

            UIAtlas copyAtlas = copyAtlasObj.GetComponent <UIAtlas>();

            if (BeforeBuildUIAtlasFilter != null)
            {
                BeforeBuildUIAtlasFilter(copyAtlas);
            }

            Material cacheMat = copyAtlas.spriteMaterial;
            string   matPath  = KDepBuild_Material.BuildDepMaterial(cacheMat, scale); // 缩放

            // 缩放
            copyAtlas.pixelSize = 1 / PictureScale;
            foreach (var spriteData in copyAtlas.spriteList)
            {
                spriteData.x            = Mathf.FloorToInt(spriteData.x * PictureScale);
                spriteData.y            = Mathf.FloorToInt(spriteData.y * PictureScale);
                spriteData.width        = Mathf.FloorToInt(spriteData.width * PictureScale);
                spriteData.height       = Mathf.FloorToInt(spriteData.height * PictureScale);
                spriteData.borderLeft   = Mathf.FloorToInt(spriteData.borderLeft * PictureScale);
                spriteData.borderRight  = Mathf.FloorToInt(spriteData.borderRight * PictureScale);
                spriteData.borderTop    = Mathf.FloorToInt(spriteData.borderTop * PictureScale);
                spriteData.borderBottom = Mathf.FloorToInt(spriteData.borderBottom * PictureScale);
                // padding 不变, ngui bug
                spriteData.paddingBottom = Mathf.FloorToInt(spriteData.paddingBottom * PictureScale);
                spriteData.paddingTop    = Mathf.FloorToInt(spriteData.paddingTop * PictureScale);
                spriteData.paddingLeft   = Mathf.FloorToInt(spriteData.paddingLeft * PictureScale);
                spriteData.paddingRight  = Mathf.FloorToInt(spriteData.paddingRight * PictureScale);
            }

            KAssetDep.Create <KUIAtlasDep>(copyAtlas, matPath);

            copyAtlas.spriteMaterial = null;                                                                  // 挖空atlas

            result = KDependencyBuild.DoBuildAssetBundle("UIAtlas/UIAtlas_" + path, copyAtlasObj, needBuild); // Build主对象, 被挖空Material了的

            if (AfterBuildUIAtlasFilter != null)
            {
                AfterBuildUIAtlasFilter(copyAtlas);
            }
            GameObject.DestroyImmediate(copyAtlasObj);

            KDepCollectInfoCaching.SetCache(atlas, result);
            return(result.Path);
        }