Пример #1
0
    public static string BuildDepMaterial(Material mat, float scaleTexture = 1f)
    {
        CDepCollectInfo buildResult = KDepCollectInfoCaching.GetCache(mat);

        if (buildResult != null)
        {
            return(buildResult.Path);
        }

        KSerializeMaterial sMat = __DoExportMaterial(mat, scaleTexture);

        if (sMat != null)
        {
            string path = AssetDatabase.GetAssetPath(mat);

            bool needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(path);
            if (needBuild)
            {
                AssetVersionControl.TryMarkBuildVersion(path);
            }

            path        = KDependencyBuild.__GetPrefabBuildPath(path);
            buildResult = KDependencyBuild.__DoBuildScriptableObject("Material/Material_" + path, sMat, needBuild);

            KDepCollectInfoCaching.SetCache(mat, buildResult);

            return(buildResult.Path);
        }

        // 可能没路径的材质,直接忽略
        return("");
    }
Пример #2
0
        /// <summary>
        /// 从版本控制系统中判断是否需要Build这个Asset
        /// </summary>
        /// <param name="assetPath"></param>
        /// <returns></returns>
        private static bool CheckNeedBuildAsset(string assetPath)
        {
            // 判断是否需要打包,根据要在依赖判断之后哦
            if (!AssetVersionControl.TryCheckNeedBuildWithMeta(assetPath))
            {
                if (!InternalEditorUtility.inBatchMode)
                {
                    Debug.LogWarning("Same file, no Need To Build " + assetPath);
                }
                return(false);
            }

            // 检查是否需要打包的后缀类型
            var extType = GetAssetExtType(assetPath);

            if (Define.IgnoreDepType.Contains(extType))
            {
                if (!InternalEditorUtility.inBatchMode)
                {
                    Log.Warning("Asset {0}, Type: {1}, no need build", assetPath, extType);
                }
                return(false);
            }

            return(true);
        }
Пример #3
0
    // Prefab ,  build
    public static string BuildSprite(Sprite sprite)
    {
        if (sprite.packed)
        {
            Log.Warning("Sprite: {0} is packing!!!", sprite.name);
        }

        string assetPath = AssetDatabase.GetAssetPath(sprite);
        bool   needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(assetPath);

        if (needBuild)
        {
            AssetVersionControl.TryMarkBuildVersion(assetPath);
        }

        string path = KDependencyBuild.__GetPrefabBuildPath(assetPath);

        if (string.IsNullOrEmpty(path))
        {
            Log.Warning("[BuildSprite]不是文件的Texture, 估计是Material的原始Texture?");
        }
        var result = KDependencyBuild.DoBuildAssetBundle("Common/Sprite_" + path, sprite, needBuild);

        return(result.Path);
    }
Пример #4
0
    /// <summary>
    /// 图片打包工具,直接打包,不用弄成Texture!, 需要借助TexturePacker
    /// </summary>
    /// <summary>
    /// 单独打包的纹理图片, 这种图片,不在Unity目录内,用bytes读取, 指定保存的目录
    /// </summary>
    /// <param name="saveCacheFolderName"></param>
    /// <param name="tex"></param>
    /// <returns></returns>
    public static string BuildIOTexture(string saveCacheFolderName, string imageSystemFullPath, float scale = 1)
    {
        var cleanPath = imageSystemFullPath.Replace("\\", "/");

        var fileName  = Path.GetFileNameWithoutExtension(cleanPath);
        var buildPath = string.Format("{0}/{1}_{0}{2}", saveCacheFolderName, fileName,
                                      AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt));
        var needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(cleanPath);

        var texture = new Texture2D(1, 1);

        if (needBuild && !IsJustCollect)
        {
            var cacheDir = "Assets/" + KEngineDef.ResourcesBuildCacheDir + "/BuildIOTexture/" + saveCacheFolderName +
                           "/";
            var cacheFilePath = cacheDir + Path.GetFileName(cleanPath);

            //CFolderSyncTool.TexturePackerScaleImage(cleanPath, cacheFilePath, Math.Min(1, GameDef.PictureScale * scale));  // TODO: do scale

            texture = AssetDatabase.LoadAssetAtPath(cacheFilePath, typeof(Texture2D)) as Texture2D;
            if (texture == null)
            {
                Log.Error("[BuildIOTexture]TexturePacker scale failed... {0}", cleanPath);
                return(null);
            }

            //CTextureCompressor.CompressTextureAsset(cleanPath, texture);

            //CTextureCompressor.AutoCompressTexture2D(texture, EditorUserBuildSettings.activeBuildTarget);

            //if (!texture.LoadImage(File.ReadAllBytes(cleanPath)))
            //{
            //    Log.Error("无法LoadImage的Texture: {0}", cleanPath);
            //    return null;
            //}
            //texture.name = fileName;

            //// 多线程快速,图像缩放,双线性过滤插值
            //TextureScaler.Bilinear(texture, (int)(texture.width * GameDef.PictureScale),
            //    (int)(texture.height * GameDef.PictureScale));
            //GC.CollectMaterial();
        }

        // card/xxx_card.box
        var result = KDependencyBuild.DoBuildAssetBundle(buildPath, texture, needBuild);

        if (needBuild)
        {
            AssetVersionControl.TryMarkBuildVersion(cleanPath);
        }

        return(result.Path);
    }
    public static string BuildAudioClip(AudioClip audioClip)
    {
        string assetPath = AssetDatabase.GetAssetPath(audioClip);
        bool   needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(assetPath);

        if (needBuild)
        {
            AssetVersionControl.TryMarkBuildVersion(assetPath);
        }

        var result = KDependencyBuild.DoBuildAssetBundle("Audio/Audio_" + audioClip.name, audioClip, needBuild);

        return(result.Path);
    }
Пример #6
0
    /// <summary>
    /// 对依赖的字体进行打包,返回打包结果路径
    /// </summary>
    /// <param name="font"></param>
    /// <returns></returns>
    public static string BuildFont(Font font)
    {
        string fontAssetPath = AssetDatabase.GetAssetPath(font);

        if (string.IsNullOrEmpty(fontAssetPath) || fontAssetPath == "Library/unity default resources")
        {
            Log.Error("[BuildFont]无法打包字体...{0}", font);
            return(null);
        }
        //fontAssetPath = __GetPrefabBuildPath(fontAssetPath).Replace("Atlas_", "");
        //string[] splitArr = fontAssetPath.Split('/');

        bool needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(fontAssetPath);

        if (needBuild)
        {
            AssetVersionControl.TryMarkBuildVersion(fontAssetPath);
        }

        var result = DoBuildAssetBundle("Font/Font_" + font.name, font, needBuild);

        return(result.Path);
    }
Пример #7
0
    //static HashSet<string> _depTextureScaleList = new HashSet<string>();  // 进行过Scale的图片
    public static string BuildDepTexture(Texture tex, float scale = 1f)
    {
        Debuger.Assert(tex);
        CDepCollectInfo result = KDepCollectInfoCaching.GetCache(tex);

        if (result != null)
        {
            return(result.Path);
        }

        string assetPath = AssetDatabase.GetAssetPath(tex);
        bool   needBuild = AssetVersionControl.TryCheckNeedBuildWithMeta(assetPath);

        if (needBuild)
        {
            AssetVersionControl.TryMarkBuildVersion(assetPath);
        }

        Texture newTex;

        if (tex is Texture2D)
        {
            var tex2d = (Texture2D)tex;

            if (needBuild &&
                !scale.Equals(1f)) // 需要进行缩放,才进来拷贝
            {
                var cacheDir      = "Assets/" + KEngineDef.ResourcesBuildCacheDir + "/BuildDepTexture/";
                var cacheFilePath = cacheDir + Path.GetFileName(assetPath);

                //var needScale = !BuildedCache.ContainsKey("BuildDepTexture:" + assetPath);
                //if (needScale && !IsJustCollect)
                //{
                //    CFolderSyncTool.TexturePackerScaleImage(assetPath, cacheFilePath, scale);  // do scale
                //    var actionName = "BuildDepTexture:" + assetPath;
                //    //BuildedCache[actionName] = true;  // 下次就别scale了!蛋痛
                //    AddCache(actionName);
                //}

                newTex = AssetDatabase.LoadAssetAtPath(cacheFilePath, typeof(Texture2D)) as Texture2D;
                if (newTex == null)
                {
                    Log.Error("TexturePacker scale failed... {0}", assetPath);
                    newTex = tex2d;
                }

                SyncTextureImportSetting(tex2d, newTex as Texture2D);

                // TODO: mark to write
                //var texPath = AssetDatabase.GetAssetPath(tex2d);

                //var newTex2D = new Texture2D(tex2d.width, tex2d.height);
                //if (!string.IsNullOrEmpty(texPath)) // Assets内的纹理
                //{
                //    var bytes = File.ReadAllBytes(texPath);
                //    newTex2D.LoadImage(bytes);
                //}
                //else
                //{
                //    var bytes = tex2d.EncodeToPNG();
                //    newTex2D.LoadImage(bytes);
                //}

                //newTex2D.Apply();
                //GC.CollectMaterial();
                //// 进行缩放
                //TextureScaler.Bilinear(newTex2D, (int) (tex.width*scale), (int) (tex.height*scale));
                //GC.CollectMaterial();

                //newTex = newTex2D;
            }
            else
            {
                newTex = tex2d;
            }
        }
        else
        {
            newTex = tex;
            if (!scale.Equals(1f))
            {
                Log.Warning("[BuildDepTexture]非Texture2D: {0}, 无法进行Scale缩放....", tex);
            }
        }
        //if (!IsJustCollect)
        //    CTextureCompressor.CompressTextureAsset(assetPath, newTex as Texture2D);

        string path = __GetPrefabBuildPath(assetPath);

        if (string.IsNullOrEmpty(path))
        {
            Log.Warning("[BuildTexture]不是文件的Texture, 估计是Material的原始Texture?");
        }
        result = DoBuildAssetBundle("Texture/Texture_" + path, newTex, needBuild);

        KDepCollectInfoCaching.SetCache(tex, result);
        GC.Collect(0);
        return(result.Path);
    }