示例#1
0
    public static CDepCollectInfo GetCache <T>(T obj)
    {
        CDepCollectInfo info = null;

        _cache.TryGetValue(obj, out info);
        return(info);
    }
    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("");
    }
示例#3
0
 public static void SetCache <T>(T obj, CDepCollectInfo info)
 {
     _cache[obj] = info;
 }
示例#4
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);
    }