Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }