示例#1
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
        {
            Log.Warning("UISprite null Atlas: {0}", text.name);
        };
    }
示例#2
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);
            }
        }
示例#3
0
        public void Dispose()
        {
            WriteVersion();
            if (BuildedList.Count > 0)
            {
                //ProductMd5_CurPlatform();
                Logger.Log("一共打包了{0}個資源:\n{1}", BuildedList.Count, string.Join("\n", BuildedList.ToArray()));
            }
            else
            {
                Logger.Log("没有任何需要打包的资源!");
            }

            KDependencyBuild.SaveBuildAction();

            Current = null;
            KBuildTools.AfterBuildAssetBundleEvent -= OnAfterBuildAssetBundleEvent;
            KDependencyBuild.Clear();
        }
示例#4
0
        /// <summary>
        /// 资源打包周期版本管理
        /// </summary>
        /// <param name="rebuild">如果是rebuild,将无视之前的差异打包信息</param>
        public KAssetVersionControl(bool rebuild = false)
        {
            if (Current != null)
            {
                Logger.LogError("New a KAssetVersionControl, but already has annother instance using! Be careful!");
            }

            Current = this;

            _isRebuild = rebuild;

            Logger.LogWarning("================== KAssetVersionControl Begin ======================");

            SetupHistory();

            KDependencyBuild.Clear();

            KBuildTools.AfterBuildAssetBundleEvent += OnAfterBuildAssetBundleEvent;
        }
        public void Dispose()
        {
            WriteVersion();
            if (BuildCount > 0)
            {
                //ProductMd5_CurPlatform();
                Logger.Log("一共打包了{0}個資源", BuildCount);
            }
            else
            {
                Logger.Log("没有任何需要打包的资源!");
            }

            KDependencyBuild.SaveBuildAction();

            Current = null;
            KBuildTools.AfterBuildAssetBundleEvent -= OnAfterBuildAssetBundleEvent;
            KDependencyBuild.Clear();
        }
    private static string _BuildShader(Shader shader)
    {
        Shader fileShader;
        string shaderAssetPath = AssetDatabase.GetAssetPath(shader);

        if (shaderAssetPath.Contains("unity_builtin_extra"))
        {
            shaderAssetPath = "Assets/" + KEngineDef.ResourcesBuildCacheDir + "/BuiltinShader";

            fileShader = AssetDatabase.LoadAssetAtPath(shaderAssetPath, typeof(Shader)) as Shader;
            if (fileShader == null)
            {
                AssetDatabase.CreateAsset(shader, shaderAssetPath);
                AssetDatabase.ImportAsset(shaderAssetPath);
                fileShader = AssetDatabase.LoadAssetAtPath(shaderAssetPath, typeof(Shader)) as Shader;

                if (fileShader == null)
                {
                    Log.Error("Cannot Build Builtin Shader: {0}", shader.name);
                }
            }
        }
        else
        {
            fileShader = shader;
        }

        //var shaderFlag = string.Format("Shader:{0}:{1}", fileShader.name, shaderAssetPath);  // 构造一个标记

        bool needBuild = AssetVersionControl.TryCheckFileBuild(shaderAssetPath);

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

        var cleanShaderName = GetShaderNameToBuild(fileShader);
        var result          = KDependencyBuild.DoBuildAssetBundle("Shader/Shader_" + cleanShaderName, fileShader, needBuild);

        return(result.Path);
    }
示例#7
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);
        }
    private static KSerializeMaterialProperty _GetShaderTexProp(Material mm, string texProp, float scaleTexture = 1f)
    {
        if (mm.HasProperty(texProp))
        {
            Texture tex = mm.GetTexture(texProp);
            if (tex != null)
            {
                KSerializeMaterialProperty shaderProp = new KSerializeMaterialProperty();

                shaderProp.PropName = texProp;
                if (tex is Texture2D)
                {
                    var texTiling = mm.GetTextureScale(texProp); // 纹理+tiling+offset
                    var texOffset = mm.GetTextureOffset(texProp);
                    var texPath   = KDependencyBuild.BuildDepTexture(tex, scaleTexture);
                    shaderProp.Type = KSerializeMaterialProperty.ShaderType.Texture;

                    shaderProp.PropValue = string.Format("{0}|{1}|{2}|{3}|{4}", texPath, texTiling.x, texTiling.y,
                                                         texOffset.x, texOffset.y);
                }
                else
                {
                    Log.Warning("找到一个非Texture2D, Type:{0} Mat:{1} PropName:{2}", tex.GetType(), mm.name, texProp);
                    shaderProp.Type = KSerializeMaterialProperty.ShaderType.RenderTexture;
                    // Shader的RenderTexture不打包,一般由脚本动态生成
                    shaderProp.PropValue = null;
                }
                return(shaderProp);
            }
            else
            {
                Log.Info("[_GetShaderTexProp]处理纹理时发现获取不到纹理, 材质{0}  Shader属性{1}", mm.name, texProp);
                return(null);
            }
        }
        return(null);
    }
示例#9
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);
        }
示例#10
0
 /// <summary>
 /// 不用依赖判断,整个打包!
 /// </summary>
 /// <param name="tmpSpineObj"></param>
 /// <param name="path"></param>
 /// <param name="checkNeedBuild"></param>
 public static void BuildPureGameObject(GameObject tmpSpineObj, string path, bool checkNeedBuild)
 {
     KDependencyBuild.DoBuildAssetBundle(path, tmpSpineObj, checkNeedBuild);
 }
示例#11
0
 static void Custom_ExportUIMenu()
 {
     KDependencyBuild.Clear();
 }